diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-30 03:07:51 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-02 03:41:49 +0200 |
commit | 6c470a7f5f5e3c115dce116b358df97bb3ebb37a (patch) | |
tree | e989ffe895f5a8d5b5d3d4576a489f89bb9cbba1 /src/crypto/zinc/chacha20/chacha20.c | |
parent | 8451e85a596dbd8f9f961f49a3e7ee09ac82aa10 (diff) |
chacha20: split chacha20_ctx into union
This avoids casts and makes counter increments obvious.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/chacha20/chacha20.c')
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c index 3415105..3f0392f 100644 --- a/src/crypto/zinc/chacha20/chacha20.c +++ b/src/crypto/zinc/chacha20/chacha20.c @@ -25,7 +25,7 @@ static void __init chacha20_fpu_init(void) { } -static inline bool chacha20_arch(struct chacha20_ctx *state, u8 *dst, +static inline bool chacha20_arch(struct chacha20_ctx *ctx, u8 *dst, const u8 *src, size_t len, simd_context_t *simd_context) { @@ -79,45 +79,45 @@ static inline bool hchacha20_arch(u32 derived_key[CHACHA20_KEY_WORDS], DOUBLE_ROUND(x) \ ) -static void chacha20_block_generic(__le32 *stream, u32 *state) +static void chacha20_block_generic(struct chacha20_ctx *ctx, __le32 *stream) { u32 x[CHACHA20_BLOCK_WORDS]; int i; for (i = 0; i < ARRAY_SIZE(x); ++i) - x[i] = state[i]; + x[i] = ctx->state[i]; TWENTY_ROUNDS(x); for (i = 0; i < ARRAY_SIZE(x); ++i) - stream[i] = cpu_to_le32(x[i] + state[i]); + stream[i] = cpu_to_le32(x[i] + ctx->state[i]); - ++state[12]; + ctx->counter[0] += 1; } -static void chacha20_generic(struct chacha20_ctx *state, u8 *out, const u8 *in, +static void chacha20_generic(struct chacha20_ctx *ctx, u8 *out, const u8 *in, u32 len) { __le32 buf[CHACHA20_BLOCK_WORDS]; while (len >= CHACHA20_BLOCK_SIZE) { - chacha20_block_generic(buf, (u32 *)state); + chacha20_block_generic(ctx, buf); crypto_xor_cpy(out, in, (u8 *)buf, CHACHA20_BLOCK_SIZE); len -= CHACHA20_BLOCK_SIZE; out += CHACHA20_BLOCK_SIZE; in += CHACHA20_BLOCK_SIZE; } if (len) { - chacha20_block_generic(buf, (u32 *)state); + chacha20_block_generic(ctx, buf); crypto_xor_cpy(out, in, (u8 *)buf, len); } } -void chacha20(struct chacha20_ctx *state, u8 *dst, const u8 *src, u32 len, +void chacha20(struct chacha20_ctx *ctx, u8 *dst, const u8 *src, u32 len, simd_context_t *simd_context) { - if (!chacha20_arch(state, dst, src, len, simd_context)) - chacha20_generic(state, dst, src, len); + if (!chacha20_arch(ctx, dst, src, len, simd_context)) + chacha20_generic(ctx, dst, src, len); } EXPORT_SYMBOL(chacha20); |