diff options
author | Richard Levitte <levitte@openssl.org> | 2016-04-02 15:12:58 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2016-04-06 16:19:17 +0200 |
commit | 9862e9aa98ee1e38fbcef8d1dd5db0e750eb5e8d (patch) | |
tree | d7ddbd0b7d4c97875479e3b9cd52fdf579ca2434 /crypto/rsa | |
parent | 3e41ac35281827b59e55d51058cf6bb086c1f2b5 (diff) | |
download | openssl-9862e9aa98ee1e38fbcef8d1dd5db0e750eb5e8d.tar.gz |
Make the RSA structure opaque
Move rsa_st away from public headers.
Add accessor/writer functions for the public RSA data.
Adapt all other source to use the accessors and writers.
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'crypto/rsa')
-rw-r--r-- | crypto/rsa/rsa_ameth.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_asn1.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_chk.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_crpt.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_gen.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_lib.c | 95 | ||||
-rw-r--r-- | crypto/rsa/rsa_locl.h | 48 | ||||
-rw-r--r-- | crypto/rsa/rsa_oaep.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_ossl.c | 2 | ||||
-rw-r--r-- | crypto/rsa/rsa_x931g.c | 2 |
10 files changed, 150 insertions, 9 deletions
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index ad51a440e5..4ff2665d60 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -60,11 +60,11 @@ #include "internal/cryptlib.h" #include <openssl/asn1t.h> #include <openssl/x509.h> -#include <openssl/rsa.h> #include <openssl/bn.h> #include <openssl/cms.h> #include "internal/asn1_int.h" #include "internal/evp_int.h" +#include "rsa_locl.h" #ifndef OPENSSL_NO_CMS static int rsa_cms_sign(CMS_SignerInfo *si); diff --git a/crypto/rsa/rsa_asn1.c b/crypto/rsa/rsa_asn1.c index 86a71b7c6b..da8b2406dd 100644 --- a/crypto/rsa/rsa_asn1.c +++ b/crypto/rsa/rsa_asn1.c @@ -59,9 +59,9 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/rsa.h> #include <openssl/x509.h> #include <openssl/asn1t.h> +#include "rsa_locl.h" /* Override the default free and new methods */ static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, diff --git a/crypto/rsa/rsa_chk.c b/crypto/rsa/rsa_chk.c index 02d3c41340..f78050876c 100644 --- a/crypto/rsa/rsa_chk.c +++ b/crypto/rsa/rsa_chk.c @@ -49,7 +49,7 @@ #include <openssl/bn.h> #include <openssl/err.h> -#include <openssl/rsa.h> +#include "rsa_locl.h" int RSA_check_key(const RSA *key) { diff --git a/crypto/rsa/rsa_crpt.c b/crypto/rsa/rsa_crpt.c index cec4a7c2bd..6cc3c70ec3 100644 --- a/crypto/rsa/rsa_crpt.c +++ b/crypto/rsa/rsa_crpt.c @@ -60,8 +60,8 @@ #include "internal/cryptlib.h" #include <openssl/lhash.h> #include "internal/bn_int.h" -#include <openssl/rsa.h> #include <openssl/rand.h> +#include "rsa_locl.h" int RSA_bits(const RSA *r) { diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index 6ec27495e7..c4562589e1 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -65,7 +65,7 @@ #include <time.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/rsa.h> +#include "rsa_locl.h" static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb); diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index bd881ed528..7ee575d663 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -60,9 +60,9 @@ #include "internal/cryptlib.h" #include <openssl/lhash.h> #include "internal/bn_int.h" -#include <openssl/rsa.h> #include <openssl/rand.h> #include <openssl/engine.h> +#include "rsa_locl.h" static const RSA_METHOD *default_RSA_meth = NULL; @@ -283,3 +283,96 @@ int RSA_security_bits(const RSA *rsa) { return BN_security_bits(BN_num_bits(rsa->n), -1); } + +int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) +{ + /* d is the private component and may be NULL */ + if (n == NULL || e == NULL) + return 0; + + BN_free(r->n); + BN_free(r->e); + BN_free(r->d); + r->n = n; + r->e = e; + r->d = d; + + return 1; +} + +int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) +{ + if (p == NULL || q == NULL) + return 0; + + BN_free(r->p); + BN_free(r->q); + r->p = p; + r->q = q; + + return 1; +} + +int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) +{ + if (dmp1 == NULL || dmq1 == NULL || iqmp == NULL) + return 0; + + BN_free(r->dmp1); + BN_free(r->dmq1); + BN_free(r->iqmp); + r->dmp1 = dmp1; + r->dmq1 = dmq1; + r->iqmp = iqmp; + + return 1; +} + +void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d) +{ + if (n != NULL) + *n = r->n; + if (e != NULL) + *e = r->e; + if (d != NULL) + *d = r->d; +} + +void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q) +{ + if (p != NULL) + *p = r->p; + if (q != NULL) + *q = r->q; +} + +void RSA_get0_crt_params(const RSA *r, + BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp) +{ + if (dmp1 != NULL) + *dmp1 = r->dmp1; + if (dmq1 != NULL) + *dmq1 = r->dmq1; + if (iqmp != NULL) + *iqmp = r->iqmp; +} + +void RSA_clear_flags(RSA *r, int flags) +{ + r->flags &= ~flags; +} + +int RSA_test_flags(const RSA *r, int flags) +{ + return r->flags & flags; +} + +void RSA_set_flags(RSA *r, int flags) +{ + r->flags |= flags; +} + +ENGINE *RSA_get0_engine(RSA *r) +{ + return r->engine; +} diff --git a/crypto/rsa/rsa_locl.h b/crypto/rsa/rsa_locl.h index 3e88187d9b..dd9e70b6a8 100644 --- a/crypto/rsa/rsa_locl.h +++ b/crypto/rsa/rsa_locl.h @@ -1,3 +1,51 @@ +/* + * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL licenses, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.openssl.org/source/license.html + * or in the file LICENSE in the source distribution. + */ + +#include <openssl/rsa.h> + +struct rsa_st { + /* + * The first parameter is used to pickup errors where this is passed + * instead of aEVP_PKEY, it is set to 0 + */ + int pad; + long version; + const RSA_METHOD *meth; + /* functional reference if 'meth' is ENGINE-provided */ + ENGINE *engine; + BIGNUM *n; + BIGNUM *e; + BIGNUM *d; + BIGNUM *p; + BIGNUM *q; + BIGNUM *dmp1; + BIGNUM *dmq1; + BIGNUM *iqmp; + /* be careful using this if the RSA structure is shared */ + CRYPTO_EX_DATA ex_data; + int references; + int flags; + /* Used to cache montgomery values */ + BN_MONT_CTX *_method_mod_n; + BN_MONT_CTX *_method_mod_p; + BN_MONT_CTX *_method_mod_q; + /* + * all BIGNUM values are actually in the following data, if it is not + * NULL + */ + char *bignum_data; + BN_BLINDING *blinding; + BN_BLINDING *mt_blinding; + CRYPTO_RWLOCK *lock; +}; + extern int int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len, unsigned char *rm, size_t *prm_len, const unsigned char *sigbuf, diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index 355788423b..27a6e78823 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -21,10 +21,10 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/rsa.h> #include <openssl/evp.h> #include <openssl/rand.h> #include <openssl/sha.h> +#include "rsa_locl.h" int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, const unsigned char *from, int flen, diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c index 8d3383bfb0..5c3c0bf95e 100644 --- a/crypto/rsa/rsa_ossl.c +++ b/crypto/rsa/rsa_ossl.c @@ -110,8 +110,8 @@ #include "internal/cryptlib.h" #include "internal/bn_int.h" -#include <openssl/rsa.h> #include <openssl/rand.h> +#include "rsa_locl.h" #ifndef RSA_NULL diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c index d4c520c429..1e164e86e1 100644 --- a/crypto/rsa/rsa_x931g.c +++ b/crypto/rsa/rsa_x931g.c @@ -60,7 +60,7 @@ #include <time.h> #include <openssl/err.h> #include <openssl/bn.h> -#include <openssl/rsa.h> +#include "rsa_locl.h" /* X9.31 RSA key derivation and generation */ |