Skip to content

Commit

Permalink
Run init/free to the backup context for GetDigest. (#19233)
Browse files Browse the repository at this point in the history
CYW30739 platform specific SHA256 implementations need
mbedtls_sha256_init/mbedtls_sha256_free functions called to do
initialization and cleanup.
  • Loading branch information
hsusid authored and pull[bot] committed Jan 29, 2024
1 parent be837b6 commit 1438940
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/crypto/CHIPCryptoPALmbedTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,15 @@ CHIP_ERROR Hash_SHA256_stream::GetDigest(MutableByteSpan & out_buffer)

// Back-up context as we are about to finalize the hash to extract digest.
mbedtls_sha256_context previous_ctx;
mbedtls_sha256_init(&previous_ctx);
mbedtls_sha256_clone(&previous_ctx, context);

// Pad + compute digest, then finalize context. It is restored next line to continue.
CHIP_ERROR result = Finish(out_buffer);

// Restore context prior to finalization.
mbedtls_sha256_clone(context, &previous_ctx);
mbedtls_sha256_free(&previous_ctx);

return result;
}
Expand Down

0 comments on commit 1438940

Please sign in to comment.