diff options
Diffstat (limited to 'utility')
-rw-r--r-- | utility/dumpRSAPublicKey.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/utility/dumpRSAPublicKey.c b/utility/dumpRSAPublicKey.c index 26724d6e..9e90003f 100644 --- a/utility/dumpRSAPublicKey.c +++ b/utility/dumpRSAPublicKey.c @@ -14,14 +14,20 @@ #include <string.h> #include <unistd.h> +#include "openssl_compat.h" + /* Command line tool to extract RSA public keys from X.509 certificates * and output a pre-processed version of keys for use by RSA verification * routines. */ int check(RSA* key) { - int public_exponent = BN_get_word(key->e); - int modulus = BN_num_bits(key->n); + const BIGNUM *n, *e; + int public_exponent, modulus; + + RSA_get0_key(key, &n, &e, NULL); + public_exponent = BN_get_word(e); + modulus = BN_num_bits(n); if (public_exponent != 3 && public_exponent != 65537) { fprintf(stderr, @@ -41,7 +47,8 @@ int check(RSA* key) { */ void output(RSA* key) { int i, nwords; - BIGNUM *N = key->n; + const BIGNUM *key_n; + BIGNUM *N = NULL; BIGNUM *Big1 = NULL, *Big2 = NULL, *Big32 = NULL, *BigMinus1 = NULL; BIGNUM *B = NULL; BIGNUM *N0inv= NULL, *R = NULL, *RR = NULL, *RRTemp = NULL, *NnumBits = NULL; @@ -49,14 +56,15 @@ void output(RSA* key) { BN_CTX *bn_ctx = BN_CTX_new(); uint32_t n0invout; - N = key->n; /* Output size of RSA key in 32-bit words */ - nwords = BN_num_bits(N) / 32; + nwords = RSA_size(key) / 4; if (-1 == write(1, &nwords, sizeof(nwords))) goto failure; /* Initialize BIGNUMs */ + RSA_get0_key(key, &key_n, NULL, NULL); + N = BN_dup(key_n); Big1 = BN_new(); Big2 = BN_new(); Big32 = BN_new(); @@ -121,6 +129,7 @@ void output(RSA* key) { failure: /* Free BIGNUMs. */ + BN_free(N); BN_free(Big1); BN_free(Big2); BN_free(Big32); |