From: York Sun <york.sun@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 5/9] fsl: secure boot: Add fsl_rsa_modexp_raw function for scenarios without DM model
Date: Mon, 15 May 2017 09:16:05 -0700 [thread overview]
Message-ID: <1494864969-7374-6-git-send-email-york.sun@nxp.com> (raw)
In-Reply-To: <1494864969-7374-1-git-send-email-york.sun@nxp.com>
From: Ruchika Gupta <ruchika.gupta@nxp.com>
Add fsl_rsa_modexp_raw() for secure boot during SPL stage where DM
driver is not loaded.
Signed-off-by: Sumit Garg <sumit.garg@nxp.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta@nxp.com>
Signed-off-by: York Sun <york.sun@nxp.com>
---
board/freescale/common/fsl_validate.c | 13 +++++++++----
drivers/crypto/fsl/fsl_rsa.c | 28 ++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/board/freescale/common/fsl_validate.c b/board/freescale/common/fsl_validate.c
index 86baecc..96bd879 100644
--- a/board/freescale/common/fsl_validate.c
+++ b/board/freescale/common/fsl_validate.c
@@ -786,10 +786,6 @@ static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img)
{
int ret;
uint32_t key_len;
- struct key_prop prop;
-#if !defined(USE_HOSTCC)
- struct udevice *mod_exp_dev;
-#endif
ret = calc_esbchdr_esbc_hash(img);
if (ret)
return ret;
@@ -797,6 +793,14 @@ static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img)
/* Construct encoded hash EM' wrt PKCSv1.5 */
construct_img_encoded_hash_second(img);
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_DM)
+ ret = fsl_mod_exp_raw(img->img_sign, img->hdr.sign_len,
+ img->img_key, key_len, img->img_encoded_hash);
+#else
+ struct key_prop prop;
+#if !defined(USE_HOSTCC)
+ struct udevice *mod_exp_dev;
+#endif
/* Fill prop structure for public key */
memset(&prop, 0, sizeof(struct key_prop));
key_len = get_key_len(img) / 2;
@@ -813,6 +817,7 @@ static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img)
ret = rsa_mod_exp(mod_exp_dev, img->img_sign, img->hdr.sign_len,
&prop, img->img_encoded_hash);
+#endif
if (ret)
return ret;
diff --git a/drivers/crypto/fsl/fsl_rsa.c b/drivers/crypto/fsl/fsl_rsa.c
index 5471504..32c059f 100644
--- a/drivers/crypto/fsl/fsl_rsa.c
+++ b/drivers/crypto/fsl/fsl_rsa.c
@@ -15,7 +15,34 @@
#include "jr.h"
#include "rsa_caam.h"
#include <u-boot/rsa-mod-exp.h>
+#include <fsl_validate.h>
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_DM)
+int fsl_mod_exp_raw(const uint8_t *sig, uint32_t sig_len,
+ uint8_t *rsa_pub_key, int keylen, uint8_t *out)
+{
+ struct pk_in_params pkin;
+ uint32_t *desc = malloc(sizeof(int) * MAX_CAAM_DESCSIZE);
+ int ret;
+
+ pkin.a = sig;
+ pkin.a_siz = sig_len;
+ pkin.n = rsa_pub_key;
+ pkin.n_siz = keylen;
+ pkin.e = rsa_pub_key + keylen;
+ pkin.e_siz = keylen;
+
+ inline_cnstr_jobdesc_pkha_rsaexp(desc, &pkin, out, sig_len);
+
+ ret = run_descriptor_jr(desc);
+ if (ret) {
+ debug("%s: RSA failed to verify: %d\n", __func__, ret);
+ return -EFAULT;
+ }
+
+ return 0;
+}
+#else
int fsl_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
struct key_prop *prop, uint8_t *out)
{
@@ -59,3 +86,4 @@ U_BOOT_DRIVER(fsl_rsa_mod_exp) = {
U_BOOT_DEVICE(fsl_rsa) = {
.name = "fsl_rsa_mod_exp",
};
+#endif
--
2.7.4
next prev parent reply other threads:[~2017-05-15 16:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-15 16:16 [U-Boot] [PATCH v1 0/9] Enable falcon boot for LS1043ARDB SDCARD boot York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 1/9] armv8: ls1043ardb: Use static DDR setting for SPL secure boot York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 2/9] armv8: layerscape: Eanble falcon boot York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 3/9] armv8: ls1043ardb_sdcard: Enable " York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 4/9] fsl: secure boot: Remove dependency of command line for fsl_validate.c York Sun
2017-11-29 18:39 ` York Sun
2017-05-15 16:16 ` York Sun [this message]
2017-05-15 16:16 ` [U-Boot] [PATCH v1 6/9] crypto: fsl: Allocate memory for descriptor from main memory York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 7/9] armv8: fsl-layerscape: Enable secure boot valiation for SPL boot York Sun
2017-05-16 0:37 ` Tom Rini
2017-05-16 16:04 ` york sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 8/9] armv8: layerscape: falcon: Implement FIT image validation York Sun
2017-05-15 16:16 ` [U-Boot] [PATCH v1 9/9] armv8: ls1043ardb: Enable loading PPA and falcon boot for SD secure boot York Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1494864969-7374-6-git-send-email-york.sun@nxp.com \
--to=york.sun@nxp.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox