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 | 26b94a83ba634669cfcc0fc362ffe1f2eaefb43f (patch) | |
tree | 9dcf99b3d71414beee6ad924e667f66bd7173708 /src/crypto/zinc/chacha20/chacha20.c | |
parent | qemu: support m68k (diff) | |
download | wireguard-monolithic-historical-26b94a83ba634669cfcc0fc362ffe1f2eaefb43f.tar.xz wireguard-monolithic-historical-26b94a83ba634669cfcc0fc362ffe1f2eaefb43f.zip |
chacha20: split chacha20_ctx into union
This avoids casts and makes counter increments obvious.
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); |