Skip to content

Commit 4c973cf

Browse files
Simplify context reuse protection in mbedtls_sha3_starts
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent 2e0cbd8 commit 4c973cf

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/builtin/src/sha3.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ void mbedtls_sha3_clone(mbedtls_sha3_context *dst,
270270
*/
271271
int mbedtls_sha3_starts(mbedtls_sha3_context *ctx, mbedtls_sha3_id id)
272272
{
273+
/* Clean up in case the context is being reused */
274+
memset(ctx, 0, sizeof(*ctx));
275+
273276
switch (id) {
274277
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_224)
275278
case MBEDTLS_SHA3_224:
@@ -315,10 +318,6 @@ int mbedtls_sha3_starts(mbedtls_sha3_context *ctx, mbedtls_sha3_id id)
315318
return MBEDTLS_ERR_SHA3_BAD_INPUT_DATA;
316319
}
317320

318-
memset(ctx->state, 0, sizeof(ctx->state));
319-
ctx->index = 0;
320-
ctx->finished = 0;
321-
322321
return 0;
323322
}
324323

0 commit comments

Comments
 (0)