feat(nan): Add aes_wrap/unwrap crypto callbacks

- Use crypto callbacks instead of calling internal API's
- Clean up of unused code, flags. Re-arrange functions
This commit is contained in:
Nachiket Kukade
2026-06-30 14:56:45 +08:00
committed by Jack
parent 7475e1bced
commit 478be42bd1
7 changed files with 64 additions and 111 deletions
@@ -78,26 +78,28 @@ typedef int (*esp_aes_128_encrypt_t)(const unsigned char *key, const unsigned ch
typedef int (*esp_aes_128_decrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
/**
* @brief The AES wrap callback function used by esp_wifi.
* @brief The AES key wrap (RFC 3394) callback function used by esp_wifi.
*
* @param kek 16-octet Key encryption key (KEK).
* @param kek Key encryption key (KEK).
* @param kek_len Length of the KEK in bytes.
* @param n Length of the plaintext key in 64-bit units;
* @param plain Plaintext key to be wrapped, n * 64 bits
* @param cipher Wrapped key, (n + 1) * 64 bits
*
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_aes_wrap_t)(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher);
typedef int (*esp_aes_wrap_t)(const unsigned char *kek, size_t kek_len, int n, const unsigned char *plain, unsigned char *cipher);
/**
* @brief The AES unwrap callback function used by esp_wifi.
* @brief The AES key unwrap (RFC 3394) callback function used by esp_wifi.
*
* @param kek 16-octet Key decryption key (KEK).
* @param kek Key encryption key (KEK).
* @param kek_len Length of the KEK in bytes.
* @param n Length of the plaintext key in 64-bit units;
* @param cipher Wrapped key to be unwrapped, (n + 1) * 64 bits
* @param plain Plaintext key, n * 64 bits
*
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_aes_unwrap_t)(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain);
typedef int (*esp_aes_unwrap_t)(const unsigned char *kek, size_t kek_len, int n, const unsigned char *cipher, unsigned char *plain);
/**
* @brief The SHA256 callback function used by esp_wifi.
@@ -404,6 +406,8 @@ typedef struct wpa_crypto_funcs_t {
esp_ccmp_encrypt_t ccmp_encrypt; /**< Encrypt data callback function using CCMP */
esp_aes_gmac_t aes_gmac; /**< One-Key GMAC hash callback function with AES for MIC computation */
esp_sha256_vector_t sha256_vector; /**< SHA256 hash callback function for data vector */
esp_aes_wrap_t aes_wrap; /**< The AES key wrap (RFC 3394) callback function used by esp_wifi */
esp_aes_unwrap_t aes_unwrap; /**< The AES key unwrap (RFC 3394) callback function used by esp_wifi */
} wpa_crypto_funcs_t;
/**