From a56ede1947297720b93915e68eb9ad1efc391e02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 16 Apr 2013 14:22:08 +0200
Subject: [PATCH] Increase umac block count to 64 bits. Some reordering of umac
 contexts.

---
 ChangeLog |  5 +++++
 umac-l2.c |  4 ++--
 umac.h    | 26 +++++++++++++++++---------
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 35da57d3..bc0c950c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2013-04-16  Niels Möller  <nisse@lysator.liu.se>
 
+	* umac.h (umac32_ctx, umac64_ctx, umac96_ctx, umac128_ctx): Make
+	block count an uint64_t. Reorder some elements to put short values
+	together.
+	* umac-l2.c (_umac_l2, _umac_l2_final): Make count argument an uint64_t.
+
 	* configure.ac: Changed version number to 2.7.
 	(LIBNETTLE_MINOR): Bumped library version, to 4.6
 	(LIBHOGWEED_MINOR): And to 2.4
diff --git a/umac-l2.c b/umac-l2.c
index 7fa5650b..f0ca122d 100644
--- a/umac-l2.c
+++ b/umac-l2.c
@@ -57,7 +57,7 @@ _umac_l2_init (unsigned size, uint32_t *k)
 
 void
 _umac_l2(const uint32_t *key, uint64_t *state, unsigned n,
-	 unsigned count, uint64_t *prev, const uint64_t *m)
+	 uint64_t count, uint64_t *prev, const uint64_t *m)
 {
   unsigned i;
 
@@ -95,7 +95,7 @@ _umac_l2(const uint32_t *key, uint64_t *state, unsigned n,
 
 void
 _umac_l2_final(const uint32_t *key, uint64_t *state, unsigned n,
-	       unsigned count, uint64_t *prev)
+	       uint64_t count, uint64_t *prev)
 {
   unsigned i;
 
diff --git a/umac.h b/umac.h
index a2fd0101..6f4d831c 100644
--- a/umac.h
+++ b/umac.h
@@ -81,39 +81,47 @@ extern "C" {
   /* Input to the pdf_key, zero-padded and low bits	\
      cleared if appropriate. */				\
   uint8_t nonce[AES_BLOCK_SIZE];			\
-  unsigned short nonce_length; /* For incrementing */	\
-  /* Buffering */					\
+  unsigned short nonce_length /* For incrementing */
+
+  /* Buffering */ 
+#define _UMAC_BUFFER					\
   /* Complete blocks processed */			\
-  unsigned count;					\
   unsigned index;					\
-  uint8_t block[UMAC_BLOCK_SIZE];
-
+  uint64_t count;					\
+  uint8_t block[UMAC_BLOCK_SIZE]
+  
 #define _UMAC_NONCE_CACHED 0x80
 
 struct umac32_ctx
 {
   _UMAC_STATE(1);
-  unsigned short nonce_low; /* Low bits, plus some flag for the pad cache. */
+  /* Low bits and cache flag. */
+  unsigned short nonce_low;
   /* Previous padding block */
   uint32_t pad_cache[AES_BLOCK_SIZE / 4];
+  _UMAC_BUFFER;
 };
 
 struct umac64_ctx
 {
   _UMAC_STATE(2);
-  int nonce_low; /* Low bits, plus some flag for the pad cache. */
+  /* Low bit and cache flag. */
+  unsigned short nonce_low;
   /* Previous padding block */
   uint32_t pad_cache[AES_BLOCK_SIZE/4];
+  _UMAC_BUFFER;
 };
 
 struct umac96_ctx
 {
   _UMAC_STATE(3);
+  _UMAC_BUFFER;
 };
 
 struct umac128_ctx
 {
   _UMAC_STATE(4);
+  _UMAC_BUFFER;
 };
 
 /* The _set_key function initialize the nonce to zero. */
@@ -211,11 +219,11 @@ _umac_l2_init (unsigned size, uint32_t *k);
 
 void
 _umac_l2(const uint32_t *key, uint64_t *state, unsigned n,
-	 unsigned count, uint64_t *prev, const uint64_t *m);
+	 uint64_t count, uint64_t *prev, const uint64_t *m);
 
 void
 _umac_l2_final(const uint32_t *key, uint64_t *state, unsigned n,
-	       unsigned count, uint64_t *prev);
+	       uint64_t count, uint64_t *prev);
 
 void
 _umac_l3_init (unsigned size, uint64_t *k);
-- 
GitLab