public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH V3 1/7] rsa: use new openssl API to create signature
@ 2018-11-13 16:43 Philippe Reynes
  2018-11-13 16:43 ` [U-Boot] [PATCH V3 2/7] rsa: add a structure for the padding Philippe Reynes
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Philippe Reynes @ 2018-11-13 16:43 UTC (permalink / raw)
  To: u-boot

Previous implementation of the rsa signature was using
the openssl API EVP_Sign*, but the new openssl API
EVP_DigestSign* is more flexible. So we move to this
new API.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Clément Péron <peron.clem@gmail.com>
---
 lib/rsa/rsa-sign.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Changelog:
v3:
- no change
v2:
- no change

diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index 05ac67b..78e348e 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -393,7 +393,8 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
 {
 	EVP_PKEY *key;
 	EVP_MD_CTX *context;
-	int size, ret = 0;
+	int ret = 0;
+	size_t size;
 	uint8_t *sig;
 	int i;
 
@@ -409,7 +410,7 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
 	size = EVP_PKEY_size(key);
 	sig = malloc(size);
 	if (!sig) {
-		fprintf(stderr, "Out of memory for signature (%d bytes)\n",
+		fprintf(stderr, "Out of memory for signature (%zu bytes)\n",
 			size);
 		ret = -ENOMEM;
 		goto err_alloc;
@@ -421,22 +422,26 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
 		goto err_create;
 	}
 	EVP_MD_CTX_init(context);
-	if (!EVP_SignInit(context, checksum_algo->calculate_sign())) {
+	if (EVP_DigestSignInit(context, NULL,
+			       checksum_algo->calculate_sign(),
+			       NULL, key) <= 0) {
 		ret = rsa_err("Signer setup failed");
 		goto err_sign;
 	}
 
 	for (i = 0; i < region_count; i++) {
-		if (!EVP_SignUpdate(context, region[i].data, region[i].size)) {
+		if (!EVP_DigestSignUpdate(context, region[i].data,
+					  region[i].size)) {
 			ret = rsa_err("Signing data failed");
 			goto err_sign;
 		}
 	}
 
-	if (!EVP_SignFinal(context, sig, sig_size, key)) {
+	if (!EVP_DigestSignFinal(context, sig, &size)) {
 		ret = rsa_err("Could not obtain signature");
 		goto err_sign;
 	}
+
 	#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
 		(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x02070000fL)
 		EVP_MD_CTX_cleanup(context);
@@ -446,7 +451,7 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
 	EVP_MD_CTX_destroy(context);
 	EVP_PKEY_free(key);
 
-	debug("Got signature: %d bytes, expected %d\n", *sig_size, size);
+	debug("Got signature: %d bytes, expected %zu\n", *sig_size, size);
 	*sigp = sig;
 	*sig_size = size;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-14 12:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-13 16:43 [U-Boot] [PATCH V3 1/7] rsa: use new openssl API to create signature Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 2/7] rsa: add a structure for the padding Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 3/7] rsa: add support of padding pss Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 4/7] doc: uImage.FIT: signature.txt: add option padding Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 5/7] configs: sandbox: enable padding pss for rsa signature Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 6/7] test: vboot: add " Philippe Reynes
2018-11-13 16:43 ` [U-Boot] [PATCH V3 7/7] test: vboot: clean its file Philippe Reynes
2018-11-14 12:32   ` Clément Péron
2018-11-14 12:54     ` Philippe REYNES

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox