Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release the lock in mbedtls_sha256_free if it was not released already #2105

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rp2_common/pico_mbedtls/pico_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void mbedtls_sha256_init(__unused mbedtls_sha256_context *ctx) {
}

void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) {
pico_sha256_cleanup(ctx);
}

int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) {
Expand Down
10 changes: 10 additions & 0 deletions src/rp2_common/pico_sha256/include/pico/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ typedef struct pico_sha256_state {
size_t total_data_size;
} pico_sha256_state_t;

/*! \brief Release the internal lock on the SHA-256 hardware
* \ingroup pico_sha256
*
* Release the internal lock on the SHA-256 hardware.
* Fails if the internal lock was not claimed.
*
* @param state A pointer to a pico_sha256_state_t instance
*/
void pico_sha256_cleanup(pico_sha256_state_t *state);

/*! \brief Start a SHA-256 calculation returning immediately with an error if the SHA-256 hardware is not available
* \ingroup pico_sha256
*
Expand Down
6 changes: 6 additions & 0 deletions src/rp2_common/pico_sha256/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ void __weak pico_sha256_unlock(pico_sha256_state_t *state) {
state->locked = false;
}

void pico_sha256_cleanup(pico_sha256_state_t *state) {
if (state->locked) {
pico_sha256_unlock(state);
}
}

int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) {
memset(state, 0, sizeof(*state));
if (!pico_sha256_lock(state)) return PICO_ERROR_RESOURCE_IN_USE;
Expand Down