summaryrefslogtreecommitdiffstats
path: root/sha256.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-12-06 01:39:33 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-12-06 01:39:33 +0100
commit6533e74370acfa51653608b1dc5e1292c72970c9 (patch)
treedbd3b13cb10df6f341a82a5a449fcf5a4b9d9b66 /sha256.c
parenta583bb24fb23728c9c4ed6c6c573d526ab654c49 (diff)
downloadcrypto-6533e74370acfa51653608b1dc5e1292c72970c9.zip
crypto-6533e74370acfa51653608b1dc5e1292c72970c9.tar.gz
remove extra spaces
Diffstat (limited to 'sha256.c')
-rw-r--r--sha256.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sha256.c b/sha256.c
index ce13e22..fa99505 100644
--- a/sha256.c
+++ b/sha256.c
@@ -42,13 +42,13 @@ static void sha_compress(struct sha256_ctx *md)
{
u32 S[8], W[64], t0, t1;
int i;
-
+
/* copy state into S */
for (i = 0; i < 8; i++)
S[i] = md->state[i];
-
+
/* copy the state into 512-bits into W[0..15] */
- for (i = 0; i < 16; i++)
+ for (i = 0; i < 16; i++)
W[i] = (((unsigned long) md->buf[(4 * i) + 0]) << 24) |
(((unsigned long) md->buf[(4 * i) + 1]) << 16) |
(((unsigned long) md->buf[(4 * i) + 2]) << 8) |
@@ -57,7 +57,7 @@ static void sha_compress(struct sha256_ctx *md)
/* fill W[16..63] */
for (i = 16; i < 64; i++)
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
-
+
/* Compress */
for (i = 0; i < 64; i++) {
t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
@@ -71,7 +71,7 @@ static void sha_compress(struct sha256_ctx *md)
S[1] = S[0];
S[0] = t0 + t1;
}
-
+
/* feedback */
for (i = 0; i < 8; i++)
md->state[i] += S[i];
@@ -111,38 +111,38 @@ void sha256_final(void *ctx, u8 *hash)
{
struct sha256_ctx *md = ctx;
int i;
-
+
/* increase the length of the message */
md->length += md->curlen * 8;
-
+
/* append the '1' bit */
md->buf[md->curlen++] = 0x80;
-
+
/* if the length is currenlly above 56 bytes we append zeros
* then compress. Then we can fall back to padding zeros and length
* encoding like normal.
*/
-
+
if (md->curlen >= 56) {
for (; md->curlen < 64;)
md->buf[md->curlen++] = 0;
sha_compress(md);
md->curlen = 0;
}
-
+
/* pad upto 56 bytes of zeroes */
for (; md->curlen < 56;)
md->buf[md->curlen++] = 0;
-
+
/* since all messages are under 2^32 bits we mark the top bits zero */
for (i = 56; i < 60; i++)
md->buf[i] = 0;
-
+
/* append length */
for (i = 60; i < 64; i++)
md->buf[i] = (md->length >> ((63 - i) * 8)) & 255;
sha_compress(md);
-
+
/* copy output */
for (i = 0; i < 32; i++)
hash[i] = (md->state[i >> 2] >> (((3 - i) & 3) << 3)) & 255;