Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to understand why the constants differ in this SHA1 implementation:


    this._hash = new WordArray.init([
        0x67452301, 0xefcdab89,
        0x98badcfe, 0x10325476,

    V = 0x67452301,
    W = 0x88888888,
    Y = 271733878,
    X = Y ^ W,
    Z = 0xC3D2E1F0;

You'll notice the constants in [1] and [2] are different. Is this the result of an optimization, or is there another reason why those constants are different?

share|improve this question
up vote 7 down vote accepted

They are actually the same, because you missed W^=V in the second link. When you work out the XORs, you arrive at the same constants.

share|improve this answer
Yes, and it appears to be an optimization to save code space, as there is 1 less constant – Richie Frame Apr 18 '14 at 10:17
And what a strange optimization it is: 2 characters less for 2 XORs. – Artjom B. Apr 18 '14 at 11:26
Same thing with the Y value, it only saves 1 byte of code space – Richie Frame Apr 18 '14 at 22:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.