diff --git a/components/wpa_supplicant/src/crypto/aes-cbc.c b/components/wpa_supplicant/src/crypto/aes-cbc.c index d0e4c822..91b0192f 100644 --- a/components/wpa_supplicant/src/crypto/aes-cbc.c +++ b/components/wpa_supplicant/src/crypto/aes-cbc.c @@ -91,4 +91,51 @@ aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len) return 0; } +#else /* CONFIG_ESP_AES */ + +#include +#include "esp_aes.h" + +#ifndef AES_BLOCK_SIZE +#define AES_BLOCK_SIZE 16 +#endif + +int aes_128_cbc_encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len) +{ + int ret; + esp_aes_t ctx; + uint8_t iv_tmp[AES_BLOCK_SIZE]; + + ret = esp_aes_set_encrypt_key(&ctx, key, 128); + if (ret) + return ret; + + memcpy(iv_tmp, iv, AES_BLOCK_SIZE); + + ret = esp_aes_encrypt_cbc(&ctx, data, data_len, data, data_len, iv_tmp); + if (ret) + return ret; + + return 0; +} + +int aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len) +{ + int ret; + esp_aes_t ctx; + uint8_t iv_tmp[AES_BLOCK_SIZE]; + + ret = esp_aes_set_decrypt_key(&ctx, key, 128); + if (ret) + return ret; + + memcpy(iv_tmp, iv, AES_BLOCK_SIZE); + + ret = esp_aes_decrypt_cbc(&ctx, data, data_len, data, data_len, iv_tmp); + if (ret) + return ret; + + return 0; +} + #endif /* CONFIG_ESP_AES */