]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wolfSSL: Improve error checking and logging in AES functions
authorJuliusz Sosinowicz <juliusz@wolfssl.com>
Wed, 8 Mar 2023 17:18:47 +0000 (18:18 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 4 Nov 2023 16:18:25 +0000 (18:18 +0200)
Signed-off-by: Juliusz Sosinowicz <juliusz@wolfssl.com>
src/crypto/crypto_wolfssl.c

index e84e02a421155230d72939292a808525717c05d5..6b49bb3a77d5da7b7bfbc986f82561b2167ef9eb 100644 (file)
@@ -456,15 +456,20 @@ int des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
 void * aes_encrypt_init(const u8 *key, size_t len)
 {
        Aes *aes;
+       int err;
 
        if (TEST_FAIL())
                return NULL;
 
        aes = os_malloc(sizeof(Aes));
-       if (!aes)
+       if (!aes) {
+               LOG_WOLF_ERROR_FUNC_NULL(os_malloc);
                return NULL;
+       }
 
-       if (wc_AesSetKey(aes, key, len, NULL, AES_ENCRYPTION) < 0) {
+       err = wc_AesSetKey(aes, key, len, NULL, AES_ENCRYPTION);
+       if (err < 0) {
+               LOG_WOLF_ERROR_FUNC(wc_AesSetKey, err);
                os_free(aes);
                return NULL;
        }
@@ -475,7 +480,12 @@ void * aes_encrypt_init(const u8 *key, size_t len)
 
 int aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
 {
-       wc_AesEncryptDirect(ctx, crypt, plain);
+       int err = wc_AesEncryptDirect(ctx, crypt, plain);
+
+       if (err != 0) {
+               LOG_WOLF_ERROR_FUNC(wc_AesEncryptDirect, err);
+               return -1;
+       }
        return 0;
 }
 
@@ -489,15 +499,20 @@ void aes_encrypt_deinit(void *ctx)
 void * aes_decrypt_init(const u8 *key, size_t len)
 {
        Aes *aes;
+       int err;
 
        if (TEST_FAIL())
                return NULL;
 
        aes = os_malloc(sizeof(Aes));
-       if (!aes)
+       if (!aes) {
+               LOG_WOLF_ERROR_FUNC_NULL(os_malloc);
                return NULL;
+       }
 
-       if (wc_AesSetKey(aes, key, len, NULL, AES_DECRYPTION) < 0) {
+       err = wc_AesSetKey(aes, key, len, NULL, AES_DECRYPTION);
+       if (err < 0) {
+               LOG_WOLF_ERROR_FUNC(wc_AesSetKey, err);
                os_free(aes);
                return NULL;
        }
@@ -508,7 +523,12 @@ void * aes_decrypt_init(const u8 *key, size_t len)
 
 int aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
 {
-       wc_AesDecryptDirect(ctx, plain, crypt);
+       int err = wc_AesDecryptDirect(ctx, plain, crypt);
+
+       if (err != 0) {
+               LOG_WOLF_ERROR_FUNC(wc_AesDecryptDirect, err);
+               return -1;
+       }
        return 0;
 }