I use MBED-TLS on STM32F103 device. STM 32F103 device has little SRAM memory (20 Kbytes).
I would like to calculate the ram used by mbedtls_rsa_context
How to do this? Is it :
sizeof(mbedtls_rsa_context) + 13 * sizeof(mbedtls_mpi ) + mbedtls_mpi_size (D) + ..... + mbedtls_mpi_size (Vf)
Thanks,
Regards.
Note that the struct mbedtls_rsa_context
contains these 13 mbedtls_mpi
structs, so if you do sizeof(mbedtls_rsa_context)
, it already includes the 13 * sizeof(mbedtls_mpi )
part. So, no need to add that part.
As for the RAM that each mbedtls_mpi
consumes, as you can see in mbedtls_mpi_grow
, the size that is allocated is the number of limbs (x->n) multiplied with chars in limbs (CiL).
If you use mbedtls_mpi_size
on every mpi, it will just give you the size in bytes that the big integer uses, without the leading zeros, if there are any, which also consume RAM.
Note that this means accessing internal members of the struct, which is not recommended, however there isn't any public API to get that knowledge.
If you are constrained with SRAM, have you considered using ECDSA keys, as same security strength keys consume less RAM?
Regards