Skip to content

Commit 4fb0acd

Browse files
committed
FIX: using shorter code variant for extending a series at its tail
1 parent 044c59d commit 4fb0acd

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/core/p-crypt.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
444444
if (blk > 0 && len < blk) return 0;
445445

446446
// make space at tail if needed...
447-
ofs = SERIES_TAIL(bin);
448-
Expand_Series(bin, AT_TAIL, len);
449-
// reset the tail (above expand modifies it!)
450-
SERIES_TAIL(bin) = ofs;
447+
Extend_Series(bin, len);
451448

452449
switch (ctx->cipher_type) {
453450

@@ -858,9 +855,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
858855
//puts("update");
859856
#ifdef MBEDTLS_CHACHAPOLY_C
860857
if (ctx->cipher_type == SYM_CHACHA20_POLY1305) {
861-
olen = SERIES_TAIL(bin);
862-
Expand_Series(bin, AT_TAIL, 16);
863-
SERIES_TAIL(bin) = olen; // reset the tail (above expand modifies it!)
858+
Extend_Series(bin, 16);
864859
err = mbedtls_chachapoly_finish((mbedtls_chachapoly_context*)ctx->cipher_ctx, BIN_TAIL(bin));
865860
SERIES_TAIL(bin) += 16;
866861
ctx->state = CRYPT_PORT_NEEDS_AAD;
@@ -870,10 +865,7 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
870865
if (ctx->unprocessed_len > 0) {
871866
ofs = 0;
872867
blk = ctx->cipher_block_size;
873-
olen = SERIES_TAIL(bin);
874-
Expand_Series(bin, AT_TAIL, blk);
875-
// reset the tail (above expand modifies it!)
876-
SERIES_TAIL(bin) = olen;
868+
Extend_Series(bin, blk);
877869

878870
if (ctx->unprocessed_len > blk) abort();
879871
len = blk - ctx->unprocessed_len;

0 commit comments

Comments
 (0)