From bfff260d2465d42b5916640dc70e91953b967b56 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 4 Sep 2019 18:42:32 +0100 Subject: [PATCH] symm/chacha.c, symm/salsa20.c: Merge the `zerononce' values. Previously, each file had four separate `zerononce' values, for no good reason. Consolidate them. (I haven't merged them across the files, to keep the implementations self-contained.) --- symm/chacha.c | 6 ++---- symm/salsa20.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/symm/chacha.c b/symm/chacha.c index 84b6c36f..a30516de 100644 --- a/symm/chacha.c +++ b/symm/chacha.c @@ -152,6 +152,8 @@ static void populate(chacha_matrix a, const void *key, size_t ksz) /*----- ChaCha implementation ---------------------------------------------*/ +static const octet zerononce[XCHACHA_NONCESZ]; + /* --- @chacha_init@ --- * * * Arguments: @chacha_ctx *ctx@ = context to fill in @@ -167,8 +169,6 @@ static void populate(chacha_matrix a, const void *key, size_t ksz) void chacha_init(chacha_ctx *ctx, const void *key, size_t ksz, const void *nonce) { - static const octet zerononce[CHACHA_NONCESZ]; - populate(ctx->a, key, ksz); chacha_setnonce(ctx, nonce ? nonce : zerononce); } @@ -403,8 +403,6 @@ CHACHA_VARS(DEFHCHACHA) void XCHACHA_INIT(r, XCHACHA_CTX(r) *ctx, \ const void *key, size_t ksz, const void *nonce) \ { \ - static const octet zerononce[XCHACHA_NONCESZ]; \ - \ populate(ctx->k, key, ksz); \ ctx->s.a[ 0] = CHACHA_A256; \ ctx->s.a[ 1] = CHACHA_B256; \ diff --git a/symm/salsa20.c b/symm/salsa20.c index e78baf05..cc01cf75 100644 --- a/symm/salsa20.c +++ b/symm/salsa20.c @@ -161,6 +161,8 @@ static void populate(salsa20_matrix a, const void *key, size_t ksz) /*----- Salsa20 implementation --------------------------------------------*/ +static const octet zerononce[XSALSA20_NONCESZ]; + /* --- @salsa20_init@ --- * * * Arguments: @salsa20_ctx *ctx@ = context to fill in @@ -176,8 +178,6 @@ static void populate(salsa20_matrix a, const void *key, size_t ksz) void salsa20_init(salsa20_ctx *ctx, const void *key, size_t ksz, const void *nonce) { - static const octet zerononce[SALSA20_NONCESZ]; - populate(ctx->a, key, ksz); salsa20_setnonce(ctx, nonce ? nonce : zerononce); } @@ -421,8 +421,6 @@ SALSA20_VARS(DEFHSALSA20) void XSALSA20_INIT(r, XSALSA20_CTX(r) *ctx, \ const void *key, size_t ksz, const void *nonce) \ { \ - static const octet zerononce[XSALSA20_NONCESZ]; \ - \ populate(ctx->k, key, ksz); \ ctx->s.a[ 0] = SALSA20_A256; \ ctx->s.a[ 1] = SALSA20_B256; \ -- 2.11.0