All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jelle van der Waa <jelle@vdwaa.nl>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/3] tools: kwbimage fix build with OpenSSL 1.1.x
Date: Tue,  4 Apr 2017 23:59:50 +0200	[thread overview]
Message-ID: <20170404215950.6588-3-jelle@vdwaa.nl> (raw)
In-Reply-To: <20170404215950.6588-1-jelle@vdwaa.nl>

The rsa_st struct has been made opaque in 1.1.x, add forward compatible
code to access the n, e, d members of rsa_struct.

EVP_MD_CTX_cleanup has been removed in 1.1.x and EVP_MD_CTX_reset should be
called to reinitialise an already created structure.

Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
 tools/kwbimage.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 2c637c7446..e07e3cc467 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -22,6 +22,25 @@
 #include <openssl/pem.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
+void RSA_get0_key(const RSA *r,
+                 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
+{
+   if (n != NULL)
+       *n = r->n;
+   if (e != NULL)
+       *e = r->e;
+   if (d != NULL)
+       *d = r->d;
+}
+
+#else
+void EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
+{
+	EVP_MD_CTX_reset(ctx);
+}
+#endif
 #endif
 
 static struct image_cfg_element *image_cfg;
@@ -470,12 +489,16 @@ static int kwb_export_pubkey(RSA *key, struct pubkey_der_v1 *dst, FILE *hashf,
 			     char *keyname)
 {
 	int size_exp, size_mod, size_seq;
+	const BIGNUM *key_e, *key_n;
 	uint8_t *cur;
 	char *errmsg = "Failed to encode %s\n";
 
-	if (!key || !key->e || !key->n || !dst) {
+	RSA_get0_key(key, NULL, &key_e, NULL);
+	RSA_get0_key(key, NULL, &key_n, NULL);
+
+	if (!key || !key_e || !key_n || !dst) {
 		fprintf(stderr, "export pk failed: (%p, %p, %p, %p)",
-			key, key->e, key->n, dst);
+			key, key_e, key_n, dst);
 		fprintf(stderr, errmsg, keyname);
 		return -EINVAL;
 	}
@@ -490,8 +513,8 @@ static int kwb_export_pubkey(RSA *key, struct pubkey_der_v1 *dst, FILE *hashf,
 	 * do the encoding manually.
 	 */
 
-	size_exp = BN_num_bytes(key->e);
-	size_mod = BN_num_bytes(key->n);
+	size_exp = BN_num_bytes(key_e);
+	size_mod = BN_num_bytes(key_n);
 	size_seq = 4 + size_mod + 4 + size_exp;
 
 	if (size_mod > 256) {
@@ -520,14 +543,14 @@ static int kwb_export_pubkey(RSA *key, struct pubkey_der_v1 *dst, FILE *hashf,
 	*cur++ = 0x82;
 	*cur++ = (size_mod >> 8) & 0xFF;
 	*cur++ = size_mod & 0xFF;
-	BN_bn2bin(key->n, cur);
+	BN_bn2bin(key_n, cur);
 	cur += size_mod;
 	/* Exponent */
 	*cur++ = 0x02;		/* INTEGER */
 	*cur++ = 0x82;
 	*cur++ = (size_exp >> 8) & 0xFF;
 	*cur++ = size_exp & 0xFF;
-	BN_bn2bin(key->e, cur);
+	BN_bn2bin(key_e, cur);
 
 	if (hashf) {
 		struct hash_v1 pk_hash;
-- 
2.12.2

  parent reply	other threads:[~2017-04-04 21:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04 21:59 [U-Boot] [PATCH v2 1/3] rsa: Fix build with OpenSSL 1.1.x Jelle van der Waa
2017-04-04 21:59 ` [U-Boot] [PATCH v2 2/3] rsa: Fix deprecated warnings for " Jelle van der Waa
2017-04-04 21:59 ` Jelle van der Waa [this message]
2017-04-05  9:34   ` [U-Boot] [PATCH v2 3/3] tools: kwbimage fix build with " Mario Six
2017-04-05  9:49 ` [U-Boot] [PATCH v2 1/3] rsa: Fix " Mario Six
2017-04-18 16:58   ` Peter Robinson
2017-04-19 14:27     ` Tom Rini

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=20170404215950.6588-3-jelle@vdwaa.nl \
    --to=jelle@vdwaa.nl \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.