Skip to main content
Wladimir
Associate II
April 29, 2021
Question

Cryptolib RSA Nucleo-L476RG working slow

  • April 29, 2021
  • 11 replies
  • 2454 views

Hello to all!

Using X-Cube-Cryptolib for RSA algorythm on Nucleo-L476RG board, encryption and subsequent decryption of demo message going very slow - 2 seconds, its mostly decription, i using hardware timer2 for time measuring.

Is there any ways to reduce decription time?

Best regards!

This topic has been closed for replies.

11 replies

Tesla DeLorean
Guru
April 29, 2021

Code your own crypto more optimally? Perhaps there are commercial libraries that run faster, perhaps look at what's available for CM3 and CM4 platforms.

Large bit count, and Elliptic Curve stuff is going to be quite slow.

The L486 would likely provide faster AES-256

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Wladimir
WladimirAuthor
Associate II
April 30, 2021

Are there any STM32 chips that support the RSA algorithm at the hardware level?

Wladimir
WladimirAuthor
Associate II
April 30, 2021

there isn't

Jocelyn RICARD
ST Employee
May 4, 2021

I Wladimir,

Yes there are chips that support public key acceleration:

STM32L5, STM32WL, STM32L4Q, STM32WB and coming STM32U5 with DPA resistance

You have the information in AN5156 (except for STM32L4A which is quite recent)

Best regards

Jocelyn

Wladimir
WladimirAuthor
Associate II
April 30, 2021

Hello!

The Cryptolib documentation has performance tables for the RSA encryption algorithm.

0693W00000AMy7fQAD.png0693W00000AMy7kQAD.pngIn the demo example for the NUCLEO-L476RG board, decryption using the RSA algorithm takes 195123172 clock cycles, the chip operates at a frequency of 80 MHz, so decryption takes 2.5 seconds. But, according to Table 53, the decryption time should take 57192232 clock cycles, which is less than a second, and the key size is larger than in the demo example.

How can i achieve at least this speed of decryption? Why does the speed in the demo example not match the speed in the documentation? Despite the fact that the key is smaller.

And if we look at table 54 - there is decryption time takes 7588416 clock cycles, outstanding!) With key size 2048.

How can i achieve that?

Best regards, Vladimir.

Wladimir
WladimirAuthor
Associate II
May 4, 2021

Hello to all!!

Is it possible to increase the block of data for encryption and decryption for the RSA algorithm?

The current limit is 244 bytes.

Best regards!

Wladimir
WladimirAuthor
Associate II
May 7, 2021

Hello!

How can i include cryptolyb library .a files into STM32CubeIDE project?

Project doesn't recognize them for now. I put them in source directory in project files catalog.

0693W00000ANemuQAD.jpg 

0693W00000ANeo2QAD.jpg 

The following errors occur:

" ../Src/main.c:313: undefined reference to `RSA_PKCS1v15_Encrypt' "

" ../Src/main.c:297: undefined reference to `RNGinit' "

Best regards!

Wladimir
WladimirAuthor
Associate II
May 7, 2021

Adding libs directory to "Library Path" in Project Properties doesn't change anything.

Jocelyn RICARD
ST Employee
May 7, 2021

Hello Wladimir,

You can add the library in the Build configuration/Setting/GCC Linker/Libraries

In top window add:

:STM32CryptographicV3.0.0_CM4_GCC.a

in bottom window add the path to the library

Best regards

Jocelyn

Wladimir
WladimirAuthor
Associate II
May 7, 2021

Hello Jocelyn RICARD,

Unfortunately, it didn't help, the error has changed, now can't find the library file. The path to the library file I tried is both absolute and relative to the workspace.

0693W00000ANiJNQA1.png 

The error is:

" c:\st\stm32cubeide_1.3.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: cannot find -l:STM32CryptographicV3.0.0_CM4_GCC.a "

Best regards, Vladimir

Jocelyn RICARD
ST Employee
May 10, 2021

Hello Wladimir,

the issue could be related to too long path.

Could you try moving your project in a directory close to root ?

Otherwise, you could get the last cryptolib patch

The STM32CubeIDE is supported there for the recent STM32 families

Best regards

Jocelyn

Wladimir
WladimirAuthor
Associate II
May 10, 2021

Hello, Jocelyn RICARD,

Found solution of my problem in this topic, check out my latest post:

https://community.st.com/s/question/0D50X0000BJ2gL4SQJ/how-to-add-external-libraries-in-stm32cubeide?t=1620543260730

Wladimir
WladimirAuthor
Associate II
May 10, 2021

If we talk about the original question of this topic, as I understand it, there are no ways to speed up the STM32Cryptolib.