aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/zinc/chacha20/chacha20.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/zinc/chacha20/chacha20.c')
-rw-r--r--src/crypto/zinc/chacha20/chacha20.c22
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);