Merge branch 'mdw/rsvr'
[catacomb] / symm / chacha.c
index 37c6cfb..983f58c 100644 (file)
@@ -153,6 +153,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
@@ -168,8 +170,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);
 }
@@ -405,8 +405,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;                                                \
@@ -595,7 +593,7 @@ CHACHA_VARS(DEFGCIPHER)
                                                                        \
   const gccipher xchacha##r = {                                                \
     "xchacha" #r, chacha_keysz,                                                \
-    CHACHA_NONCESZ, gxinit_##r                                         \
+    XCHACHA_NONCESZ, gxinit_##r                                                \
   };
 
 CHACHA_VARS(DEFGXCIPHER)