2
$\begingroup$

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?

$\endgroup$
7
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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