Mbed TLS is now part of TrustedFirmware.org.

RSA for MCU


Jan 11, 2011 07:41
Johnny You

Hi,
I'm currently working with RSA library from PolarSSL on TI Stellaris Cortex-M3 MCU. My application is very complicated, so I need to use an RTOS (FreeRTOS) inside.

When the first time I tried this library on my MCU, the program works fine. After I merge the library with my application, my CPU stops after executing RSA verification process. After tracing, I know the problem is within bignum.c file which rely heavily on malloc function (mpi_grow). The program works fine if I commented out all function related to it or change mpi_grow with a fixed length array.

But the problem is, due to my limited programming skill, not all mpi_grow can be converted to use fixed array successfully.

It is not recommended to use malloc in embedded processor, Is there any way to implement rsa algorithm without using malloc?

Thank you
 
Jan 12, 2011 08:13
Paul Bakker

Hi Johnie,

I understand that in some situations you can run into problems with malloc() on your MCU.

It is possible to make PolarSSL use no dynamic allocation at all for RSA. I'll try to see if I can get a write-up and patch in the Documentation section. If you need it sooner that end of next month, please contact me by mail (p.j.bakker at polarssl dot org)

Paul
 
Feb 10, 2011 16:58
devine

For a fixed, known RSA public key length, it is entirely possible to know in advance the max. size of the structure. However those are rather large numbers, so stack might not be enough -- you could use a pool of global variables, returning the next free one for each allocation. For ease of use, this could be a wrapper around malloc.
 
Feb 10, 2011 17:19
Jean-Marc

malloc is slow and takes allot of code space. It is not recommended for that reason. If you can live with that then try increasing and decreasing your stack size. Malloc was not working for me on the STM32 so I increase the stack size by a fair amount and it works well now.
 
Apr 26, 2011 08:24
Jonas

Hi Johnnie!

I'm working on a thesis based on an STM Cortex-M3 and FreeRTOS + POLARSSL. I had the same problem with malloc in "mpi_grow".

In FreeRTOS you should use "pvPortMalloc" and "vPortFree" instead of "malloc" and "free". Read more on: http://www.freertos.org/a00111.html

Regards Jonas
 
Aug 20, 2011 15:41
Thomas

Hi Paul,

I'm facing this problem also. My target is to port bignum&rsa functions to MCU(arm cortex m3). Any advice?

Polarssl is very good! Architecture is well designed, code is clean, document is find, and full of test and samples. It costed less for me to understand the lib.
 
Aug 20, 2011 19:58
Marcos Oliveira

Hi,

take a look at: http://polarssl.org/forum_view_topic?topic_id=154 (ARM Cortex M3 LM3S6965 - RSA implementation)

I have a FW running with cortex-m3 and if you want I can send my source code to you... I also have a tool written with VC++ to send and recieve commands...

Best regards.
 
Aug 21, 2011 00:22
Thomas

Thank you very much! Please send them all to donghb@gmail.com
 
Dec 23, 2011 09:26
Ayhan

Hi,
Im stduying on RSA implemantation too. Could you send me your source code me too.
Thanks.
 
Sep 14, 2012 10:14
Jerry Black

Hi,

In order to use the malloc() command on the Stellaris you
need to set the heap size in the startup file. it just below the stack size. malloc() uses that heap space for dynamic memory allocation.

-Jerry B.
 
Jul 17, 2015 15:25
Jeff White

HI

I am trying to build PolarSSL into a embedded project on a MSP430/TI-CSS/TI-RTOS and would also appreciate if you could send me your example code.

Many thanks,

Jeff White

 
Aug 18, 2016 08:16
mika

Hi All,

I am using Cortex-M4(STM32F4), mbedTLS and not using any RTOS. I am also facing the same problem with calloc in mpi_grow.

Can anyone help me to resolve this issue.