mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
hwcrypto sha: Allow SHA contexts to be shared between tasks
Previously, hardware SHA engine "locks" were mutex semaphores. This meant that the task which started a particular SHA session (in hardware) needed to finalise that session, or an invalid FreeRTOS state was created. Replace with binary semaphore which can be shared between tasks. Includes a unit test, but unit test doesn't crash even without this fix (some other unknown condition is required).
This commit is contained in:
@@ -255,3 +255,47 @@ TEST_CASE("mbedtls SHA256 clone", "[mbedtls]")
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_finish_ret(&clone, sha256));
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_thousand_as, sha256, 32, "SHA256 cloned calculation");
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
mbedtls_sha256_context ctx;
|
||||
uint8_t result[32];
|
||||
int ret;
|
||||
bool done;
|
||||
} finalise_sha_param_t;
|
||||
|
||||
static void tskFinaliseSha(void *v_param)
|
||||
{
|
||||
finalise_sha_param_t *param = (finalise_sha_param_t *)v_param;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_update_ret(¶m->ctx, one_hundred_as, 100));
|
||||
}
|
||||
|
||||
param->ret = mbedtls_sha256_finish_ret(¶m->ctx, param->result);
|
||||
param->done = true;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
TEST_CASE("mbedtls SHA session passed between tasks" , "[mbedtls]")
|
||||
{
|
||||
finalise_sha_param_t param = { 0 };
|
||||
|
||||
mbedtls_sha256_init(¶m.ctx);
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_starts_ret(¶m.ctx, false));
|
||||
for (int i = 0; i < 5; i++) {
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_update_ret(¶m.ctx, one_hundred_as, 100));
|
||||
}
|
||||
|
||||
// pass the SHA context off to a different task
|
||||
//
|
||||
// note: at the moment this doesn't crash even if a mutex semaphore is used as the
|
||||
// engine lock, but it can crash...
|
||||
xTaskCreate(tskFinaliseSha, "SHAFinalise", SHA_TASK_STACK_SIZE, ¶m, 3, NULL);
|
||||
|
||||
while (!param.done) {
|
||||
vTaskDelay(1);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, param.ret);
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_thousand_as, param.result, 32, "SHA256 result from other task");
|
||||
}
|
||||
|
Reference in New Issue
Block a user