A simple library to support serving https.
Dependents: oldheating gps motorhome heating
Diff: sha/sha1.c
- Revision:
- 14:03a0b8fd6ddc
- Parent:
- 7:94ef5824c3c0
--- a/sha/sha1.c Fri Sep 27 11:31:18 2019 +0000 +++ b/sha/sha1.c Wed Oct 02 20:26:04 2019 +0000 @@ -94,20 +94,20 @@ } void Sha1Add(struct Sha1State *ctx, const uint8_t *data, int len) { - int i = ctx->count % sizeof(ctx->buf); + int i = ctx->count % SHA1_BLOCK_SIZE; const uint8_t *p = (const uint8_t *)data; ctx->count += len; - while (len > sizeof(ctx->buf) - i) + while (len > SHA1_BLOCK_SIZE - i) { - memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i); - len -= sizeof(ctx->buf) - i; - p += sizeof(ctx->buf) - i; + memcpy(&ctx->buf.b[i], p, SHA1_BLOCK_SIZE - i); + len -= SHA1_BLOCK_SIZE - i; + p += SHA1_BLOCK_SIZE - i; sha1_transform(ctx); i = 0; } while (len--) { ctx->buf.b[i++] = *p++; - if (i == sizeof(ctx->buf)) { + if (i == SHA1_BLOCK_SIZE) { sha1_transform(ctx); i = 0; } @@ -118,7 +118,7 @@ uint32_t cnt = ctx->count * 8; int i; Sha1Add(ctx, (uint8_t *)"\x80", 1); - while ((ctx->count % sizeof(ctx->buf)) != (sizeof(ctx->buf) - 8)) + while ((ctx->count % SHA1_BLOCK_SIZE) != (SHA1_BLOCK_SIZE - 8)) Sha1Add(ctx, (uint8_t *)"\0", 1); for (i = 0; i < 8; ++i) { uint8_t tmp = cnt >> ((7 - i) * 8);