Skip to content

Commit

Permalink
Fix ABI break (revert to original behaviour)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Rodgman <[email protected]>
  • Loading branch information
daverodgman committed Oct 16, 2024
1 parent c55b159 commit 9489ce1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions tf-psa-crypto/drivers/builtin/src/chacha20.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ static void chacha20_block(const uint32_t initial_state[16],
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
{
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_chacha20_context));

/* Initially, there's no keystream bytes available */
ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
}

void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
Expand Down Expand Up @@ -418,7 +421,7 @@ int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
}

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

return 0;
}
Expand All @@ -431,11 +434,10 @@ int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
size_t offset = 0U;

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

ctx->keystream_bytes_used = (ctx->keystream_bytes_used + 1) % CHACHA20_BLOCK_SIZE_BYTES;
ctx->keystream_bytes_used++;
offset++;
size--;
}
Expand Down Expand Up @@ -491,7 +493,7 @@ int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,

mbedtls_xor(output + offset, input + offset, ctx->keystream8, size);

ctx->keystream_bytes_remaining = CHACHA20_BLOCK_SIZE_BYTES - size;
ctx->keystream_bytes_used = size;

}
#endif
Expand Down

0 comments on commit 9489ce1

Please sign in to comment.