File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
tf-psa-crypto/drivers/builtin/src Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,9 @@ static void chacha20_block(const uint32_t initial_state[16],
366366void 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
371374void 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 }
You can’t perform that action at this time.
0 commit comments