diff options
author | Niels Möller <nisse@lysator.liu.se> | 2023-02-01 17:23:32 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2023-02-06 20:27:58 +0100 |
commit | 5ca5504ebf361899fb2fbf5485cbfa7aabb8c491 (patch) | |
tree | 69bcf2f48d174c3efe36a3e20d7be52f3310caf2 | |
parent | 2324714fddef77faec25ab95f8e52ae88fa8de73 (diff) | |
download | nettle-5ca5504ebf361899fb2fbf5485cbfa7aabb8c491.tar.gz |
Simplify ocb_update logic, less duplication.
-rw-r--r-- | ocb.c | 19 |
1 files changed, 4 insertions, 15 deletions
@@ -185,10 +185,12 @@ ocb_update (struct ocb_ctx *ctx, const struct ocb_key *key, if (ctx->data_count == 0) ctx->offset.u64[0] = ctx->offset.u64[1] = 0; - while (n > OCB_MAX_BLOCKS) + while (n > 0) { - size_t blocks = OCB_MAX_BLOCKS - 1 + (ctx->data_count & 1); size_t size, i; + size_t blocks = (n <= OCB_MAX_BLOCKS) ? n + : OCB_MAX_BLOCKS - 1 + (ctx->data_count & 1); + ocb_fill_n (key, &ctx->offset, ctx->data_count, blocks, block); ctx->data_count += blocks; @@ -200,20 +202,7 @@ ocb_update (struct ocb_ctx *ctx, const struct ocb_key *key, n -= blocks; data += size; } - if (n > 0) - { - size_t size, i; - ocb_fill_n (key, &ctx->offset, ctx->data_count, n, block); - ctx->data_count += n; - size = n * OCB_BLOCK_SIZE; - memxor (block[0].b, data, size); - f (cipher, size, block[0].b, block[0].b); - for (i = 0; i < n; i++) - block16_xor(&ctx->sum, &block[i]); - - data += size; - } length &= 15; if (length > 0) { |