Topic: AesCbcDecrypt hardfaulting on STmicro

I am trying to get Aes to work and I am having an issue with it hard faulting.

I call this to generate the key

ret = wc_RNG_GenerateBlock(&sysRNG,iv,AESSIZE);
ret=wc_AesSetKey(&denc,aesKey,AESSIZE,iv,AES_DECRYPTION);

And then call this to decrypt each packet as it comes in.

wc_AesCbcDecrypt(&denc,block,cipher,*size);

and this is my settings.h file
#ifdef WOLFSSL_STM32F2
    #define SIZEOF_LONG_LONG 8
    #define NO_DEV_RANDOM
    #define NO_WOLFSSL_DIR
    #define NO_RABBIT
    #define STM32F2_RNG
    #define STM32F2_CRYPTO
    #define KEIL_INTRINSICS
    #define NO_WRITEV
    #define NO_FILESYSTEM
    #define NO_DES3
    #undef  NO_AES
    #define SINGLE_THREADED
    #define WOLFSSL_KEY_GEN
    #define RSA_DECODE_EXTRA
#endif

Any ideas I am using an STM32F4 but the crypto block is supposed to be compatible

Share

Re: AesCbcDecrypt hardfaulting on STmicro

Hi lwatcdr,

There is a couple things to check with the code. The first thing to check for the issue with hard faulting is that "size" is a pointer since being dereferenced and to check "size" is not NULL.

wc_AesCbcDecrypt(&denc,block,cipher,*size);

The next thing to check is that the return value of wc_AesSetKey is equal to 0. If it is not then there is a case where denc has not been set.

The final thing with the hard fault is to make sure that AESSIZE is equal to AES_BLOCK_SIZE from wolfSSL.

Not related to a hard fault but still important is that the iv should be the same as what was used for encryption. Creating a new random iv for the decryption will result in not being able to properly decrypt the information.

An example of using AES can be found at https://github.com/wolfSSL/wolfssl-exam … crypto/aes though it has a little bit more since using the function wc_PBKDF2 to stretch out the key if needed, it allows for seeing the flow of a standard AES encrypt -> decrypt.

Regards,
Jacob

Share