]> granicus.if.org Git - esp-idf/commitdiff
mbedTLS SHA Acceleration: Add missing esp_sha_lock_engine() function
authorAngus Gratton <angus@espressif.com>
Tue, 22 Nov 2016 09:56:36 +0000 (20:56 +1100)
committerAngus Gratton <angus@espressif.com>
Tue, 22 Nov 2016 09:57:01 +0000 (20:57 +1100)
components/esp32/hwcrypto/sha.c
components/esp32/include/hwcrypto/sha.h

index fd8075fc72250f8b950df52fdb4e3cfc7b6d6b3c..601981e2a192b06d4a1d173746bde04933d48283 100644 (file)
@@ -133,14 +133,29 @@ inline static bool sha_engines_all_idle() {
         && !engine_states[2].in_use;
 }
 
+static void esp_sha_lock_engine_inner(sha_engine_state *engine);
+
 bool esp_sha_try_lock_engine(esp_sha_type sha_type)
 {
     sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
     if(_lock_try_acquire(&engine->lock) != 0) {
         /* This SHA engine is already in use */
         return false;
+    } else {
+        esp_sha_lock_engine_inner(engine);
+        return true;
     }
+}
+
+void esp_sha_lock_engine(esp_sha_type sha_type)
+{
+    sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
+    _lock_acquire(&engine->lock);
+    esp_sha_lock_engine_inner(engine);
+}
 
+static void esp_sha_lock_engine_inner(sha_engine_state *engine)
+{
     _lock_acquire(&state_change_lock);
 
     if (sha_engines_all_idle()) {
@@ -157,10 +172,9 @@ bool esp_sha_try_lock_engine(esp_sha_type sha_type)
 
     assert( !engine->in_use && "in_use flag should be cleared" );
     engine->in_use = true;
-
-    return true;
 }
 
+
 void esp_sha_unlock_engine(esp_sha_type sha_type)
 {
     sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
@@ -253,7 +267,7 @@ void esp_sha(esp_sha_type sha_type, const unsigned char *input, size_t ilen, uns
 {
     size_t block_len = block_length(sha_type);
 
-    esp_sha_try_lock_engine(sha_type);
+    esp_sha_lock_engine(sha_type);
 
     SHA_CTX ctx;
     ets_sha_init(&ctx);
index 3162b133176845d94124cf549f71d95cba450a77..2a0ec78abee3f4e86e35a28ec719a93edd8bfa67 100644 (file)
@@ -131,7 +131,7 @@ void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state);
  * while a TLS connection is open, suggest using
  * esp_sha_try_lock_engine() and failing over to software SHA.
  */
-bool esp_sha_lock_engine(esp_sha_type sha_type);
+void esp_sha_lock_engine(esp_sha_type sha_type);
 
 /**
  * @brief Try and obtain exclusive access to a particular SHA engine