STM32 - Cryptographic lib

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

STM32 - Cryptographic lib

Post by Noname »

Hello

It's not directly related to ChibiOS so, I'll try to ask my question in this section of the forum, before switching to the st forum maybe.

Has someone successfully implemented the crypto library for the STM32 of ST? :(

I have added those lines in the ChibiOS makefile:

Code: Select all

INCDIR =...
        ./STM32_Cryptographic_Library/inc   \
        ./STM32F4xx_StdPeriph_Driver/inc     

and

Code: Select all

# List all user libraries here
ULIBS = Lib/M4_CryptoFW_2_0_6.a


But I'm getting those errors when I compile:
undefined reference to `__aeabi_memcpy'
undefined reference to `__aeabi_memclr4'
...
...


That M4_CryptoFW_2_0_6.a lib file was originally located in a folder name "Binary/EWARM", so I assume it was compiled with IAR compiler. There is also a M4_CryptoFW_2_0_6.lib in the folder "Binary/MK-ARM", it probably was compiled with the Keil compiler.

If a use le .lib file instead of the .a file I'm getting different errors too.
build/ch.elf: hidden symbol `__aeabi_memcpy' isn't defined



Are those lib binary files not compatible with the gnu arm compiler (ChibiStudio)?

:(

Thanks
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 - Cryptographic lib

Post by Giovanni »

Hi,

Doesn't ST provide a library for GCC? if not then you should add the source code directly, assuming it is available.

Giovanni
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

Re: STM32 - Cryptographic lib

Post by Noname »

Giovanni wrote:Hi,
Doesn't ST provide a library for GCC?

No :(

Giovanni wrote:if not then you should add the source code directly, assuming it is available.

In the STM32_Cryptographic_Library folder, there are only the lib binaries and header files/prototype functions called in the main.c sample code.

But in the STM32F4xx_StdPeriph_Driver there are 3 .c files (stm32f4xx_cryp.c, stm32f4xx_cryp_aes.c, stm32f4xx_cryp_des.c) related to the encryption fonctionality, but I'm not sure that is the sources of the crypto lib since they don't implement the declared prototypes that I mentioned before, and the demo code in the main.c don't use at all those functions also.
* @file stm32f4xx_cryp.c

* @brief This file provides firmware functions to manage the following
* functionalities of the Cryptographic processor (CRYP) peripheral:
* + Initialization and Configuration functions
* + Data treatment functions
* + Context swapping functions
* + DMA interface function
* + Interrupts and flags management

* @file stm32f4xx_cryp_aes.c

* @brief This file provides high level functions to encrypt and decrypt an
* input message using AES in ECB/CBC/CTR/GCM/CCM modes.
* It uses the stm32f4xx_cryp.c/.h drivers to access the STM32F4xx CRYP
* peripheral.
* AES-ECB/CBC/CTR/GCM/CCM modes are available on STM32F437x Devices.
* For STM32F41xx Devices, only AES-ECB/CBC/CTR modes are available.


Strange :?

To summarize:
There are binary files and header files with the prototypes functions of the crypto lib.
And there are source files that don't match at all with the prototypes of the crypto lib.

And demo code in main.c that uses only the fonctions of the crypto lib (prototype functions).


I'm lost :D

I will take a look in the manual.


Well, my attempt to get into microcontroller programming as an hobbyist becomes more painful as initially thought :D

EDIT:
STM32F4xx_StdPeriph_Driver folder = HAL
STM32_Cryptographic_Library (binaries) = middleware (a layer above of the HAL).

So, no source files of the crypto lib :-/
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 - Cryptographic lib

Post by Giovanni »

Probably you should ask for the GCC library on the ST forum.

I know the persons who made that library but I don't know when I will have a chance to talk with them again and probably it is not up to them to decide if to release a GCC version or not.

Something you could try is to provide the unresolved functions, those look pretty standard.

Giovanni
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

Re: STM32 - Cryptographic lib

Post by Noname »

Right :-)

https://my.st.com/public/STe2ecommuniti ... ntviews=26

It compiles, but now I have another issue. Well at my level it doesn't surpise me :D :D :D
C:\SVN\MCD_STM32_Cryptographic_V2_0_6\LibraryCreation\Cortex_M4_FW\Crypto_Sources_Files\crypto.c:(.text+0x11250): undefined reference to `RCC_AHBPeriphClockCmd'


Strange because in the stm32f4xx_rcc.c (STM32F4xx_StdPeriph_Driver) there is a
RCC_AHB1PeriphClockCmd
and a
RCC_AHB2PeriphClockCmd,
but no
RCC_AHBPeriphClockCmd function.


The second seems to be the right one because it's written in the function descritpion that it can enable the crypt peripheral:
/**
* @brief Enables or disables the AHB2 peripheral clock.
* @note After reset, the peripheral clock (used for registers read/write access)
* is disabled and the application software has to enable this clock before
* using it.
* @param RCC_AHBPeriph: specifies the AHB2 peripheral to gates its clock.
* This parameter can be any combination of the following values:
* @arg RCC_AHB2Periph_DCMI: DCMI clock
* @arg RCC_AHB2Periph_CRYP: CRYP clock
* @arg RCC_AHB2Periph_HASH: HASH clock
* @arg RCC_AHB2Periph_RNG: RNG clock
* @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
* @param NewState: new state of the specified peripheral clock.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/


But if I rename RCC_AHB2PeriphClockCmd, into RCC_AHBPeriphClockCmd, I get that error :D
/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c:1165: undefined reference to `assert_param'


Code: Select all

void RCC_AHBPeriphClockCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    RCC->AHB2ENR |= RCC_AHB2Periph;
  }
  else
  {
    RCC->AHB2ENR &= ~RCC_AHB2Periph;
  }
}




EDIT:
Well I have put those 2 lines in comment, now it compiles. Let's see if the demo does what it is intended to :-)
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

Re: STM32 - Cryptographic lib

Post by Noname »

Well the encryption fails.

It doesn't surprise me:D.

I think the encryption peripheral (peripheral ??? I thought that only 2 versions of the STM32F4 had an hardware encryption engine, on the others ons the encryption engine ran over software) has to be initialized by ChibiOS it self.

rccEnableAHB2(...)
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

Re: STM32 - Cryptographic lib

Post by Noname »

Everythings works now.

I was using the wrong binary, M4_CryptoFW_2_0_6 instead of M4_CryptoFW_RngHW_2_0_6.

And secondly I had to use the stm32f4xx_rcc.h header included in the lib and not that one included in ChibiOS (stm32_rcc.h).
HyperText
Posts: 2
Joined: Sun Jun 01, 2014 7:59 pm

Re: STM32 - Cryptographic lib

Post by HyperText »

Hi,

I'm trying to compile my project, but I can't figure it out.
I'm including the library file (M4_CryptoFW_RngHW_2_0_6.a) via Eclipse, but it says:
Building target: CryptoFirmware.elf
Invoking: Cross ARM C Linker
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g3 -T libs.ld -T mem.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -L../libs -Wl,-Map,"CryptoFirmware.map" -o "CryptoFirmware.elf" ./src/abi.o ./src/main.o ./libs/misc/src/_sbrk.o ./libs/misc/src/_write.o ./libs/misc/src/trace_impl.o ./libs/cmsis/src/startup_cm.o ./libs/cmsis/src/startup_stm32f4xx.o ./libs/cmsis/src/system_stm32f4xx.o ./libs/cmsis/src/vectors_stm32f4xx.o ./libs/StdPeriph/src/misc.o ./libs/StdPeriph/src/stm32f4xx_adc.o ./libs/StdPeriph/src/stm32f4xx_can.o ./libs/StdPeriph/src/stm32f4xx_crc.o ./libs/StdPeriph/src/stm32f4xx_cryp.o ./libs/StdPeriph/src/stm32f4xx_cryp_aes.o ./libs/StdPeriph/src/stm32f4xx_cryp_des.o ./libs/StdPeriph/src/stm32f4xx_cryp_tdes.o ./libs/StdPeriph/src/stm32f4xx_dac.o ./libs/StdPeriph/src/stm32f4xx_dbgmcu.o ./libs/StdPeriph/src/stm32f4xx_dcmi.o ./libs/StdPeriph/src/stm32f4xx_dma.o ./libs/StdPeriph/src/stm32f4xx_dma2d.o ./libs/StdPeriph/src/stm32f4xx_exti.o ./libs/StdPeriph/src/stm32f4xx_flash.o ./libs/StdPeriph/src/stm32f4xx_fmc.o ./libs/StdPeriph/src/stm32f4xx_fsmc.o ./libs/StdPeriph/src/stm32f4xx_gpio.o ./libs/StdPeriph/src/stm32f4xx_hash.o ./libs/StdPeriph/src/stm32f4xx_hash_md5.o ./libs/StdPeriph/src/stm32f4xx_hash_sha1.o ./libs/StdPeriph/src/stm32f4xx_i2c.o ./libs/StdPeriph/src/stm32f4xx_iwdg.o ./libs/StdPeriph/src/stm32f4xx_ltdc.o ./libs/StdPeriph/src/stm32f4xx_pwr.o ./libs/StdPeriph/src/stm32f4xx_rcc.o ./libs/StdPeriph/src/stm32f4xx_rng.o ./libs/StdPeriph/src/stm32f4xx_rtc.o ./libs/StdPeriph/src/stm32f4xx_sai.o ./libs/StdPeriph/src/stm32f4xx_sdio.o ./libs/StdPeriph/src/stm32f4xx_spi.o ./libs/StdPeriph/src/stm32f4xx_syscfg.o ./libs/StdPeriph/src/stm32f4xx_tim.o ./libs/StdPeriph/src/stm32f4xx_usart.o ./libs/StdPeriph/src/stm32f4xx_wwdg.o -llibs/mammtmym4.a
c:/arm/gnu tools arm embedded/4.8 2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibs/M4_CryptoFW_RngHW_2_0_6.a
collect2.exe: error: ld returned 1 exit status"


I don't understand why it says so. I tried to change the path, the name, the directory... nothing works. Is this a problem of Eclipse or of my toolchain?


Thanks,
Pierpaolo
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 - Cryptographic lib

Post by Giovanni »

It is unrelated to Eclipse, the linker does not find that library M4_CryptoFW_RngHW_2_0_6.a

Giovanni
HyperText
Posts: 2
Joined: Sun Jun 01, 2014 7:59 pm

Re: STM32 - Cryptographic lib

Post by HyperText »

Thanks for the answer!

So what could be the problem? I'm using this toolchain: https://launchpad.net/gcc-arm-embedded
Is this the problem? What could I try?


Thanks,
Pierpaolo
Post Reply