diff options
author | Niels Möller <nisse@lysator.liu.se> | 2023-02-02 19:50:33 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2023-02-06 20:27:58 +0100 |
commit | 1839172702e6a54b3adfc7097ec926ea5b132c3f (patch) | |
tree | 2603c34119fc6f5683caa4a1f0fa9e69e8d8de3b | |
parent | 5ca5504ebf361899fb2fbf5485cbfa7aabb8c491 (diff) | |
download | nettle-1839172702e6a54b3adfc7097ec926ea5b132c3f.tar.gz |
Simplify ocb_crypt_n logic, less duplication.
-rw-r--r-- | ocb.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -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 |