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_contextcontains these 13mbedtls_mpistructs, so if you dosizeof(mbedtls_rsa_context), it already includes the13 * sizeof(mbedtls_mpi )part. So, no need to add that part. As for the RAM that eachmbedtls_mpiconsumes, as you can see inmbedtls_mpi_grow, the size that is allocated is the number of limbs (x->n) multiplied with chars in limbs (CiL). If you usembedtls_mpi_sizeon 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