summaryrefslogtreecommitdiffstats
path: root/crypto/rsa/rsa_ameth.c
diff options
context:
space:
mode:
authorPaul Yang <yang.yang@baishancloud.com>2017-08-02 02:19:43 +0800
committerPaul Yang <yang.yang@baishancloud.com>2017-11-21 14:38:42 +0800
commit665d899fa6d3571da016925067ebcf1789d7d19c (patch)
tree1674f352dc0feee9e68e6221d21c5d79bd1935ab /crypto/rsa/rsa_ameth.c
parentb0004708730f300a2e5c6a11c887caab50b6c42a (diff)
Support multi-prime RSA (RFC 8017)
* Introduce RSA_generate_multi_prime_key to generate multi-prime RSA private key. As well as the following functions: RSA_get_multi_prime_extra_count RSA_get0_multi_prime_factors RSA_get0_multi_prime_crt_params RSA_set0_multi_prime_params RSA_get_version * Support EVP operations for multi-prime RSA * Support ASN.1 operations for multi-prime RSA * Support multi-prime check in RSA_check_key_ex * Support multi-prime RSA in apps/genrsa and apps/speed * Support multi-prime RSA manipulation functions * Test cases and documentation are added * CHANGES is updated Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/4241)
Diffstat (limited to 'crypto/rsa/rsa_ameth.c')
-rw-r--r--crypto/rsa/rsa_ameth.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c
index 97a37ba47d..98121b5e64 100644
--- a/crypto/rsa/rsa_ameth.c
+++ b/crypto/rsa/rsa_ameth.c
@@ -316,10 +316,11 @@ static int pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
const RSA *x = pkey->pkey.rsa;
char *str;
const char *s;
- int ret = 0, mod_len = 0;
+ int ret = 0, mod_len = 0, ex_primes;
if (x->n != NULL)
mod_len = BN_num_bits(x->n);
+ ex_primes = sk_RSA_PRIME_INFO_num(x->prime_infos);
if (!BIO_indent(bp, off, 128))
goto err;
@@ -328,7 +329,8 @@ static int pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
goto err;
if (priv && x->d) {
- if (BIO_printf(bp, "Private-Key: (%d bit)\n", mod_len) <= 0)
+ if (BIO_printf(bp, "Private-Key: (%d bit, %d primes)\n",
+ mod_len, ex_primes <= 0 ? 2 : ex_primes + 2) <= 0)
goto err;
str = "modulus:";
s = "publicExponent:";
@@ -343,6 +345,8 @@ static int pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
if (!ASN1_bn_print(bp, s, x->e, NULL, off))
goto err;
if (priv) {
+ int i;
+
if (!ASN1_bn_print(bp, "privateExponent:", x->d, NULL, off))
goto err;
if (!ASN1_bn_print(bp, "prime1:", x->p, NULL, off))
@@ -355,6 +359,39 @@ static int pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
goto err;
if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, NULL, off))
goto err;
+ for (i = 0; i < sk_RSA_PRIME_INFO_num(x->prime_infos); i++) {
+ /* print multi-prime info */
+ BIGNUM *bn = NULL;
+ RSA_PRIME_INFO *pinfo;
+ int j;
+
+ pinfo = sk_RSA_PRIME_INFO_value(x->prime_infos, i);
+ for (j = 0; j < 3; j++) {
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+ switch (j) {
+ case 0:
+ if (BIO_printf(bp, "prime%d:", i + 3) <= 0)
+ goto err;
+ bn = pinfo->r;
+ break;
+ case 1:
+ if (BIO_printf(bp, "exponent%d:", i + 3) <= 0)
+ goto err;
+ bn = pinfo->d;
+ break;
+ case 2:
+ if (BIO_printf(bp, "coefficient%d:", i + 3) <= 0)
+ goto err;
+ bn = pinfo->t;
+ break;
+ default:
+ break;
+ }
+ if (!ASN1_bn_print(bp, "", bn, NULL, off))
+ goto err;
+ }
+ }
}
if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off))
goto err;