Skip to content

Instantly share code, notes, and snippets.

@hak8or
Created December 15, 2013 11:13
Show Gist options
  • Save hak8or/7971686 to your computer and use it in GitHub Desktop.
Save hak8or/7971686 to your computer and use it in GitHub Desktop.
notes sha-256
// NOTES
abc
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
RabbleRabble
fc9d6d9a223480bc51e4c6a4893502930d66a13c71c5818d230f1f50be2a20e6 <-- website 1
fc9d6d9a223480bc51e4c6a4893502930d66a13c71c5818d230f1f50be2a20e6
RabbleRabbleRabbleRabble
0a7b55d5b014c6c437e891a98ea0db3d3e3d808bacdda1b9f7f0c5f6a61b66ed <-- website 1
0a7b55d5b014c6c437e891a98ea0db3d3e3d808bacdda1b9f7f0c5f6a61b66ed
RabbleRabbleRabbleRabbleRabbleRabbleRabbleRabble
63af46a49f3432af28dcb1c9fd88919a6270f422f7ff76a80cc5219c7917fe51 <-- website 1
63af46a49f3432af28dcb1c9fd88919a6270f422f7ff76a80cc5219c7917fe51
two words
a03f1d611645eb53ad16c1af546ca0792dc884505bab57ede80f4dad6b911d3a <-- website 1
a03f1d611645eb53ad16c1af546ca0792dc884505bab57ede80f4dad6b911d3a
I am a sentence with a period.
7e18a2132d5d9ea5ecd78704d240680ac3d75d511325a17f6df2d36dcd96d562 <-- website 1
7e18a2132d5d9ea5ecd78704d240680ac3d75d511325a17f6df2d36dcd96d562
===VVVV=== OLD CRAP ===VVVV=== ==VVVV===OLD CRAP ===VVVV===
Friggen should add in limits to make sure I am working with only 32 bit variables!
Ways this could have been done faster:
Make sure spec is correct (no idea how NIST gave wrong spec)
Make sure I am working with 32 bit variables when I need to.
Should have discovered firebug earlier, gdb will take a while to learn well.
switch (argc) {
case 1:
cout << "no input string found, running test using abc\n";
string message = "abc";
break;
case 2:
cout << "Using " << argv[2] << "as mesage\n";
string message = argv[2];
break;
default:
cout << "Too many things in the command line."
exit(-1);
break;
}
20A 20E is where all goes wrong.
20A:
// my code
e = d + temp_1
75ab8b63 = dec567974555 + dec1088745109
temp_1 = h + EP1(e) + CH(e,f,g) + k[t] + W[t];
dec1088745109 = dec-2144066916 + dec-130597203 + dec-2079464091 + dec770255983 + dec377650040
1cb4939d40e4ee95 = 8034229c + 2d7822df8373ead + 840de565 + 2de92c6f + 19dd116e16827b78
95eee440
// ON JS
temp_1 = h + EP1(e) + CH(e,f,g) + k[t] + W[t];
dec-2533364075 = dec-2144066916 + dec-130597203 + dec-2079464091 + dec770255983 + dec1050508152
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
===VVVV=== OLD CRAP ===VVVV=== ==VVVV===OLD CRAP ===VVVV===
E and A are wrong.
e = d + temp1
Should be
E: FA2A4622 = a54ff53a + 54da50e8
BSIG1(e) <-- This is wrong, from the official spec sheet!
temp_1 = h + EP1(e) + CH(e,f,g) + k[i] + w[i];
2b72aef = 5be0cd19 + EP1(510e527f) CH(510e527f, 9b05688c, 1f83d9ab) 428a2f98 + 61626380
// PER JS
154DA50E8 = 5be0cd19 + ........ + ........ + 428a2f98 + 61626380
154DA50E8 = 5be0cd19 + 3587272B + 1F85C98C + 428a2f98 + 61626380
// From my program
154DA50E8 = 5be0cd19 + ..... + ..... + 428a2f98 + 61626380
154DA50E8 = 5be0cd19 + e3640132 + 743be0cb + 428a2f98 + 61626380
*** EP1(510e527f) SHOULD = 0xe3640132
from JS Sha256.Sigma1(0x510E527F)
Friggen rotating bits is wrong!
Sha256.Sigma1 = Sha256.ROTR(6, x) ^ Sha256.ROTR(11, x) ^ Sha256.ROTR(25, x)
*** CH(510e527f, 9b05688c, 1f83d9ab) SHOULD = 0x743be0cb
from JS Sha256.Ch(0x510E527F, 0x9B05688C, 1F83D9AB)
a = (temp1 + temp2)
A: 5D6AEBCD = 154DA50E8 + ......
// From my code
temp_2 = BSIG0(a) + MAJ(a,b,c);
temp_2 = BSIG0(6a09e667) + MAJ(6a09e667, bb67ae85 ,3c6ef372 );
4094ef47cdbe9 = d4094eba0cf582 + 3a6fe667
// From JS
temp_2 = Sha256.Sigma0(a) + Sha256.Maj(a, b, c);
8909AE5 = Sha256.Sigma0(1779033703) + Sha256.Maj(1779033703, 3144134277, 1013904242);
8909AE5 = Sha256.Sigma0(6A09E667) + Sha256.Maj(6A09E667, BB67AE85, 3C6EF372);
8909AE5 = Sha256.Sigma0(6A09E667) + 3A6FE667
from JS
Sha256.Sigma0 = Sha256.ROTR(2, x) ^ Sha256.ROTR(13, x) ^ Sha256.ROTR(22, x)
===VVVV=== OLD CRAP ===VVVV=== ==VVVV===OLD CRAP ===VVVV===
taken from paper:
temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t];
SHA256_SIGMA1(E) is in my program EP1
#define SHA256_SIGMA1(word) \ // PAPERS
(SHA256_ROTR( 6,word) ^ SHA256_ROTR(11,word) ^ SHA256_ROTR(25,word))
#define EP1(x) // MINE
(ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
// ==================
#define SHA256_ROTR(bits,word) // PAPERS \
(((word) >> (bits)) | ((word) << (32-(bits))))
// MINE
#define ROTRIGHT(bits,word (((word) >> (bits)) | ((word) << (32-(bits))))
From paper
for (t = 0; t < 64; t++) {
temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t];
temp2 = SHA256_SIGMA0(A) + SHA_Maj(A,B,C);
H = G;
G = F;
F = E;
E = D + temp1;
D = C;
C = B;
B = A;
A = temp1 + temp2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment