Skip to main content
davhak
Associate III
October 13, 2016
Question

STM32F4 and crypto question

  • October 13, 2016
  • 13 replies
  • 3849 views
Posted on October 14, 2016 at 00:41

Dear All,

I successfully could integrate the AES GCM algorithms (firmware variant, no hardware acceleration) of STM32 cryptographic library v2.0.6 into the project. It encrypts and decrypts the plaintext correctly without any error.

Simultaneously, there is another crypto project in the PC side using the Crypto++ library with the same AES GCM encrypt/decrypt parts. Here, too, everything works.

However, the problem is that when using the same AES256 key, IV array (size 12), plaintext, header (AAD), the STM32F4 and the PC generates different ciphers and tags. Their lengths are the same across the platforms but the content is totally different.

So it becomes impossible to encrypt in PC and try to decrypt the cipher in STM32F4. I have tried to supply the cipher and the tag generated in STM32F4 to the PC decrypted but it breaks with the error:

Caught HashVerificationFailed...

 

HashVerificationFilter: message hash or MAC not valid

 

So my question what might be the problem that they generate different ciphers?

Thanks a lot for any suggestion.

#!stm32 #help-thyself
This topic has been closed for replies.

13 replies

davhak
davhakAuthor
Associate III
October 19, 2016
Posted on October 19, 2016 at 18:28

Dear Clive,

I am happy to say that after initializing the CRC with:

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);

everything works correctly now.

Thank you so much for your great help!

Tesla DeLorean
Guru
October 19, 2016
Posted on October 19, 2016 at 19:58

The library authenticates itself as running on ST hardware (vs NXP, ATMEL, etc) by checking that it can use the CRC peripheral. It should enable it, but apparently doesn't. The SDIO/CRYPT units depend on a 48 MHz coming from the Q-Tap of the PLL. I've not double checked it for the CRYPT unit, but SDIO doesn't work if the PLL isn't running, ie straight from HSE or HSI

 /* Enable CRC clock */

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
davhak
davhakAuthor
Associate III
October 19, 2016
Posted on October 19, 2016 at 20:39

Dear Clive,

Yes, your hint about the CRC solved the problem.

Thank you very much for the additional information.