symm/chacha.c, symm/salsa20.c: Merge the `zerononce' values.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 4 Sep 2019 17:42:32 +0000 (18:42 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 4 Sep 2019 21:37:41 +0000 (22:37 +0100)
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
symm/salsa20.c

index 84b6c36..a30516d 100644 (file)
@@ -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;                                                \
index e78baf0..cc01cf7 100644 (file)
@@ -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;                                       \