cancel
Showing results for 
Search instead for 
Did you mean: 

AES CMAC encryption returning bad_context error

tyler_nehowig
Associate
Posted on February 10, 2014 at 17:32

Hello,

I'm currently implementing AES CMAC crypto using the STM32 crypto library from ST and I'm unable to get the example code to work without returning an error.  I'm using an STM32F103.

The example encrypt routine in aes_cmac.h is always returning 3103 (bad_context) as the error_status during the AES_CMAC_Encrypt_Finish() function.

I can't figure out why it keeps generating this error, I've read through the user guide for the STM32 crypto library and nothing jumps out at me as to why it doesn't like the context.

Any help would be GREATLY appreciated.

Regards,

Tyler Nehowig

#stm32f103 #stm32-crypto-lib #aes
1 REPLY 1
susella.ruggero
Associate
Posted on March 14, 2014 at 16:08

Hi,

CMAC is bit trickier than other algorithms.

Before processing the last part of the message with the AES_CMAC_Encrypt_Append you should set the E_SK_FINAL_APPEND flag in your context's flags.

If you've done that and you get the error then the most probably cause is that you didn't set a value for mTagSize in your context. Set it between 1 and 16 and it should work.

Best Regards Regards,

Ruggero