1 From 65030804dc57f3488e4ffe21e72fc65cd245cb98 Mon Sep 17 00:00:00 2001
2 From: Jelle van der Waa <jelle@vdwaa.nl>
3 Date: Mon, 8 May 2017 21:31:20 +0200
4 Subject: [PATCH 2/2] tools: kwbimage fix build with OpenSSL 1.1.x
6 The rsa_st struct has been made opaque in 1.1.x, add forward compatible
7 code to access the n, e, d members of rsa_struct.
9 EVP_MD_CTX_cleanup has been removed in 1.1.x and EVP_MD_CTX_reset should be
10 called to reinitialise an already created structure.
12 Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
14 tools/kwbimage.c | 36 ++++++++++++++++++++++++++++++------
15 1 file changed, 30 insertions(+), 6 deletions(-)
17 --- a/tools/kwbimage.c
18 +++ b/tools/kwbimage.c
22 #ifdef CONFIG_KWB_SECURE
23 +#include <openssl/bn.h>
24 #include <openssl/rsa.h>
25 #include <openssl/pem.h>
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
29 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
30 +static void RSA_get0_key(const RSA *r,
31 + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
42 +void EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
44 + EVP_MD_CTX_reset(ctx);
49 static struct image_cfg_element *image_cfg;
50 @@ -470,12 +490,16 @@ static int kwb_export_pubkey(RSA *key, s
53 int size_exp, size_mod, size_seq;
54 + const BIGNUM *key_e, *key_n;
56 char *errmsg = "Failed to encode %s\n";
58 - if (!key || !key->e || !key->n || !dst) {
59 + RSA_get0_key(key, NULL, &key_e, NULL);
60 + RSA_get0_key(key, &key_n, NULL, NULL);
62 + if (!key || !key_e || !key_n || !dst) {
63 fprintf(stderr, "export pk failed: (%p, %p, %p, %p)",
64 - key, key->e, key->n, dst);
65 + key, key_e, key_n, dst);
66 fprintf(stderr, errmsg, keyname);
69 @@ -490,8 +514,8 @@ static int kwb_export_pubkey(RSA *key, s
70 * do the encoding manually.
73 - size_exp = BN_num_bytes(key->e);
74 - size_mod = BN_num_bytes(key->n);
75 + size_exp = BN_num_bytes(key_e);
76 + size_mod = BN_num_bytes(key_n);
77 size_seq = 4 + size_mod + 4 + size_exp;
80 @@ -520,14 +544,14 @@ static int kwb_export_pubkey(RSA *key, s
82 *cur++ = (size_mod >> 8) & 0xFF;
83 *cur++ = size_mod & 0xFF;
84 - BN_bn2bin(key->n, cur);
85 + BN_bn2bin(key_n, cur);
88 *cur++ = 0x02; /* INTEGER */
90 *cur++ = (size_exp >> 8) & 0xFF;
91 *cur++ = size_exp & 0xFF;
92 - BN_bn2bin(key->e, cur);
93 + BN_bn2bin(key_e, cur);
96 struct hash_v1 pk_hash;