diff options
Diffstat (limited to 'sha512.c')
-rw-r--r-- | sha512.c | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -126,9 +126,9 @@ sha512_transform(u64 *state, const u8 *input) } /* load the state into our registers */ - a=state[0]; b=state[1]; c=state[2]; d=state[3]; - e=state[4]; f=state[5]; g=state[6]; h=state[7]; - + a=state[0]; b=state[1]; c=state[2]; d=state[3]; + e=state[4]; f=state[5]; g=state[6]; h=state[7]; + /* now iterate */ for (i=0; i<80; i+=8) { t1 = h + e1(e) + Ch(e,f,g) + sha512_K[i ] + W[i ]; @@ -148,9 +148,9 @@ sha512_transform(u64 *state, const u8 *input) t1 = a + e1(f) + Ch(f,g,h) + sha512_K[i+7] + W[i+7]; t2 = e0(b) + Maj(b,c,d); e+=t1; a=t1+t2; } - - state[0] += a; state[1] += b; state[2] += c; state[3] += d; - state[4] += e; state[5] += f; state[6] += g; state[7] += h; + + state[0] += a; state[1] += b; state[2] += c; state[3] += d; + state[4] += e; state[5] += f; state[6] += g; state[7] += h; /* erase our data */ a = b = c = d = e = f = g = h = t1 = t2 = 0; @@ -198,7 +198,7 @@ sha512_update(void *ctx, const u8 *data, unsigned int len) /* Compute number of bytes mod 128 */ index = (unsigned int)((sctx->count[0] >> 3) & 0x7F); - + /* Update number of bits */ if ((sctx->count[0] += (len << 3)) < (len << 3)) { if ((sctx->count[1] += 1) < 1) @@ -206,9 +206,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len) sctx->count[3]++; sctx->count[1] += (len >> 29); } - + part_len = 128 - index; - + /* Transform as many times as possible. */ if (len >= part_len) { memcpy(&sctx->buf[index], data, part_len); @@ -230,7 +230,7 @@ void sha512_final(void *ctx, u8 *hash) { struct sha512_ctx *sctx = ctx; - + static u8 padding[128] = { 0x80, }; u32 t; @@ -247,22 +247,22 @@ sha512_final(void *ctx, u8 *hash) bits[15] = t; t>>=8; bits[14] = t; t>>=8; bits[13] = t; t>>=8; - bits[12] = t; + bits[12] = t; t = sctx->count[1]; bits[11] = t; t>>=8; bits[10] = t; t>>=8; bits[9 ] = t; t>>=8; - bits[8 ] = t; + bits[8 ] = t; t = sctx->count[2]; bits[7 ] = t; t>>=8; bits[6 ] = t; t>>=8; bits[5 ] = t; t>>=8; - bits[4 ] = t; + bits[4 ] = t; t = sctx->count[3]; bits[3 ] = t; t>>=8; bits[2 ] = t; t>>=8; bits[1 ] = t; t>>=8; - bits[0 ] = t; + bits[0 ] = t; /* Pad out to 112 mod 128. */ index = (sctx->count[0] >> 3) & 0x7f; @@ -284,7 +284,7 @@ sha512_final(void *ctx, u8 *hash) hash[j+1] = (char)t2 & 0xff; t2>>=8; hash[j ] = (char)t2 & 0xff; } - + /* Zeroize sensitive information. */ memset(sctx, 0, sizeof(struct sha512_ctx)); } |