Fixed umac nonce increment.
authorNiels Möller <nisse@lysator.liu.se>
Tue, 16 Apr 2013 05:59:40 +0000 (07:59 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Tue, 16 Apr 2013 05:59:40 +0000 (07:59 +0200)
ChangeLog
umac128.c
umac32.c
umac64.c
umac96.c

index d069e75addeca783d4455f60652433b6a310bb2b..59f37bf3b28b6390a7f019baf8d6a605d0478f74 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2013-04-16  Niels Möller  <nisse@lysator.liu.se>
 
+       * umac32.c (umac32_digest): Fix nonce increment, use INCREMENT
+       macro.
+       * umac64.c (umac64_digest): Likewise.
+       * umac96.c (umac96_digest): Likewise.
+       * umac128.c (umac128_digest): Likewise.
+
        * macros.h (INCREMENT): Allow size == 1.
 
 2013-04-15  Niels Möller  <nisse@lysator.liu.se>
index 74936021449b1f6e731e54b2bc042de14d2fa65c..6d33b4f9a7463db87a72a529929f03dfb8d43258 100644 (file)
--- a/umac128.c
+++ b/umac128.c
@@ -108,12 +108,7 @@ umac128_digest (struct umac128_ctx *ctx,
   aes_encrypt (&ctx->pdf_key, AES_BLOCK_SIZE,
               (uint8_t *) tag, ctx->nonce);
 
-  /* Increment nonce */
-  i = ctx->nonce_length - 1;
-  if (++ctx->nonce[i] == 0)
-    while (i > 0)
-      if (++ctx->nonce[--i] == 0)
-       break;
+  INCREMENT (ctx->nonce_length, ctx->nonce);
 
   _umac_l2_final (ctx->l2_key, ctx->l2_state, 4, ctx->count, ctx->l1_out);
   for (i = 0; i < 4; i++)
index c3714fa3228e425b66601b6c6318c71128c3f83d..98f987e9b359b0af16968d1a34cf22996cfe8f87 100644 (file)
--- a/umac32.c
+++ b/umac32.c
@@ -115,10 +115,8 @@ umac32_digest (struct umac32_ctx *ctx,
       ctx->nonce_low = 0;
       ctx->nonce[i] += 4;
 
-      if (ctx->nonce[i] == 0)
-       while (i > 0)
-         if (++ctx->nonce[--i] == 0)
-           break;
+      if (ctx->nonce[i] == 0 && i > 0)
+       INCREMENT (i, ctx->nonce);
     }
 
   _umac_l2_final (ctx->l2_key, ctx->l2_state, 1, ctx->count, ctx->l1_out);
index 6f8132de9508039fd401d1dce49f0a0b37e28958..b2a6970984c1dc68b344ca434dc48ebd5c2ab9b2 100644 (file)
--- a/umac64.c
+++ b/umac64.c
@@ -118,10 +118,8 @@ umac64_digest (struct umac64_ctx *ctx,
       ctx->nonce_low = 0;
       ctx->nonce[i] += 2;
 
-      if (ctx->nonce[i] == 0)
-       while (i > 0)
-         if (++ctx->nonce[--i] == 0)
-           break;
+      if (ctx->nonce[i] == 0 && i > 0)
+       INCREMENT (i, ctx->nonce);
     }
 
   _umac_l2_final (ctx->l2_key, ctx->l2_state, 2, ctx->count, ctx->l1_out);
index b4b43ed7b90fd7885ed11450400bd5c72137e994..2831ad14615163c4912de2028afcc74aa566e2aa 100644 (file)
--- a/umac96.c
+++ b/umac96.c
@@ -106,12 +106,7 @@ umac96_digest (struct umac96_ctx *ctx,
   aes_encrypt (&ctx->pdf_key, AES_BLOCK_SIZE,
               (uint8_t *) tag, ctx->nonce);
 
-  /* Increment nonce */
-  i = ctx->nonce_length - 1;
-  if (++ctx->nonce[i] == 0)
-    while (i > 0)
-      if (++ctx->nonce[--i] == 0)
-       break;
+  INCREMENT (ctx->nonce_length, ctx->nonce);
 
   _umac_l2_final (ctx->l2_key, ctx->l2_state, 3, ctx->count, ctx->l1_out);
   for (i = 0; i < 3; i++)