TAY
Fork of Crypto_light by
Diff: SHA2_32.cpp
- Revision:
- 2:473bac39ae7c
- Parent:
- 0:7a1237bd2d13
- Child:
- 3:85c6ee25cf3e
--- a/SHA2_32.cpp Mon Sep 09 12:15:26 2013 +0000 +++ b/SHA2_32.cpp Mon Sep 09 16:16:24 2013 +0000 @@ -237,7 +237,9 @@ { uint32_t w[64]; for(int t = 0; t < 16; ++t) + { w[t] = (buffer[t*4] << 24) | (buffer[t*4+1] << 16) | (buffer[t*4+2] << 8) | buffer[t*4+3]; + } for(int t = 16; t < 64; ++t) w[t] = SSIG1(w[t-2]) + w[t-7] + SSIG0(w[t-15]) + w[t-16]; @@ -301,53 +303,32 @@ uint64_t lengthBit = length * 8; uint32_t lengthBitLow = lengthBit; uint32_t lengthBitHigh = lengthBit >> 32; - uint8_t tmp[4]; - tmp[0] = lengthBitLow >> 24; - tmp[1] = lengthBitLow >> 16; - tmp[2] = lengthBitLow >> 8; - tmp[3] = lengthBitLow; - memcpy(&buffer[60], tmp, 4); - tmp[0] = lengthBitHigh >> 24; - tmp[1] = lengthBitHigh >> 16; - tmp[2] = lengthBitHigh >> 8; - tmp[3] = lengthBitHigh; - memcpy(&buffer[56], tmp, 4); + lengthBitLow = __rev(lengthBitLow); + memcpy(&buffer[60], &lengthBitLow, 4); + lengthBitHigh = __rev(lengthBitHigh); + memcpy(&buffer[56], &lengthBitHigh, 4); computeBlock(&h0, &h1, &h2, &h3, &h4, &h5, &h6, &h7, buffer); - digest[0] = h0 >> 24; - digest[1] = h0 >> 16; - digest[2] = h0 >> 8; - digest[3] = h0; - digest[4] = h1 >> 24; - digest[5] = h1 >> 16; - digest[6] = h1 >> 8; - digest[7] = h1; - digest[8] = h2 >> 24; - digest[9] = h2 >> 16; - digest[10] = h2 >> 8; - digest[11] = h2; - digest[12] = h3 >> 24; - digest[13] = h3 >> 16; - digest[14] = h3 >> 8; - digest[15] = h3; - digest[16] = h4 >> 24; - digest[17] = h4 >> 16; - digest[18] = h4 >> 8; - digest[19] = h4; - digest[20] = h5 >> 24; - digest[21] = h5 >> 16; - digest[22] = h5 >> 8; - digest[23] = h5; - digest[24] = h6 >> 24; - digest[25] = h6 >> 16; - digest[26] = h6 >> 8; - digest[27] = h6; + h0 = __rev(h0); + h1 = __rev(h1); + h2 = __rev(h2); + h3 = __rev(h3); + h4 = __rev(h4); + h5 = __rev(h5); + h6 = __rev(h6); + + memcpy(digest, &h0, 4); + memcpy(&digest[4], &h1, 4); + memcpy(&digest[8], &h2, 4); + memcpy(&digest[12], &h3, 4); + memcpy(&digest[16], &h4, 4); + memcpy(&digest[20], &h5, 4); + memcpy(&digest[24], &h6, 4); + if(type == SHA_256) { - digest[28] = h7 >> 24; - digest[29] = h7 >> 16; - digest[30] = h7 >> 8; - digest[31] = h7; + h7 = __rev(h7); + memcpy(&digest[28], &h7, 4); } }