A simple library to support serving https.
Dependents: oldheating gps motorhome heating
Diff: sha/sha256.c
- Revision:
- 7:94ef5824c3c0
- Parent:
- 4:6a1d887f1cad
- Child:
- 14:03a0b8fd6ddc
--- a/sha/sha256.c Sun Sep 01 18:15:12 2019 +0000 +++ b/sha/sha256.c Thu Sep 05 12:58:41 2019 +0000 @@ -109,24 +109,24 @@ while (inlen > 0) { - if (md->curlen == 0 && inlen >= SHA_BLOCK_SIZE) + if (md->curlen == 0 && inlen >= SHA256_BLOCK_SIZE) { if (compress(md, in) < 0) return -1; - md->length += SHA_BLOCK_SIZE * 8; - in += SHA_BLOCK_SIZE; - inlen -= SHA_BLOCK_SIZE; + md->length += SHA256_BLOCK_SIZE * 8; + in += SHA256_BLOCK_SIZE; + inlen -= SHA256_BLOCK_SIZE; } else { - int n = inlen < SHA_BLOCK_SIZE - md->curlen ? inlen : SHA_BLOCK_SIZE - md->curlen; + int n = inlen < SHA256_BLOCK_SIZE - md->curlen ? inlen : SHA256_BLOCK_SIZE - md->curlen; memcpy(md->buf + md->curlen, in, n); md->curlen += n; in += n; inlen -= n; - if (md->curlen == SHA_BLOCK_SIZE) + if (md->curlen == SHA256_BLOCK_SIZE) { if (compress(md, md->buf) < 0) return -1; - md->length += 8 * SHA_BLOCK_SIZE; + md->length += 8 * SHA256_BLOCK_SIZE; md->curlen = 0; } } @@ -187,4 +187,12 @@ Sha256Start (&md); Sha256Add (&md, in, inlen); Sha256Finish(&md, hash); +} + +void Sha256Copy(struct Sha256State* pTo, struct Sha256State* pFrom) +{ + pTo->length = pFrom->length; + pTo->curlen = pFrom->curlen; + for (int i = 0; i < SHA256_HASH_SIZE / 4; i++) pTo->state[i] = pFrom->state[i]; + for (int i = 0; i < SHA256_BLOCK_SIZE; i++) pTo->buf[i] = pFrom->buf[i]; } \ No newline at end of file