Skip to content

Commit 6c06f90

Browse files
nilswiersmanilspeterharperuk
authored
Release the lock in mbedtls_sha256_free if it was not released already (#2105)
* Release the lock in mbedtls_sha256_free if it was not released already. Requires making pico_sha256_unlock include-able. Fixes #2103. * addres lock release API comment * Fix description of pico_sha256_cleanup --------- Co-authored-by: nils <nils@nils> Co-authored-by: Peter Harper <[email protected]>
1 parent 3d746b3 commit 6c06f90

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/rp2_common/pico_mbedtls/pico_mbedtls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void mbedtls_sha256_init(__unused mbedtls_sha256_context *ctx) {
3636
}
3737

3838
void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) {
39+
pico_sha256_cleanup(ctx);
3940
}
4041

4142
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) {

src/rp2_common/pico_sha256/include/pico/sha256.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ typedef struct pico_sha256_state {
5858
size_t total_data_size;
5959
} pico_sha256_state_t;
6060

61+
/*! \brief Release the internal lock on the SHA-256 hardware
62+
* \ingroup pico_sha256
63+
*
64+
* Release the internal lock on the SHA-256 hardware.
65+
* Does nothing if the internal lock was not claimed.
66+
*
67+
* @param state A pointer to a pico_sha256_state_t instance
68+
*/
69+
void pico_sha256_cleanup(pico_sha256_state_t *state);
70+
6171
/*! \brief Start a SHA-256 calculation returning immediately with an error if the SHA-256 hardware is not available
6272
* \ingroup pico_sha256
6373
*

src/rp2_common/pico_sha256/sha256.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ void __weak pico_sha256_unlock(pico_sha256_state_t *state) {
3030
state->locked = false;
3131
}
3232

33+
void pico_sha256_cleanup(pico_sha256_state_t *state) {
34+
if (state->locked) {
35+
pico_sha256_unlock(state);
36+
}
37+
}
38+
3339
int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) {
3440
memset(state, 0, sizeof(*state));
3541
if (!pico_sha256_lock(state)) return PICO_ERROR_RESOURCE_IN_USE;

0 commit comments

Comments
 (0)