From: Niels Möller Date: Thu, 2 Feb 2023 18:50:33 +0000 (+0100) Subject: Simplify ocb_crypt_n logic, less duplication. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1839172702e6a54b3adfc7097ec926ea5b132c3f;p=thirdparty%2Fnettle.git Simplify ocb_crypt_n logic, less duplication. --- diff --git a/ocb.c b/ocb.c index 167b8cf5..9d82d43f 100644 --- 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