Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

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

  1. https://code.google.com/p/crypto-js/source/browse/tags/3.1.2/src/sha1.js

    this._hash = new WordArray.init([
        0x67452301, 0xefcdab89,
        0x98badcfe, 0x10325476,
        0xc3d2e1f0
    ]);
    
  2. https://code.google.com/p/google-authenticator/source/browse/libpam/totp.html

    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
add comment

1 Answer 1

up vote 6 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 at 10:17
    
And what a strange optimization it is: 2 characters less for 2 XORs. –  Artjom B. Apr 18 at 11:26
    
Same thing with the Y value, it only saves 1 byte of code space –  Richie Frame Apr 18 at 22:17
add comment

Your Answer

 
discard

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.