Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "soc/hwcrypto_reg.h"
36 #include "soc/dport_access.h"
37 #include "esp_private/periph_ctrl.h"
46 #if (ESP32_CRYPTO_CIPHER_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
56 periph_module_enable(PERIPH_AES_MODULE);
78 DPORT_REG_WRITE(AES_KEY_BASE, context->
ek[0]);
79 DPORT_REG_WRITE(AES_KEY_BASE + 4, context->
ek[1]);
80 DPORT_REG_WRITE(AES_KEY_BASE + 8, context->
ek[2]);
81 DPORT_REG_WRITE(AES_KEY_BASE + 12, context->
ek[3]);
83 else if(context->
nr == 12)
89 DPORT_REG_WRITE(AES_KEY_BASE, context->
ek[0]);
90 DPORT_REG_WRITE(AES_KEY_BASE + 4, context->
ek[1]);
91 DPORT_REG_WRITE(AES_KEY_BASE + 8, context->
ek[2]);
92 DPORT_REG_WRITE(AES_KEY_BASE + 12, context->
ek[3]);
93 DPORT_REG_WRITE(AES_KEY_BASE + 16, context->
ek[4]);
94 DPORT_REG_WRITE(AES_KEY_BASE + 20, context->
ek[5]);
102 DPORT_REG_WRITE(AES_KEY_BASE, context->
ek[0]);
103 DPORT_REG_WRITE(AES_KEY_BASE + 4, context->
ek[1]);
104 DPORT_REG_WRITE(AES_KEY_BASE + 8, context->
ek[2]);
105 DPORT_REG_WRITE(AES_KEY_BASE + 12, context->
ek[3]);
106 DPORT_REG_WRITE(AES_KEY_BASE + 16, context->
ek[4]);
107 DPORT_REG_WRITE(AES_KEY_BASE + 20, context->
ek[5]);
108 DPORT_REG_WRITE(AES_KEY_BASE + 24, context->
ek[6]);
109 DPORT_REG_WRITE(AES_KEY_BASE + 28, context->
ek[7]);
125 p = (uint32_t *) input;
126 DPORT_REG_WRITE(AES_TEXT_BASE,
p[0]);
127 DPORT_REG_WRITE(AES_TEXT_BASE + 4,
p[1]);
128 DPORT_REG_WRITE(AES_TEXT_BASE + 8,
p[2]);
129 DPORT_REG_WRITE(AES_TEXT_BASE + 12,
p[3]);
132 DPORT_REG_WRITE(AES_START_REG, 1);
135 while(DPORT_REG_READ(AES_IDLE_REG) == 0)
140 p = (uint32_t *) output;
141 DPORT_INTERRUPT_DISABLE();
142 p[0] = DPORT_SEQUENCE_REG_READ(AES_TEXT_BASE);
143 p[1] = DPORT_SEQUENCE_REG_READ(AES_TEXT_BASE + 4);
144 p[2] = DPORT_SEQUENCE_REG_READ(AES_TEXT_BASE + 8);
145 p[3] = DPORT_SEQUENCE_REG_READ(AES_TEXT_BASE + 12);
146 DPORT_INTERRUPT_RESTORE();
161 if(context == NULL || key == NULL)
170 else if(keyLen == 24)
175 else if(keyLen == 32)
238 #if (ECB_SUPPORT == ENABLED)
251 const uint8_t *
p, uint8_t *
c,
size_t length)
325 const uint8_t *
c, uint8_t *
p,
size_t length)
388 #if (CBC_SUPPORT == ENABLED)
402 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
498 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
587 #if (CFB_SUPPORT == ENABLED)
602 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
638 for(i = 0; i <
n; i++)
665 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
684 for(i = 0; i <
n; i++)
724 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
764 for(i = 0; i <
n; i++)
787 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
810 for(i = 0; i <
n; i++)
833 #if (OFB_SUPPORT == ENABLED)
848 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
884 for(i = 0; i <
n; i++)
911 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
930 for(i = 0; i <
n; i++)
957 #if (CTR_SUPPORT == ENABLED)
972 uint8_t *
t,
const uint8_t *
p, uint8_t *
c,
size_t length)
1009 for(i = 0; i <
n; i++)
1055 for(i = 0; i <
n; i++)
void aesLoadKey(AesContext *context, uint32_t mode)
Load AES key.
CipherAlgoDecryptBlock decryptBlock
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
Collection of AEAD algorithms.
error_t cfbDecrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CFB decryption.
ESP32 cipher hardware accelerator.
#define AES_MODE_128_BITS
ESP32 hardware cryptographic accelerator.
CipherAlgoEncryptBlock encryptBlock
error_t ctrEncrypt(const CipherAlgo *cipher, void *context, uint_t m, uint8_t *t, const uint8_t *p, uint8_t *c, size_t length)
CTR encryption.
#define AES_MODE_256_BITS
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
error_t ofbEncrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
OFB encryption.
void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using AES algorithm.
void aesProcessDataBlock(const uint8_t *input, uint8_t *output)
Encrypt/decrypt a 16-byte block using AES algorithm.
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
@ ERROR_INVALID_KEY_LENGTH
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
General definitions for cryptographic algorithms.
Block cipher modes of operation.
void esp32AesInit(void)
AES module initialization.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
#define AES_ENDIAN_DEFAULT
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Common interface for encryption algorithms.
void ctrIncBlock(uint8_t *ctr, uint32_t inc, size_t blockSize, size_t m)
Increment counter block.
#define AES_MODE_192_BITS
#define osMemmove(dest, src, length)
error_t cfbEncrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CFB encryption.