views:

50

answers:

2

The MessageDigest class implements the SHA-1 algorithm (among many others). The SHA-1 algorithm allows one to use different "seeds" or initial digests. See SHA-1 Psuedocode

The algorithm initializes variables, or the seed:

Initialize variables:
h0 = 0x67452301
h1 = 0xEFCDAB89
h2 = 0x98BADCFE
h3 = 0x10325476
h4 = 0xC3D2E1F0

However the MessageDigest class, as described in the Online Java Manual, provides no API for setting these initial variables. In fact, it doesn't state the value of the initial variables.

How can I set the initial seed for the SHA-1 algorithm?

Where is an example of SHA-1 in Java, USING AN INITIAL SEED?
(I'm looking for the SHA-1 implementation, unless the example uses MessageDigest with an alternative initial seed.)

+1  A: 

Where do you see the need for a seed in a SHA-1 digest? Normally in encryption algorithm with a need of source of random numbers, a seed is "needed". But in SHA-1 you don't even use random numbers at all, so there is no seed or initial vector to set. The variables you mentioned are 'hard' (constants), they are part of the algorithm, no need or use to change the values of h0-4.

Michael Konietzka
My application performs SHA-1 on an executable. One of the requirements of the application is to allow users to set the initial seed of the SHA-1 algorithm. This allows the user to verify the executable.
Thomas Matthews
You can verify a hash without changing the initial seed. What's the motivation for changing the seed? Those constants are part of the SHA-1 algorithm: http://www.itl.nist.gov/fipspubs/fip180-1.htmIt's worth noting that you should never try to tweak encryption and hashing algorithms without really really really knowing what you're doing, as you may effectively nullify any security benefits the algorithm provided.
Alan Krueger
A: 

The Java function cannot be supplied with an initial seed.

I copied a C implementation of SHA-1 algorithm and modified it to allow changing of the initial seed values.

Thomas Matthews