From 21251045f44aa488b4d85b1e713d3a8304c8b2e1 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Vuotto Date: Sat, 15 Jun 2024 21:22:12 +0000 Subject: [PATCH] Rename the state block buffers from m{,len} to b{,len} --- auth_poly1305.c | 26 +++++++++++++------------- cipher_chacha20.c | 42 +++++++++++++++++++++--------------------- hash_sha224_sha256.c | 34 +++++++++++++++++----------------- hash_sha384_sha512.c | 36 ++++++++++++++++++------------------ impl_chacha20.h | 4 ++-- impl_poly1305.c | 8 ++++---- impl_poly1305.h | 4 ++-- impl_sha256.c | 2 +- impl_sha256.h | 4 ++-- impl_sha512.c | 2 +- impl_sha512.h | 4 ++-- 11 files changed, 83 insertions(+), 83 deletions(-) diff --git a/auth_poly1305.c b/auth_poly1305.c index a0bb601..ca7960a 100644 --- a/auth_poly1305.c +++ b/auth_poly1305.c @@ -58,9 +58,9 @@ poly1305_init(void *arg, void *initparams) state->s2 = load32le(¶ms->key[24]); state->s3 = load32le(¶ms->key[28]); - state->mlen = 0; + state->blen = 0; for (i = 0; i < LC_POLY1305_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; return 1; } @@ -71,15 +71,15 @@ poly1305_update(void *arg, const uint8_t *in, size_t inlen) struct poly1305_state *state = arg; size_t i; - for (i = 0; i + state->mlen < LC_POLY1305_BLOCKLEN && i < inlen; i++) - state->m[i + state->mlen] = in[i]; - state->mlen += i; + for (i = 0; i + state->blen < LC_POLY1305_BLOCKLEN && i < inlen; i++) + state->b[i + state->blen] = in[i]; + state->blen += i; in += i; inlen -= i; - if (state->mlen == LC_POLY1305_BLOCKLEN) { + if (state->blen == LC_POLY1305_BLOCKLEN) { poly1305_block(state, 1); - state->mlen = 0; + state->blen = 0; } if (inlen == 0) @@ -87,7 +87,7 @@ poly1305_update(void *arg, const uint8_t *in, size_t inlen) while (inlen >= LC_POLY1305_BLOCKLEN) { for (i = 0; i < LC_POLY1305_BLOCKLEN; i++) - state->m[i] = in[i]; + state->b[i] = in[i]; poly1305_block(state, 1); in += LC_POLY1305_BLOCKLEN; @@ -95,8 +95,8 @@ poly1305_update(void *arg, const uint8_t *in, size_t inlen) } for (i = 0; i < inlen; i++) - state->m[i] = in[i]; - state->mlen = inlen; + state->b[i] = in[i]; + state->blen = inlen; return 1; } @@ -112,12 +112,12 @@ poly1305_final(void *arg, uint8_t *out, size_t *outlen) if (out == NULL) return 1; - i = state->mlen; + i = state->blen; if (i > 0) { if (i < LC_POLY1305_BLOCKLEN) { - state->m[i++] = 1; + state->b[i++] = 1; for (; i < LC_POLY1305_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; poly1305_block(state, 0); } else poly1305_block(state, 1); diff --git a/cipher_chacha20.c b/cipher_chacha20.c index ba466a0..dbc480e 100644 --- a/cipher_chacha20.c +++ b/cipher_chacha20.c @@ -44,7 +44,7 @@ chacha20_anycrypt_init(void *arg, void *initparams) state->n[0] = params->counter; for (i = 1; i < CHACHA20_NONCE_WORDS; i++) state->n[i] = load32le(¶ms->nonce[(i - 1) * 4]); - state->mlen = 0; + state->blen = 0; return 1; } @@ -62,7 +62,7 @@ xchacha20_anycrypt_init(void *arg, void *initparams) state->k[i] = load32le(¶ms->key[i * 4]); for (i = 0; i < CHACHA20_NONCE_WORDS; i++) state->n[i] = load32le(¶ms->nonce[i * 4]); - state->mlen = 0; + state->blen = 0; hchacha20_block(state); @@ -91,35 +91,35 @@ chacha20_anycrypt_update(void *arg, uint8_t *out, size_t *outlen, uint32_t h; *outlen = 0; - if (inlen > SIZE_MAX - (LC_CHACHA20_BLOCKLEN - 1) - state->mlen) + if (inlen > SIZE_MAX - (LC_CHACHA20_BLOCKLEN - 1) - state->blen) return 0; - blocks = (inlen + state->mlen + LC_CHACHA20_BLOCKLEN - 1) / + blocks = (inlen + state->blen + LC_CHACHA20_BLOCKLEN - 1) / LC_CHACHA20_BLOCKLEN; if (blocks + state->n[0] > CHACHA20_CTRMAX) return 0; - *outlen = state->mlen + inlen - - ((state->mlen + inlen) % LC_CHACHA20_BLOCKLEN); + *outlen = state->blen + inlen - + ((state->blen + inlen) % LC_CHACHA20_BLOCKLEN); if (out == NULL) return 1; - for (i = 0; i + state->mlen < LC_CHACHA20_BLOCKLEN && i < inlen; i++) - state->m[i + state->mlen] = in[i]; - state->mlen += i; + for (i = 0; i + state->blen < LC_CHACHA20_BLOCKLEN && i < inlen; i++) + state->b[i + state->blen] = in[i]; + state->blen += i; in += i; inlen -= i; - if (state->mlen == LC_CHACHA20_BLOCKLEN) { + if (state->blen == LC_CHACHA20_BLOCKLEN) { chacha20_block(state); state->n[0]++; for (i = 0; i < CHACHA20_BLOCKLEN_WORDS; i++) { - h = load32le(&state->m[i * 4]); + h = load32le(&state->b[i * 4]); h ^= state->s[i]; store32le(&out[i * 4], h); } out += LC_CHACHA20_BLOCKLEN; - state->mlen = 0; + state->blen = 0; } if (inlen == 0) @@ -140,8 +140,8 @@ chacha20_anycrypt_update(void *arg, uint8_t *out, size_t *outlen, } for (i = 0; i < inlen; i++) - state->m[i] = in[i]; - state->mlen = inlen; + state->b[i] = in[i]; + state->blen = inlen; return 1; } @@ -154,25 +154,25 @@ chacha20_anycrypt_final(void *arg, uint8_t *out, size_t *outlen) uint32_t h; uint8_t s[4]; - *outlen = state->mlen; + *outlen = state->blen; if (out == NULL) return 1; - if (state->mlen > 0) + if (state->blen > 0) chacha20_block(state); - for (i = 0; i < state->mlen / 4; i++) { - h = load32le(&state->m[i * 4]); + for (i = 0; i < state->blen / 4; i++) { + h = load32le(&state->b[i * 4]); h ^= state->s[i]; store32le(&out[i * 4], h); } off = i * 4; - state->mlen -= off; + state->blen -= off; out += off; store32le(&s[0], state->s[i]); - for (i = 0; i < state->mlen; i++) - out[i] = state->m[i + off] ^ s[i]; + for (i = 0; i < state->blen; i++) + out[i] = state->b[i + off] ^ s[i]; lc_scrub(state, sizeof(*state)); diff --git a/hash_sha224_sha256.c b/hash_sha224_sha256.c index 2594590..0e64357 100644 --- a/hash_sha224_sha256.c +++ b/hash_sha224_sha256.c @@ -70,9 +70,9 @@ sha224_init(void *arg) state->sz = 0; - state->mlen = 0; + state->blen = 0; for (i = 0; i < LC_SHA256_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; return 1; } @@ -94,9 +94,9 @@ sha256_init(void *arg) state->sz = 0; - state->mlen = 0; + state->blen = 0; for (i = 0; i < LC_SHA256_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; return 1; } @@ -111,15 +111,15 @@ sha224_sha256_update(void *arg, const uint8_t *in, size_t inlen) return 0; state->sz += inlen; - for (i = 0; i + state->mlen < LC_SHA256_BLOCKLEN && i < inlen; i++) - state->m[i + state->mlen] = in[i]; - state->mlen += i; + for (i = 0; i + state->blen < LC_SHA256_BLOCKLEN && i < inlen; i++) + state->b[i + state->blen] = in[i]; + state->blen += i; in += i; inlen -= i; - if (state->mlen == LC_SHA256_BLOCKLEN) { + if (state->blen == LC_SHA256_BLOCKLEN) { sha256_block(state); - state->mlen = 0; + state->blen = 0; } if (inlen == 0) @@ -127,7 +127,7 @@ sha224_sha256_update(void *arg, const uint8_t *in, size_t inlen) while (inlen >= LC_SHA256_BLOCKLEN) { for (i = 0; i < LC_SHA256_BLOCKLEN; i++) - state->m[i] = in[i]; + state->b[i] = in[i]; in += i; inlen -= i; @@ -135,8 +135,8 @@ sha224_sha256_update(void *arg, const uint8_t *in, size_t inlen) } for (i = 0; i < inlen; i++) - state->m[i] = in[i]; - state->mlen = inlen; + state->b[i] = in[i]; + state->blen = inlen; return 1; } @@ -158,19 +158,19 @@ sha224_sha256_final(struct sha256_state *state) { size_t i, mlen; - mlen = state->mlen; - state->m[mlen++] = 0x80; + mlen = state->blen; + state->b[mlen++] = 0x80; if (mlen >= LC_SHA256_BLOCKLEN - sizeof(uint64_t)) { for (i = mlen; i < LC_SHA256_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; sha256_block(state); mlen = 0; } for (i = mlen; i < LC_SHA256_BLOCKLEN - sizeof(uint64_t); i++) - state->m[i] = 0; - store64be(&state->m[i], state->sz << 3); + state->b[i] = 0; + store64be(&state->b[i], state->sz << 3); sha256_block(state); } diff --git a/hash_sha384_sha512.c b/hash_sha384_sha512.c index f1fd133..320ba9c 100644 --- a/hash_sha384_sha512.c +++ b/hash_sha384_sha512.c @@ -71,9 +71,9 @@ sha384_init(void *arg) state->szhi = state->szlo = 0; - state->mlen = 0; + state->blen = 0; for (i = 0; i < LC_SHA512_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; return 1; } @@ -95,9 +95,9 @@ sha512_init(void *arg) state->szhi = state->szlo = 0; - state->mlen = 0; + state->blen = 0; for (i = 0; i < LC_SHA512_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; return 1; } @@ -116,15 +116,15 @@ sha384_sha512_update(void *arg, const uint8_t *in, size_t inlen) } else state->szlo += inlen; - for (i = 0; i + state->mlen < LC_SHA512_BLOCKLEN && i < inlen; i++) - state->m[i + state->mlen] = in[i]; - state->mlen += i; + for (i = 0; i + state->blen < LC_SHA512_BLOCKLEN && i < inlen; i++) + state->b[i + state->blen] = in[i]; + state->blen += i; in += i; inlen -= i; - if (state->mlen == LC_SHA512_BLOCKLEN) { + if (state->blen == LC_SHA512_BLOCKLEN) { sha512_block(state); - state->mlen = 0; + state->blen = 0; } if (inlen == 0) @@ -132,7 +132,7 @@ sha384_sha512_update(void *arg, const uint8_t *in, size_t inlen) while (inlen >= LC_SHA512_BLOCKLEN) { for (i = 0; i < LC_SHA512_BLOCKLEN; i++) - state->m[i] = in[i]; + state->b[i] = in[i]; in += i; inlen -= i; @@ -140,8 +140,8 @@ sha384_sha512_update(void *arg, const uint8_t *in, size_t inlen) } for (i = 0; i < inlen; i++) - state->m[i] = in[i]; - state->mlen = inlen; + state->b[i] = in[i]; + state->blen = inlen; return 1; } @@ -163,20 +163,20 @@ sha384_sha512_final(struct sha512_state *state) { size_t i, mlen; - mlen = state->mlen; - state->m[mlen++] = 0x80; + mlen = state->blen; + state->b[mlen++] = 0x80; if (mlen >= LC_SHA512_BLOCKLEN - 2 * sizeof(uint64_t)) { for (i = mlen; i < LC_SHA512_BLOCKLEN; i++) - state->m[i] = 0; + state->b[i] = 0; sha512_block(state); mlen = 0; } for (i = mlen; i < LC_SHA512_BLOCKLEN - 2 * sizeof(uint64_t); i++) - state->m[i] = 0; - store64be(&state->m[i], (state->szhi << 3) | (state->szlo >> 63)); - store64be(&state->m[i + sizeof(uint64_t)], state->szlo << 3); + state->b[i] = 0; + store64be(&state->b[i], (state->szhi << 3) | (state->szlo >> 63)); + store64be(&state->b[i + sizeof(uint64_t)], state->szlo << 3); sha512_block(state); } diff --git a/impl_chacha20.h b/impl_chacha20.h index 5e03208..a7eca8d 100644 --- a/impl_chacha20.h +++ b/impl_chacha20.h @@ -28,8 +28,8 @@ struct chacha20_state { uint32_t s[CHACHA20_BLOCKLEN_WORDS]; uint32_t k[CHACHA20_KEY_WORDS]; uint32_t n[CHACHA20_NONCE_WORDS]; - size_t mlen; - uint8_t m[LC_CHACHA20_BLOCKLEN]; + size_t blen; + uint8_t b[LC_CHACHA20_BLOCKLEN]; }; diff --git a/impl_poly1305.c b/impl_poly1305.c index f31179b..ece9f57 100644 --- a/impl_poly1305.c +++ b/impl_poly1305.c @@ -167,10 +167,10 @@ poly1305_block(struct poly1305_state *state, uint32_t hibit) x3 = state->x3; x4 = state->x4; - t0 = load32le(&state->m[0]); - t1 = load32le(&state->m[4]); - t2 = load32le(&state->m[8]); - t3 = load32le(&state->m[12]); + t0 = load32le(&state->b[0]); + t1 = load32le(&state->b[4]); + t2 = load32le(&state->b[8]); + t3 = load32le(&state->b[12]); t4 = hibit; h0 += t0 & 0x3ffffff; diff --git a/impl_poly1305.h b/impl_poly1305.h index b0a2482..92a39d7 100644 --- a/impl_poly1305.h +++ b/impl_poly1305.h @@ -25,8 +25,8 @@ struct poly1305_state { uint32_t r0, r1, r2, r3, r4; uint32_t x1, x2, x3, x4; uint32_t s0, s1, s2, s3; - size_t mlen; - uint8_t m[LC_POLY1305_BLOCKLEN]; + size_t blen; + uint8_t b[LC_POLY1305_BLOCKLEN]; }; diff --git a/impl_sha256.c b/impl_sha256.c index f23f082..812f3fb 100644 --- a/impl_sha256.c +++ b/impl_sha256.c @@ -55,7 +55,7 @@ sha256_block(struct sha256_state *state) size_t i; for (i = 0; i < SHA256_BLOCKLEN_WORDS; i++) - W[i] = m[i] = load32be(&state->m[i * 4]); + W[i] = m[i] = load32be(&state->b[i * 4]); for (; i < SHA256_ROUNDS; i++) W[i] = SSIG1(W[i - 2]) + W[i - 7] + SSIG0(W[i - 15]) + W[i - 16]; diff --git a/impl_sha256.h b/impl_sha256.h index 4d92a04..d109098 100644 --- a/impl_sha256.h +++ b/impl_sha256.h @@ -24,8 +24,8 @@ struct sha256_state { uint32_t h0, h1, h2, h3, h4, h5, h6, h7; uint64_t sz; - size_t mlen; - uint8_t m[LC_SHA256_BLOCKLEN]; + size_t blen; + uint8_t b[LC_SHA256_BLOCKLEN]; }; diff --git a/impl_sha512.c b/impl_sha512.c index e533b72..925708d 100644 --- a/impl_sha512.c +++ b/impl_sha512.c @@ -79,7 +79,7 @@ sha512_block(struct sha512_state *state) size_t i; for (i = 0; i < SHA512_BLOCKLEN_WORDS; i++) - W[i] = m[i] = load64be(&state->m[i * 8]); + W[i] = m[i] = load64be(&state->b[i * 8]); for (; i < SHA512_ROUNDS; i++) W[i] = SSIG1(W[i - 2]) + W[i - 7] + SSIG0(W[i - 15]) + W[i - 16]; diff --git a/impl_sha512.h b/impl_sha512.h index 24a080e..a33db47 100644 --- a/impl_sha512.h +++ b/impl_sha512.h @@ -24,8 +24,8 @@ struct sha512_state { uint64_t h0, h1, h2, h3, h4, h5, h6, h7; uint64_t szhi, szlo; - size_t mlen; - uint8_t m[LC_SHA512_BLOCKLEN]; + size_t blen; + uint8_t b[LC_SHA512_BLOCKLEN]; };