Skip to content

Commit c55b159

Browse files
committed
Fix ABI break
Signed-off-by: Dave Rodgman <[email protected]>
1 parent cd36f25 commit c55b159

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

tf-psa-crypto/drivers/builtin/include/mbedtls/chacha20.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ extern "C" {
3434
#endif
3535

3636
typedef struct mbedtls_chacha20_context {
37-
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
38-
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
39-
size_t MBEDTLS_PRIVATE(keystream_bytes_remaining); /*! Number of not-used keystream bytes */
37+
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
38+
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
39+
size_t MBEDTLS_PRIVATE(keystream_bytes_used); /*! Number of keystream bytes already used. */
4040
}
4141
mbedtls_chacha20_context;
4242

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
418418
}
419419

420420
/* Initially, there's no keystream bytes available */
421-
ctx->keystream_bytes_remaining = 0U;
421+
ctx->keystream_bytes_used = 0U;
422422

423423
return 0;
424424
}
@@ -431,12 +431,11 @@ int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
431431
size_t offset = 0U;
432432

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

439-
ctx->keystream_bytes_remaining--;
438+
ctx->keystream_bytes_used = (ctx->keystream_bytes_used + 1) % CHACHA20_BLOCK_SIZE_BYTES;
440439
offset++;
441440
size--;
442441
}
@@ -466,7 +465,7 @@ int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
466465

467466
mbedtls_xor_no_simd(output + offset, input + offset, ctx->keystream8, size);
468467

469-
ctx->keystream_bytes_remaining = CHACHA20_BLOCK_SIZE_BYTES - size;
468+
ctx->keystream_bytes_used = size;
470469
}
471470

472471
/* Capture state */

0 commit comments

Comments
 (0)