Skip to content

Commit

Permalink
FIX: using shorter code variant for extending a series at its tail
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 10, 2022
1 parent 044c59d commit 4fb0acd
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/core/p-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
if (blk > 0 && len < blk) return 0;

// make space at tail if needed...
ofs = SERIES_TAIL(bin);
Expand_Series(bin, AT_TAIL, len);
// reset the tail (above expand modifies it!)
SERIES_TAIL(bin) = ofs;
Extend_Series(bin, len);

switch (ctx->cipher_type) {

Expand Down Expand Up @@ -858,9 +855,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
//puts("update");
#ifdef MBEDTLS_CHACHAPOLY_C
if (ctx->cipher_type == SYM_CHACHA20_POLY1305) {
olen = SERIES_TAIL(bin);
Expand_Series(bin, AT_TAIL, 16);
SERIES_TAIL(bin) = olen; // reset the tail (above expand modifies it!)
Extend_Series(bin, 16);
err = mbedtls_chachapoly_finish((mbedtls_chachapoly_context*)ctx->cipher_ctx, BIN_TAIL(bin));
SERIES_TAIL(bin) += 16;
ctx->state = CRYPT_PORT_NEEDS_AAD;
Expand All @@ -870,10 +865,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
if (ctx->unprocessed_len > 0) {
ofs = 0;
blk = ctx->cipher_block_size;
olen = SERIES_TAIL(bin);
Expand_Series(bin, AT_TAIL, blk);
// reset the tail (above expand modifies it!)
SERIES_TAIL(bin) = olen;
Extend_Series(bin, blk);

if (ctx->unprocessed_len > blk) abort();
len = blk - ctx->unprocessed_len;
Expand Down

0 comments on commit 4fb0acd

Please sign in to comment.