HMAC: adding upstream message support

This commit is contained in:
Jakob Hasse
2020-02-07 13:08:34 +01:00
parent b56993cc3f
commit ea47bbb118
9 changed files with 1165 additions and 72 deletions
+3 -10
View File
@@ -37,7 +37,6 @@
#include "soc/hwcrypto_reg.h"
#include "soc/crypto_dma_reg.h"
#include "soc/periph_defs.h"
#include "esp32s2/crypto_dma.h"
#include "esp32s2/rom/lldesc.h"
#include "esp32s2/rom/cache.h"
#include "esp_intr_alloc.h"
@@ -47,6 +46,7 @@
#include "esp_heap_caps.h"
#include "sys/param.h"
#include "esp_pm.h"
#include "esp_crypto_lock.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
@@ -89,11 +89,6 @@ static esp_pm_lock_handle_t s_pm_sleep_lock;
#endif
#endif
_lock_t crypto_dma_lock;
static _lock_t s_aes_lock;
static const char *TAG = "esp-aes";
static inline bool valid_key_length(const esp_aes_context *ctx)
@@ -105,8 +100,7 @@ static inline bool valid_key_length(const esp_aes_context *ctx)
void esp_aes_acquire_hardware( void )
{
/* Need to lock DMA since it is shared with SHA block */
_lock_acquire(&s_aes_lock);
_lock_acquire(&crypto_dma_lock);
esp_crypto_lock_acquire();
/* Enable AES hardware */
periph_module_enable(PERIPH_AES_DMA_MODULE);
@@ -118,8 +112,7 @@ void esp_aes_release_hardware( void )
/* Disable AES hardware */
periph_module_disable(PERIPH_AES_DMA_MODULE);
_lock_release(&crypto_dma_lock);
_lock_release(&s_aes_lock);
esp_crypto_lock_release();
}
+8 -20
View File
@@ -30,25 +30,23 @@
#include <sys/lock.h>
#include "esp_log.h"
#include "esp_crypto_lock.h"
#include "esp32s2/rom/cache.h"
#include "esp32s2/rom/lldesc.h"
#include "esp32s2/rom/ets_sys.h"
#include "soc/crypto_dma_reg.h"
#include "soc/dport_reg.h"
#include "soc/hwcrypto_reg.h"
#include "esp32s2/rom/cache.h"
#include "soc/cache_memory.h"
#include "soc/periph_defs.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp32s2/sha.h"
#include "esp32s2/crypto_dma.h"
#include "esp32s2/rom/lldesc.h"
#include "soc/periph_defs.h"
#include "soc/crypto_dma_reg.h"
#include "driver/periph_ctrl.h"
#include "sys/param.h"
#include "esp32s2/sha.h"
/* Max amount of bytes in a single DMA operation is 4095,
for SHA this means that the biggest safe amount of bytes is
@@ -56,9 +54,6 @@
*/
#define SHA_DMA_MAX_BYTES 3968
/* Lock for SHA engine */
static _lock_t s_sha_lock;
const static char *TAG = "esp-sha";
/* Return block size (in bytes) for a given SHA type */
@@ -103,9 +98,7 @@ inline static size_t state_length(esp_sha_type type)
/* Enable SHA peripheral and then lock it */
void esp_sha_acquire_hardware()
{
/* Need to lock DMA since it is shared with AES block */
_lock_acquire(&crypto_dma_lock);
_lock_acquire(&s_sha_lock);
esp_crypto_lock_acquire();
/* Enable SHA and DMA hardware */
periph_module_enable(PERIPH_SHA_DMA_MODULE);
@@ -120,13 +113,9 @@ void esp_sha_release_hardware()
/* Disable SHA and DMA hardware */
periph_module_disable(PERIPH_SHA_DMA_MODULE);
/* Need to lock DMA since it is shared with AES block */
_lock_release(&s_sha_lock);
_lock_release(&crypto_dma_lock);
esp_crypto_lock_release();
}
/* Busy wait until SHA is idle */
static void esp_sha_wait_idle(void)
{
@@ -134,7 +123,6 @@ static void esp_sha_wait_idle(void)
}
}
void esp_sha_write_digest_state(esp_sha_type sha_type, void *digest_state)
{
uint32_t *digest_state_words = (uint32_t *)digest_state;