diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-24 22:02:13 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-25 03:01:21 +0200 |
commit | 6b7d734ee75319cc421c57f47d295ed911033947 (patch) | |
tree | 8176c3bd3b3e4e9c0157b256d11749530dbfd5e9 /src/crypto/zinc/blake2s/blake2s.c | |
parent | 3106f71185676be1b95a814e9015525dd17ab19c (diff) |
crypto: make constant naming scheme consistent
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/blake2s/blake2s.c')
-rw-r--r-- | src/crypto/zinc/blake2s/blake2s.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index a797524..5ce74c1 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -87,7 +87,7 @@ void blake2s_init(struct blake2s_state *state, const size_t outlen) }; #ifdef DEBUG - BUG_ON(!outlen || outlen > BLAKE2S_OUTBYTES); + BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE); #endif blake2s_init_param(state, ¶m); } @@ -100,16 +100,16 @@ void blake2s_init_key(struct blake2s_state *state, const size_t outlen, .key_length = keylen, .fanout = 1, .depth = 1 }; - u8 block[BLAKE2S_BLOCKBYTES] = { 0 }; + u8 block[BLAKE2S_BLOCK_SIZE] = { 0 }; #ifdef DEBUG - BUG_ON(!outlen || outlen > BLAKE2S_OUTBYTES || !key || !keylen || - keylen > BLAKE2S_KEYBYTES); + BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE || !key || !keylen || + keylen > BLAKE2S_KEY_SIZE); #endif blake2s_init_param(state, ¶m); memcpy(block, key, keylen); - blake2s_update(state, block, BLAKE2S_BLOCKBYTES); - memzero_explicit(block, BLAKE2S_BLOCKBYTES); + blake2s_update(state, block, BLAKE2S_BLOCK_SIZE); + memzero_explicit(block, BLAKE2S_BLOCK_SIZE); } EXPORT_SYMBOL(blake2s_init_key); @@ -136,7 +136,7 @@ static inline void blake2s_compress(struct blake2s_state *state, int i; #ifdef DEBUG - BUG_ON(nblocks > 1 && inc != BLAKE2S_BLOCKBYTES); + BUG_ON(nblocks > 1 && inc != BLAKE2S_BLOCK_SIZE); #endif if (blake2s_arch(state, block, nblocks, inc)) @@ -146,7 +146,7 @@ static inline void blake2s_compress(struct blake2s_state *state, blake2s_increment_counter(state, inc); #ifdef __LITTLE_ENDIAN - memcpy(m, block, BLAKE2S_BLOCKBYTES); + memcpy(m, block, BLAKE2S_BLOCK_SIZE); #else for (i = 0; i < 16; ++i) m[i] = get_unaligned_le32(block + i * sizeof(m[i])); @@ -199,31 +199,31 @@ static inline void blake2s_compress(struct blake2s_state *state, for (i = 0; i < 8; ++i) state->h[i] ^= v[i] ^ v[i + 8]; - block += BLAKE2S_BLOCKBYTES; + block += BLAKE2S_BLOCK_SIZE; --nblocks; } } void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen) { - const size_t fill = BLAKE2S_BLOCKBYTES - state->buflen; + const size_t fill = BLAKE2S_BLOCK_SIZE - state->buflen; if (unlikely(!inlen)) return; if (inlen > fill) { memcpy(state->buf + state->buflen, in, fill); - blake2s_compress(state, state->buf, 1, BLAKE2S_BLOCKBYTES); + blake2s_compress(state, state->buf, 1, BLAKE2S_BLOCK_SIZE); state->buflen = 0; in += fill; inlen -= fill; } - if (inlen > BLAKE2S_BLOCKBYTES) { + if (inlen > BLAKE2S_BLOCK_SIZE) { const size_t nblocks = - (inlen + BLAKE2S_BLOCKBYTES - 1) / BLAKE2S_BLOCKBYTES; + (inlen + BLAKE2S_BLOCK_SIZE - 1) / BLAKE2S_BLOCK_SIZE; /* Hash one less (full) block than strictly possible */ - blake2s_compress(state, in, nblocks - 1, BLAKE2S_BLOCKBYTES); - in += BLAKE2S_BLOCKBYTES * (nblocks - 1); - inlen -= BLAKE2S_BLOCKBYTES * (nblocks - 1); + blake2s_compress(state, in, nblocks - 1, BLAKE2S_BLOCK_SIZE); + in += BLAKE2S_BLOCK_SIZE * (nblocks - 1); + inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1); } memcpy(state->buf + state->buflen, in, inlen); state->buflen += inlen; @@ -233,11 +233,11 @@ EXPORT_SYMBOL(blake2s_update); void blake2s_final(struct blake2s_state *state, u8 *out, const size_t outlen) { #ifdef DEBUG - BUG_ON(!out || !outlen || outlen > BLAKE2S_OUTBYTES); + BUG_ON(!out || !outlen || outlen > BLAKE2S_HASH_SIZE); #endif blake2s_set_lastblock(state); memset(state->buf + state->buflen, 0, - BLAKE2S_BLOCKBYTES - state->buflen); /* Padding */ + BLAKE2S_BLOCK_SIZE - state->buflen); /* Padding */ blake2s_compress(state, state->buf, 1, state->buflen); cpu_to_le32_array(state->h, ARRAY_SIZE(state->h)); memcpy(out, state->h, outlen); @@ -249,36 +249,36 @@ void blake2s_hmac(u8 *out, const u8 *in, const u8 *key, const size_t outlen, const size_t inlen, const size_t keylen) { struct blake2s_state state; - u8 x_key[BLAKE2S_BLOCKBYTES] __aligned(__alignof__(u32)) = { 0 }; - u8 i_hash[BLAKE2S_OUTBYTES] __aligned(__alignof__(u32)); + u8 x_key[BLAKE2S_BLOCK_SIZE] __aligned(__alignof__(u32)) = { 0 }; + u8 i_hash[BLAKE2S_HASH_SIZE] __aligned(__alignof__(u32)); int i; - if (keylen > BLAKE2S_BLOCKBYTES) { - blake2s_init(&state, BLAKE2S_OUTBYTES); + if (keylen > BLAKE2S_BLOCK_SIZE) { + blake2s_init(&state, BLAKE2S_HASH_SIZE); blake2s_update(&state, key, keylen); - blake2s_final(&state, x_key, BLAKE2S_OUTBYTES); + blake2s_final(&state, x_key, BLAKE2S_HASH_SIZE); } else memcpy(x_key, key, keylen); - for (i = 0; i < BLAKE2S_BLOCKBYTES; ++i) + for (i = 0; i < BLAKE2S_BLOCK_SIZE; ++i) x_key[i] ^= 0x36; - blake2s_init(&state, BLAKE2S_OUTBYTES); - blake2s_update(&state, x_key, BLAKE2S_BLOCKBYTES); + blake2s_init(&state, BLAKE2S_HASH_SIZE); + blake2s_update(&state, x_key, BLAKE2S_BLOCK_SIZE); blake2s_update(&state, in, inlen); - blake2s_final(&state, i_hash, BLAKE2S_OUTBYTES); + blake2s_final(&state, i_hash, BLAKE2S_HASH_SIZE); - for (i = 0; i < BLAKE2S_BLOCKBYTES; ++i) + for (i = 0; i < BLAKE2S_BLOCK_SIZE; ++i) x_key[i] ^= 0x5c ^ 0x36; - blake2s_init(&state, BLAKE2S_OUTBYTES); - blake2s_update(&state, x_key, BLAKE2S_BLOCKBYTES); - blake2s_update(&state, i_hash, BLAKE2S_OUTBYTES); - blake2s_final(&state, i_hash, BLAKE2S_OUTBYTES); + blake2s_init(&state, BLAKE2S_HASH_SIZE); + blake2s_update(&state, x_key, BLAKE2S_BLOCK_SIZE); + blake2s_update(&state, i_hash, BLAKE2S_HASH_SIZE); + blake2s_final(&state, i_hash, BLAKE2S_HASH_SIZE); memcpy(out, i_hash, outlen); - memzero_explicit(x_key, BLAKE2S_BLOCKBYTES); - memzero_explicit(i_hash, BLAKE2S_OUTBYTES); + memzero_explicit(x_key, BLAKE2S_BLOCK_SIZE); + memzero_explicit(i_hash, BLAKE2S_HASH_SIZE); } EXPORT_SYMBOL(blake2s_hmac); |