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 Aug 9, 2023
1 parent d2f8cb1 commit 1fa913e
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 1fa913e

Please sign in to comment.