0
\$\begingroup\$

I am trying to implement very basic AES192-CBC Mode encryption routine on STM32F407 Discovery board and I want to do that process with the onboard Cryptographic processor in STM32F407 MCU. I copied most of my code parts from ST's exampe projects. Here is my code:

#define AES_TEXT_SIZE    64                                                             

uint8_t AES192key[24] = 
              {0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
               0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
               0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b};                                // key size 192 bits

uint8_t IV_1[16] = 
              {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
               0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};                                // initialization vector                                                    

uint8_t AES_TEXT[AES_TEXT_SIZE] = 
                        {0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                         0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41}; 

uint8_t Encryptedtext[AES_TEXT_SIZE];                                                   // Encrypted text
uint8_t Decryptedtext[AES_TEXT_SIZE];                                                   // Decrypted text                                                                    

/**
  * @brief  Program entry funtion
  * @param  none    
  * @retval none
  */
int main()
{
    SystemInit();                                                                       // System initializing
    USART2_Init();                                                                      // USART2 initializing

    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_CRYP, ENABLE);                                // onboard cryp hardware clock enable

    /* program main infinite loop */
    while(1)
    {
        /* send original text first */ 
        USART_Puts(USART2, "Original Text:\n");
        USART_Puts(USART2, (char*)AES_TEXT);
        USART_Puts(USART2, "\n");

        /* if encryption process successed send encryptedtext otherwise send "Fail" */
        if(CRYP_AES_CBC(MODE_ENCRYPT, IV_1, AES192key, 192, AES_TEXT, AES_TEXT_SIZE, Encryptedtext) == SUCCESS)
        {
            USART_Puts(USART2, "Encrypted Text:\n");
            USART_Puts(USART2, (char*)Encryptedtext);
            USART_Puts(USART2, "\n");
        }
        else
        {
            USART_Puts(USART2, "Fail\n");
        }

        Simple_Delay_MS(1000);                                                          // ~1 sec delay

    }   
}

Its not working properly and thats why I debugged my code and noticed that the problem location is:

  /* Enable Crypto processor */
  CRYP_Cmd(ENABLE);

  if(CRYP_GetCmdStatus() == DISABLE)
  {
    /* The CRYP peripheral clock is not enabled or the device doesn't embedd 
       the CRYP peripheral (please check the device sales type. */
    return(ERROR);
  } 

This is the part of encryption processor driver code from ST's original drivers. In that case my Cryptographic Processor has not been started properly.

Is that problem caused by the my device's sales type (like it said in driver code) or is there anything wrong with my code routine?

\$\endgroup\$
2
\$\begingroup\$

The STM32f407 as used on the disco board doesn't have the crypto hardware, the STM32f417 is the pin and code compatible part with cryptographic hardware.

This Page provides details, see bullet point #8

The STM32F417 also integrates a crypto/hash processor providing hardware acceleration for AES 128, 192, 256, Triple DES, and hash (MD5, SHA-1)

\$\endgroup\$
  • \$\begingroup\$ After I read your post, I checked the reference manual of STM32F407 and noticed that there is no cryptographic hardware in my MCU. Thank you! \$\endgroup\$ – Batu92k Nov 29 '17 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.