diff mbox series

[RFC,05/10] image: rsa: Move verification algorithm to a linker list

Message ID 20210514194602.598322-6-mr.nuke.me@gmail.com
State RFC
Delegated to: Tom Rini
Headers show
Series image: Reduce the abuse of #ifdefs in image-sig.c | expand

Commit Message

Alex G. May 14, 2021, 7:45 p.m. UTC
Move the RSA verification crytpo_algo structure out of the
crypto_algos array, and into a linker list.

Although it appears we are adding an #ifdef to rsa-verify.c, the gains
outweigh this small inconvenience. This is because rsa_verify() is
defined differently based on #ifdefs. This change allows us to have
a single definition of rsa_verify().

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
 common/image-sig.c   |  9 ---------
 lib/rsa/rsa-verify.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 9 deletions(-)

Comments

Simon Glass May 15, 2021, 3:20 p.m. UTC | #1
On Fri, 14 May 2021 at 13:46, Alexandru Gagniuc <mr.nuke.me@gmail.com> wrote:
>
> Move the RSA verification crytpo_algo structure out of the
> crypto_algos array, and into a linker list.
>
> Although it appears we are adding an #ifdef to rsa-verify.c, the gains
> outweigh this small inconvenience. This is because rsa_verify() is
> defined differently based on #ifdefs. This change allows us to have
> a single definition of rsa_verify().
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---
>  common/image-sig.c   |  9 ---------
>  lib/rsa/rsa-verify.c | 16 ++++++++++++++++
>  2 files changed, 16 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/common/image-sig.c b/common/image-sig.c
index b750751144..d3be30289c 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -53,15 +53,6 @@  struct checksum_algo checksum_algos[] = {
 
 struct crypto_algo crypto_algos[] = {
 	{
-		.name = "rsa2048",
-		.key_len = RSA2048_BYTES,
-		.verify = rsa_verify,
-	},
-	{
-		.name = "rsa4096",
-		.key_len = RSA4096_BYTES,
-		.verify = rsa_verify,
-	},
 };
 
 struct padding_algo padding_algos[] = {
diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c
index aee76f42d5..06b0d82e7d 100644
--- a/lib/rsa/rsa-verify.c
+++ b/lib/rsa/rsa-verify.c
@@ -571,3 +571,19 @@  int rsa_verify(struct image_sign_info *info,
 
 	return rsa_verify_hash(info, hash, sig, sig_len);
 }
+
+#ifndef USE_HOSTCC
+
+U_BOOT_CRYPTO_ALGO(rsa2048) = {
+	.name = "rsa2048",
+	.key_len = RSA2048_BYTES,
+	.verify = rsa_verify,
+};
+
+U_BOOT_CRYPTO_ALGO(rsa4096) = {
+	.name = "rsa4096",
+	.key_len = RSA4096_BYTES,
+	.verify = rsa_verify,
+};
+
+#endif