From 764a4813828e85b47cdd955c2095e2080160b4df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Mon, 10 Feb 2014 19:26:51 +0100
Subject: [PATCH] Renamed chacha_set_iv to chacha_set_nonce.

---
 ChangeLog                             |  6 ++++++
 Makefile.in                           |  2 +-
 chacha-set-iv.c => chacha-set-nonce.c | 10 +++++-----
 chacha.h                              |  6 +++---
 nettle-internal.c                     |  4 ++--
 testsuite/chacha-test.c               |  8 ++++----
 6 files changed, 21 insertions(+), 15 deletions(-)
 rename chacha-set-iv.c => chacha-set-nonce.c (85%)

diff --git a/ChangeLog b/ChangeLog
index f5b9b1aa..25c161b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-02-10  Niels Möller  <nisse@lysator.liu.se>
+
+	* chacha-set-nonce.c (chacha_set_nonce): Renamed file and
+	function, updated callers and Makefile.in.
+	* chacha-set-iv.c (chacha_set_iv): ... from old names.
+
 2014-02-08  Niels Möller  <nisse@lysator.liu.se>
 
 	* testsuite/chacha-test.c (test_chacha): For 20 rounds, use
diff --git a/Makefile.in b/Makefile.in
index 61db7831..5782a38f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -88,7 +88,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
 		 camellia256-meta.c \
 		 cast128.c cast128-meta.c cbc.c \
 		 chacha-crypt.c chacha-core-internal.c \
-		 chacha-set-iv.c chacha-set-key.c \
+		 chacha-set-key.c chacha-set-nonce.c \
 		 chacha128-set-key.c chacha256-set-key.c \
 		 ctr.c gcm.c \
 		 des.c des3.c des-compat.c eax.c \
diff --git a/chacha-set-iv.c b/chacha-set-nonce.c
similarity index 85%
rename from chacha-set-iv.c
rename to chacha-set-nonce.c
index ab872bbe..78da9ff3 100644
--- a/chacha-set-iv.c
+++ b/chacha-set-nonce.c
@@ -1,6 +1,6 @@
-/* chacha-set-iv.c
+/* chacha-set-nonce.c
  *
- * Setting the IV the ChaCha stream cipher.
+ * Setting the nonce the ChaCha stream cipher.
  * Based on the Salsa20 implementation in Nettle.
  */
 
@@ -44,10 +44,10 @@
 #include "macros.h"
 
 void
-chacha_set_iv(struct chacha_ctx *ctx, const uint8_t *iv)
+chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce)
 {
   ctx->state[12] = 0;
   ctx->state[13] = 0;
-  ctx->state[14] = LE_READ_UINT32(iv + 0);
-  ctx->state[15] = LE_READ_UINT32(iv + 4);
+  ctx->state[14] = LE_READ_UINT32(nonce + 0);
+  ctx->state[15] = LE_READ_UINT32(nonce + 4);
 }
diff --git a/chacha.h b/chacha.h
index c8ec92b0..ae393435 100644
--- a/chacha.h
+++ b/chacha.h
@@ -39,7 +39,7 @@ extern "C" {
 #define chacha_set_key nettle_chacha_set_key
 #define chacha128_set_key nettle_chacha128_set_key
 #define chacha256_set_key nettle_chacha256_set_key
-#define chacha_set_iv nettle_chacha_set_iv
+#define chacha_set_nonce nettle_chacha_set_nonce
 #define chacha_crypt nettle_chacha_crypt
 #define _chacha_core _nettle_chacha_core
 
@@ -50,7 +50,7 @@ extern "C" {
 
 #define CHACHA_BLOCK_SIZE 64
 
-#define CHACHA_IV_SIZE 8
+#define CHACHA_NONCE_SIZE 8
 
 #define _CHACHA_STATE_LENGTH 16
 
@@ -81,7 +81,7 @@ chacha_set_key(struct chacha_ctx *ctx,
 	       size_t length, const uint8_t *key);
 
 void
-chacha_set_iv(struct chacha_ctx *ctx, const uint8_t *iv);
+chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
 
 void
 chacha_crypt(struct chacha_ctx *ctx, size_t length, 
diff --git a/nettle-internal.c b/nettle-internal.c
index 6733a3f1..92156982 100644
--- a/nettle-internal.c
+++ b/nettle-internal.c
@@ -77,9 +77,9 @@ nettle_blowfish128 =
 static void
 chacha_set_key_hack(void *ctx, const uint8_t *key)
 {
-  static const uint8_t iv[CHACHA_IV_SIZE];
+  static const uint8_t nonce[CHACHA_NONCE_SIZE];
   chacha256_set_key (ctx, key);
-  chacha_set_iv (ctx, iv);
+  chacha_set_nonce (ctx, nonce);
 }
 
 /* Claim zero block size, to classify as a stream cipher. */
diff --git a/testsuite/chacha-test.c b/testsuite/chacha-test.c
index 0095333d..8f16a5a1 100644
--- a/testsuite/chacha-test.c
+++ b/testsuite/chacha-test.c
@@ -29,13 +29,13 @@
 #include "chacha.h"
 
 static void
-test_chacha(const struct tstring *key, const struct tstring *iv,
+test_chacha(const struct tstring *key, const struct tstring *nonce,
 	    const struct tstring *expected, unsigned rounds)
 {
   struct chacha_ctx ctx;
 
   chacha_set_key (&ctx, key->length, key->data);
-  ASSERT (iv->length == CHACHA_IV_SIZE);
+  ASSERT (nonce->length == CHACHA_NONCE_SIZE);
 
   if (rounds == 20)
     {
@@ -48,7 +48,7 @@ test_chacha(const struct tstring *key, const struct tstring *iv,
 	  data[-1] = 17;
 	  memset (data, 0, length);
 	  data[length] = 17;
-	  chacha_set_iv(&ctx, iv->data);
+	  chacha_set_nonce(&ctx, nonce->data);
 	  chacha_crypt (&ctx, length, data, data);
 
 	  ASSERT (data[-1] == 17);
@@ -76,7 +76,7 @@ test_chacha(const struct tstring *key, const struct tstring *iv,
       uint32_t out[_CHACHA_STATE_LENGTH];
       ASSERT (expected->length == CHACHA_BLOCK_SIZE);
 
-      chacha_set_iv(&ctx, iv->data);
+      chacha_set_nonce(&ctx, nonce->data);
       _chacha_core (out, ctx.state, rounds);
 
       if (!MEMEQ(CHACHA_BLOCK_SIZE, out, expected->data))
-- 
GitLab