Skip to content

Commit c8e641e

Browse files
committed
Fix ABI break (revert to original behaviour)
Signed-off-by: Dave Rodgman <[email protected]>
1 parent c55b159 commit c8e641e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tf-psa-crypto/drivers/builtin/src/chacha20.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ static void chacha20_block(const uint32_t initial_state[16],
366366
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
367367
{
368368
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_chacha20_context));
369+
370+
/* Initially, there's no keystream bytes available */
371+
ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
369372
}
370373

371374
void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
@@ -418,7 +421,7 @@ int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
418421
}
419422

420423
/* Initially, there's no keystream bytes available */
421-
ctx->keystream_bytes_used = 0U;
424+
ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
422425

423426
return 0;
424427
}
@@ -431,11 +434,10 @@ int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
431434
size_t offset = 0U;
432435

433436
/* Use leftover keystream bytes, if available */
434-
while (size > 0U && ctx->keystream_bytes_used > 0U &&
435-
ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES) {
437+
while (size > 0U && ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES) {
436438
output[offset] = input[offset] ^ ctx->keystream8[ctx->keystream_bytes_used];
437439

438-
ctx->keystream_bytes_used = (ctx->keystream_bytes_used + 1) % CHACHA20_BLOCK_SIZE_BYTES;
440+
ctx->keystream_bytes_used++;
439441
offset++;
440442
size--;
441443
}

0 commit comments

Comments
 (0)