Skip to contentSkip to conversation

lib/rsa: Modify rsa to use DM driver if available

PATCH New Ruchika Gupta 2 participants 2 messages Dec 29, 2014 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): BY1PR0301MB12889C93AD54022544095D3EEF540@BY1PR0301MB1288.namprd03.prod.outlook.com

#1 lore raw

PATCH v3 5/9 lib/rsa: Modify rsa to use DM driver if available

Resending as the message bounced from u-boot mailing list.

Hi Simon,

Quoted 34 lines

-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: Wednesday, December 24, 2014 6:19 AM
To: Gupta Ruchika-R66431
Cc: U-Boot Mailing List; Sun York-R58495
Subject: Re: [PATCH 5/9] [v3] lib/rsa: Modify rsa to use DM driver if available

Hi Ruchika,

Quoted 21 lines · Ruchika Gupta

Modify rsa_verify to use the rsa driver of DM library available.The tools and the configurations which don't use Driver Model, will continue to use the same RSA sw library. The software implementation of RSA Modular Exponentation is now compiled if RSA_MOD_EXP_SW is selected.

Kconfig options are also added for rsa library.

---
Changes in v3:
New patch

 include/configs/am335x_evm.h |  1 +
 lib/Kconfig                  |  6 +-----
 lib/rsa/Kconfig              | 31 +++++++++++++++++++++++++++++++
 lib/rsa/Makefile             |  3 ++-
 lib/rsa/rsa-verify.c         | 18 ++++++++++++++++++
 5 files changed, 53 insertions(+), 6 deletions(-)  create mode

100644 lib/rsa/Kconfig

Quoted 11 lines

include/configs/am335x_evm.h line 28

Quoted 9 lines
(quoted diff) +0 -0

b/include/configs/am335x_evm.h index cc36985..aa79841 100644

include/configs/am335x_evm.h +1 -0
@@ -25,6 +25,7 @@
 # ifdef CONFIG_ENABLE_VBOOT
 # define CONFIG_FIT_SIGNATURE
 # define CONFIG_RSA
+# define CONFIG_RSA_MOD_EXP_SW

This should go in am335x_boneblack_vboot_defconfig I think.

I didn?t move it in the defconfig as it was conditionally defined under CONFIG_ENABLE_VBOOT

Quoted 114 lines
Quoted 33 lines
include/configs/am335x_evm.h +0 -0
 # endif
 #endif
 
lib/Kconfig +1 -5
@@ -27,10 +27,6 @@ config SYS_HZ
          get_timer() must operate in milliseconds and this option must be
          set to 1000.
 
-config RSA
-       bool "Use RSA Library"
-       help
-         RSA support.This enables the RSA algorithm used for FIT image
-         verification in U-Boot.
+source lib/rsa/Kconfig
 
 endmenu
lib/rsa/Kconfig new file +9 -0
index 0000000..8f9aa44
@@ -0,0 +1,31 @@
+config RSA
+       bool "Use RSA Library"
+       select RSA_MOD_EXP_SW if !DM
+       select DM_RSA if DM
+       help
+         RSA support.This enables the RSA algorithm used for FIT image
+         verification in U-Boot.
+         See doc/uImage.FIT/signature.txt for more details.
+

lib/rsa/Kconfig line 19

Quoted 10 lines
lib/rsa/Kconfig new file +10 -0
+if RSA && DM_RSA
+
+config RSA_SW
+       bool "User driver Model for RSA Modular Exponentiation in software"
+       depends on DM && DM_RSA && RSA
+       select RSA_MOD_EXP_SW
+       default y
+       help
+         Enables driver for modular exponentiation in software.
+This is a

RSA

lib/rsa/Kconfig

Quoted 13 lines
lib/rsa/Kconfig new file +13 -0
+         algorithm used in FIT image verification. It required RSA Key as
+         input.
+         See doc/uImage.FIT/signature.txt for more details.
+
+endif
+
+config RSA_MOD_EXP_SW
+       bool
+       default n
+       help
+         Library for SW implementation of RSA Modular Exponentiation. This
+         library is used by the mkimage tool(not selected through
+this

option)

Quoted 26 lines
lib/rsa/Kconfig new file +1 -0
+         as well as by the RSA driver model with SW implementation.
lib/rsa/Makefile index renamed from lib/rsa/Makefile +0 -0

cc25b3c..ccc6060 100644

lib/rsa/Makefile +0 -1
@@ -7,4 +7,5 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
-obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o

rsa-mod-exp.o

lib/rsa/Makefile +2 -0
+obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o
+obj-$(CONFIG_RSA_MOD_EXP_SW) += rsa-mod-exp.o
lib/rsa/rsa-verify.c index renamed from lib/rsa/rsa-verify.c +0 -0

f8bc086..27f10ef 100644

lib/rsa/rsa-verify.c +1 -0
@@ -12,6 +12,7 @@
 #include <asm/errno.h>
 #include <asm/types.h>
 #include <asm/unaligned.h>
+#include <dm.h>
 #else
 #include "fdt_host.h"
 #include "mkimage.h"
@@ -43,6 +44,9 @@ static int rsa_verify_key(struct key_prop *prop,
Quoted 1 line

const

uint8_t *sig,

Quoted 28 lines
        const uint8_t *padding;
        int pad_len;
        int ret;
lib/rsa/rsa-verify.c +16 -0
+#if defined(CONFIG_DM_RSA) && !defined(USE_HOSTCC)
+       struct udevice *rsa_dev;
+#endif
 
        if (!prop || !sig || !hash || !algo)
                return -EIO;
@@ -63,11 +67,25 @@ static int rsa_verify_key(struct key_prop *prop,
 const uint8_t *sig,
 
        uint8_t buf[sig_len];
 
+#if defined(CONFIG_DM_RSA) && !defined(USE_HOSTCC)
+       ret = uclass_get_device(UCLASS_RSA, 0, &rsa_dev);
+       if (!ret) {
+               ret = rsa_mod_exp(rsa_dev, sig, sig_len, prop, buf);
+               if (ret) {
+                       debug("Error in Modular exponentation\n");
+                       return ret;
+               }
+       } else {
+               printf("RSA: Can't find Mod Exp implemnetation\n");
+               return -EINVAL;
+       }
+#else
        ret = rsa_mod_exp_sw(sig, sig_len, prop, buf);
Quoted 8 lines

lib/rsa/rsa-verify.c static int rsa_verify_key(struct key_prop *prop, · line 89

Quoted 5 lines
lib/rsa/rsa-verify.c +1 -0
        if (ret) {
                debug("Error in Modular exponentation\n");
                return ret;
        }
+#endif

This should use the uclass regardless I think. The software implementation should just be a driver like the hardware implementation.

I have already added software implementation as a driver in the previous patch. I have kept it here for the tools (mkimage) and the platforms which don?t use CONFIG_DM by default.

Quoted 10 lines
Quoted 7 lines
lib/rsa/rsa-verify.c +0 -1
        padding = algo->rsa_padding;
        pad_len = algo->pad_len - algo->checksum_len;
--

1.8.1.4

Regards,
Simon

Regards,
Ruchika

#2 lore raw

PATCH v3 5/9 lib/rsa: Modify rsa to use DM driver if available

Hi Ruchika,

Quoted 176 lines · Ruchika Gupta

Resending as the message bounced from u-boot mailing list.

Hi Simon,

Quoted 34 lines

-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: Wednesday, December 24, 2014 6:19 AM
To: Gupta Ruchika-R66431
Cc: U-Boot Mailing List; Sun York-R58495
Subject: Re: [PATCH 5/9] [v3] lib/rsa: Modify rsa to use DM driver if available

Hi Ruchika,

Quoted 21 lines · Ruchika Gupta

Modify rsa_verify to use the rsa driver of DM library available.The tools and the configurations which don't use Driver Model, will continue to use the same RSA sw library. The software implementation of RSA Modular Exponentation is now compiled if RSA_MOD_EXP_SW is selected.

Kconfig options are also added for rsa library.

---
Changes in v3:
New patch

 include/configs/am335x_evm.h |  1 +
 lib/Kconfig                  |  6 +-----
 lib/rsa/Kconfig              | 31 +++++++++++++++++++++++++++++++
 lib/rsa/Makefile             |  3 ++-
 lib/rsa/rsa-verify.c         | 18 ++++++++++++++++++
 5 files changed, 53 insertions(+), 6 deletions(-)  create mode

100644 lib/rsa/Kconfig

Quoted 11 lines

include/configs/am335x_evm.h line 28

Quoted 9 lines
(quoted diff) +0 -0

b/include/configs/am335x_evm.h index cc36985..aa79841 100644

include/configs/am335x_evm.h +1 -0
@@ -25,6 +25,7 @@
 # ifdef CONFIG_ENABLE_VBOOT
 # define CONFIG_FIT_SIGNATURE
 # define CONFIG_RSA
+# define CONFIG_RSA_MOD_EXP_SW

This should go in am335x_boneblack_vboot_defconfig I think.

I didn?t move it in the defconfig as it was conditionally defined under CONFIG_ENABLE_VBOOT

Quoted 114 lines
Quoted 33 lines
include/configs/am335x_evm.h +0 -0
 # endif
 #endif
 
lib/Kconfig +1 -5
@@ -27,10 +27,6 @@ config SYS_HZ
          get_timer() must operate in milliseconds and this option must be
          set to 1000.
 
-config RSA
-       bool "Use RSA Library"
-       help
-         RSA support.This enables the RSA algorithm used for FIT image
-         verification in U-Boot.
+source lib/rsa/Kconfig
 
 endmenu
lib/rsa/Kconfig new file +9 -0
index 0000000..8f9aa44
@@ -0,0 +1,31 @@
+config RSA
+       bool "Use RSA Library"
+       select RSA_MOD_EXP_SW if !DM
+       select DM_RSA if DM
+       help
+         RSA support.This enables the RSA algorithm used for FIT image
+         verification in U-Boot.
+         See doc/uImage.FIT/signature.txt for more details.
+

lib/rsa/Kconfig line 19

Quoted 10 lines
lib/rsa/Kconfig new file +10 -0
+if RSA && DM_RSA
+
+config RSA_SW
+       bool "User driver Model for RSA Modular Exponentiation in software"
+       depends on DM && DM_RSA && RSA
+       select RSA_MOD_EXP_SW
+       default y
+       help
+         Enables driver for modular exponentiation in software.
+This is a

RSA

lib/rsa/Kconfig

Quoted 13 lines
lib/rsa/Kconfig new file +13 -0
+         algorithm used in FIT image verification. It required RSA Key as
+         input.
+         See doc/uImage.FIT/signature.txt for more details.
+
+endif
+
+config RSA_MOD_EXP_SW
+       bool
+       default n
+       help
+         Library for SW implementation of RSA Modular Exponentiation. This
+         library is used by the mkimage tool(not selected through
+this

option)

Quoted 26 lines
lib/rsa/Kconfig new file +1 -0
+         as well as by the RSA driver model with SW implementation.
lib/rsa/Makefile index renamed from lib/rsa/Makefile +0 -0

cc25b3c..ccc6060 100644

lib/rsa/Makefile +0 -1
@@ -7,4 +7,5 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
-obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o

rsa-mod-exp.o

lib/rsa/Makefile +2 -0
+obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o
+obj-$(CONFIG_RSA_MOD_EXP_SW) += rsa-mod-exp.o
lib/rsa/rsa-verify.c index renamed from lib/rsa/rsa-verify.c +0 -0

f8bc086..27f10ef 100644

lib/rsa/rsa-verify.c +1 -0
@@ -12,6 +12,7 @@
 #include <asm/errno.h>
 #include <asm/types.h>
 #include <asm/unaligned.h>
+#include <dm.h>
 #else
 #include "fdt_host.h"
 #include "mkimage.h"
@@ -43,6 +44,9 @@ static int rsa_verify_key(struct key_prop *prop,
Quoted 1 line

const

uint8_t *sig,

Quoted 28 lines
        const uint8_t *padding;
        int pad_len;
        int ret;
lib/rsa/rsa-verify.c +16 -0
+#if defined(CONFIG_DM_RSA) && !defined(USE_HOSTCC)
+       struct udevice *rsa_dev;
+#endif
 
        if (!prop || !sig || !hash || !algo)
                return -EIO;
@@ -63,11 +67,25 @@ static int rsa_verify_key(struct key_prop *prop,
 const uint8_t *sig,
 
        uint8_t buf[sig_len];
 
+#if defined(CONFIG_DM_RSA) && !defined(USE_HOSTCC)
+       ret = uclass_get_device(UCLASS_RSA, 0, &rsa_dev);
+       if (!ret) {
+               ret = rsa_mod_exp(rsa_dev, sig, sig_len, prop, buf);
+               if (ret) {
+                       debug("Error in Modular exponentation\n");
+                       return ret;
+               }
+       } else {
+               printf("RSA: Can't find Mod Exp implemnetation\n");
+               return -EINVAL;
+       }
+#else
        ret = rsa_mod_exp_sw(sig, sig_len, prop, buf);
Quoted 8 lines

lib/rsa/rsa-verify.c static int rsa_verify_key(struct key_prop *prop, · line 89

Quoted 5 lines
lib/rsa/rsa-verify.c +1 -0
        if (ret) {
                debug("Error in Modular exponentation\n");
                return ret;
        }
+#endif

This should use the uclass regardless I think. The software implementation should just be a driver like the hardware implementation.

Quoted 1 line

I have already added software implementation as a driver in the previous patch. I have kept it here for the tools (mkimage) and the platforms which don?t use CONFIG_DM by default.

Ah I see, OK. Sorry I missed this.

Then I think rsa_mod_exp_sw() should be called from within the software driver also. You may already be doing that, but let's make sure the code is as common as possible.

Regards,
Simon