lib: rsa: introduce RSA_SOFTWARE_EXP_TINY
RFC PATCH 1/1 lib: rsa: introduce RSA_SOFTWARE_EXP_TINY
From: Igor Opaniuk <[email protected]>
Introduce RSA_SOFTWARE_EXP_TINY Kconfig option, which does not require DM to be enabled. This can be handy on devices, where SPL + signed U-Boot FIT image setup is used, where it isn't possible to enable SPL_DM mainly due to SRAM size constraits.
For example, on iMX8MM with this option enabled and SPL_DM disabled it's possible to save almost 11Kb:
With RSA_SOFTWARE_EXP_TINY enabled:
spl/u-boot-spl-nodtb.bin 99824
Without:
spl/u-boot-spl-nodtb.bin 111088
---
lib/rsa/Kconfig | 11 ++++++++++- lib/rsa/rsa-verify.c | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
lib/rsa/Kconfig +10 -1
@@ -1,7 +1,8 @@ config RSA bool "Use RSA Library" select RSA_FREESCALE_EXP if FSL_CAAM && !ARCH_MX7 && !ARCH_MX6 && !ARCH_MX5 - select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP + select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP && DM + select RSA_SOFTWARE_EXP_TINY if !RSA_FREESCALE_EXP && !DM help RSA support. This enables the RSA algorithm used for FIT image verification in U-Boot.
@@ -45,6 +46,14 @@ config RSA_VERIFY_WITH_PKEY directly specified in image_sign_info, where all the necessary key properties will be calculated on the fly in verification code. +config RSA_SOFTWARE_EXP_TINY + bool "Enable non-DM RSA Modular Exponentiation software implementation" + help + Enable modular exponentiation implementation in software, which + does not require Driver Model to be enabled. This is a RSA algorithm + used in FIT image verification. It required RSA Key as input. + See doc/uImage.FIT/signature.txt for more details. + config RSA_SOFTWARE_EXP bool "Enable driver for RSA Modular Exponentiation in software" depends on DM
lib/rsa/rsa-verify.c +4 -4
@@ -319,7 +319,7 @@ static int rsa_verify_key(struct image_sign_info *info, const uint32_t key_len) {int ret; -#if !defined(USE_HOSTCC ) +#if !(defined(USE_HOSTCC ) || defined(RSA_SOFTWARE_EXP_TINY ))struct udevice *mod_exp_dev;#endif struct checksum_algo *checksum = info->checksum;
@@ -346,7 +346,9 @@ static int rsa_verify_key(struct image_sign_info *info,uint8_t buf[sig_len]; hash_len = checksum->checksum_len; -#if !defined(USE_HOSTCC ) +#if defined(USE_HOSTCC ) || defined(RSA_SOFTWARE_EXP_TINY ) + ret =rsa_mod_exp_sw (sig, sig_len, prop, buf); +#else ret =uclass_get_device (UCLASS_MOD_EXP ,0 , &mod_exp_dev);if (ret) {printf ("RSA: Can't find Modular Exp implementation\n" );
@@ -354,8 +356,6 @@ static int rsa_verify_key(struct image_sign_info *info, } ret =rsa_mod_exp (mod_exp_dev, sig, sig_len, prop, buf); -#else - ret =rsa_mod_exp_sw (sig, sig_len, prop, buf);#endif if (ret) {debug ("Error in Modular exponentation\n" );
Signature · 1 line
2.25.1
RFC PATCH 1/1 lib: rsa: introduce RSA_SOFTWARE_EXP_TINY
Hi Igor,
Quoted 10 lines · Igor Opaniuk
From: Igor Opaniuk <[email protected]>
Introduce
RSA_SOFTWARE_EXP_TINYKconfigoption, which does not require DM to be enabled. This can be handy on devices, where SPL + signed U-Boot FIT image setup is used, where it isn't possible to enableSPL_DMmainly due to SRAM size constraits.For example, on iMX8MM with this option enabled and
SPL_DMdisabled it's possible to save almost 11Kb:
That seems a lot...do you have OF_PLATDATA enabled?
Quoted 7 lines
With
RSA_SOFTWARE_EXP_TINYenabled:
spl/u-boot-spl-nodtb.bin 99824Without:
spl/u-boot-spl-nodtb.bin 111088
Quoted 6 lines
Signed-off-by Igor Opaniuk <[email protected]>---
lib/rsa/Kconfig | 11 ++++++++++- lib/rsa/rsa-verify.c | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
Regards,
Simon
RFC PATCH 1/1 lib: rsa: introduce RSA_SOFTWARE_EXP_TINY
Hi Simon,
Quoted 12 lines · Simon Glass
Hi Igor,
Quoted 8 lines · Igor Opaniuk
From: Igor Opaniuk <[email protected]>
Introduce
RSA_SOFTWARE_EXP_TINYKconfigoption, which does not require DM to be enabled. This can be handy on devices, where SPL + signed U-Boot FIT image setup is used, where it isn't possible to enableSPL_DMmainly due to SRAM size constraits.
Quoted 4 lines
Quoted 2 lines
For example, on iMX8MM with this option enabled and
SPL_DMdisabled it's possible to save almost 11Kb:That seems a lot...do you have
OF_PLATDATAenabled?
Nope, it's not enabled.
I've managed to get these numbers when experimenting with NXP U-Boot fork, which is based on 2020.04.
I also checked a while ago iMX6ULL mainline U-Boot with this patch, and size decrease was around 4-5 Kb, which basically is also not bad (considering 64Kb SPL size limitation for this SoC).
Quoted 11 lines
Quoted 11 lines
With
RSA_SOFTWARE_EXP_TINYenabled:
spl/u-boot-spl-nodtb.bin 99824Without:
spl/u-boot-spl-nodtb.bin 111088Signed-off-by Igor Opaniuk <[email protected]>---
Quoted 6 lines
Quoted 3 lines
lib/rsa/Kconfig | 11 ++++++++++- lib/rsa/rsa-verify.c | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-)Regards,
Simon
Thanks
Signature · 7 lines
Best regards - Freundliche Gr?sse - Meilleures salutations Igor Opaniuk Embedded Software Engineer T: +380 938364067 E: igor.opaniuk at foundries.io W: www.foundries.io
RFC PATCH 1/1 lib: rsa: introduce RSA_SOFTWARE_EXP_TINY
Hi Igor,
Quoted 16 lines · Igor Opaniuk
Hi Simon,
Quoted 12 lines · Simon Glass
Hi Igor,
Quoted 8 lines · Igor Opaniuk
From: Igor Opaniuk <[email protected]>
Introduce
RSA_SOFTWARE_EXP_TINYKconfigoption, which does not require DM to be enabled. This can be handy on devices, where SPL + signed U-Boot FIT image setup is used, where it isn't possible to enableSPL_DMmainly due to SRAM size constraits.
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
For example, on iMX8MM with this option enabled and
SPL_DMdisabled it's possible to save almost 11Kb:That seems a lot...do you have
OF_PLATDATAenabled?Nope, it's not enabled.
I think you should look at that first. It is likely to give a much larger benefit.
Quoted 6 lines
I've managed to get these numbers when experimenting with NXP U-Boot fork, which is based on 2020.04.
I also checked a while ago iMX6ULL mainline U-Boot with this patch, and size decrease was around 4-5 Kb, which basically is also not bad (considering 64Kb SPL size limitation for this SoC).
OK I see, but if we did this with every subsystem won't we end up with chaos? There will be cases where driver model is impossible, but with 64KB (which I assume you mean) I would hope that we could avoid it.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
With
RSA_SOFTWARE_EXP_TINYenabled:
spl/u-boot-spl-nodtb.bin 99824Without:
spl/u-boot-spl-nodtb.bin 111088
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Signed-off-by Igor Opaniuk <[email protected]>---
lib/rsa/Kconfig | 11 ++++++++++- lib/rsa/rsa-verify.c | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
Regards,
Simon