]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Simplify ocb_crypt_n logic, less duplication.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 2 Feb 2023 18:50:33 +0000 (19:50 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 6 Feb 2023 19:27:58 +0000 (20:27 +0100)
ocb.c

diff --git a/ocb.c b/ocb.c
index 167b8cf5d400bbe2f2ac5acf4727cf38e2b7b96f..9d82d43f22db0c2b03c30276e4674d6f7828562d 100644 (file)
--- a/ocb.c
+++ b/ocb.c
@@ -224,9 +224,11 @@ ocb_crypt_n (struct ocb_ctx *ctx, const struct ocb_key *key,
   union nettle_block16 o[OCB_MAX_BLOCKS], block[OCB_MAX_BLOCKS];
   size_t size;
 
-  while (n > OCB_MAX_BLOCKS)
+  while (n > 0)
     {
-      size_t blocks = OCB_MAX_BLOCKS - 1 + (ctx->message_count & 1);
+      size_t blocks = (n <= OCB_MAX_BLOCKS) ? n
+       : OCB_MAX_BLOCKS - 1 + (ctx->message_count & 1);
+
       ocb_fill_n (key, &ctx->offset, ctx->message_count, blocks, o);
       ctx->message_count += n;
 
@@ -237,13 +239,6 @@ ocb_crypt_n (struct ocb_ctx *ctx, const struct ocb_key *key,
 
       n -= blocks; src += size; dst -= size;
     }
-  ocb_fill_n (key, &ctx->offset, ctx->message_count, n, o);
-  ctx->message_count += n;
-
-  size = n * OCB_BLOCK_SIZE;
-  memxor3 (block[0].b, o[0].b, src, size);
-  f (cipher, size, block[0].b, block[0].b);
-  memxor3 (dst, block[0].b, o[0].b, size);
 }
 
 #if 0