65 #ifndef OPENSSL_NO_CMS
72 unsigned char *penc = NULL;
74 penclen = i2d_RSAPublicKey(pkey->
pkey.
rsa, &penc);
87 const unsigned char *
p;
92 if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen)))
109 static int old_rsa_priv_decode(
EVP_PKEY *pkey,
110 const unsigned char **pder,
int derlen)
113 if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen)))
122 static int old_rsa_priv_encode(
const EVP_PKEY *pkey,
unsigned char **pder)
124 return i2d_RSAPrivateKey(pkey->
pkey.
rsa, pder);
129 unsigned char *rk = NULL;
131 rklen = i2d_RSAPrivateKey(pkey->
pkey.
rsa, &rk);
151 const unsigned char *
p;
155 return old_rsa_priv_decode(pkey, &p, pklen);
158 static int int_rsa_size(
const EVP_PKEY *pkey)
163 static int rsa_bits(
const EVP_PKEY *pkey)
168 static void int_rsa_free(
EVP_PKEY *pkey)
174 static void update_buflen(
const BIGNUM *b,
size_t *pbuflen)
183 static int do_rsa_print(
BIO *
bp,
const RSA *x,
int off,
int priv)
187 unsigned char *m=NULL;
188 int ret=0, mod_len = 0;
191 update_buflen(x->
n, &buf_len);
192 update_buflen(x->
e, &buf_len);
196 update_buflen(x->
d, &buf_len);
197 update_buflen(x->
p, &buf_len);
198 update_buflen(x->
q, &buf_len);
199 update_buflen(x->
dmp1, &buf_len);
200 update_buflen(x->
dmq1, &buf_len);
201 update_buflen(x->
iqmp, &buf_len);
219 if (
BIO_printf(bp,
"Private-Key: (%d bit)\n", mod_len)
222 s =
"publicExponent:";
226 if (
BIO_printf(bp,
"Public-Key: (%d bit)\n", mod_len)
255 static int rsa_pub_print(
BIO *bp,
const EVP_PKEY *pkey,
int indent,
258 return do_rsa_print(bp, pkey->
pkey.
rsa, indent, 0);
262 static int rsa_priv_print(
BIO *bp,
const EVP_PKEY *pkey,
int indent,
265 return do_rsa_print(bp, pkey->
pkey.
rsa, indent, 1);
271 const unsigned char *
p;
281 pss = d2i_RSA_PSS_PARAMS(NULL, &p, plen);
286 if (pss->maskGenAlgorithm)
288 ASN1_TYPE *param = pss->maskGenAlgorithm->parameter;
294 *pmaskHash = d2i_X509_ALGOR(NULL, &p, plen);
307 if (
BIO_puts(bp,
" (INVALID PSS PARAMETERS)\n") <= 0)
315 if (
BIO_puts(bp,
"Hash Algorithm: ") <= 0)
318 if (pss->hashAlgorithm)
323 else if (
BIO_puts(bp,
"sha1 (default)") <= 0)
332 if (
BIO_puts(bp,
"Mask Algorithm: ") <= 0)
334 if (pss->maskGenAlgorithm)
345 else if (
BIO_puts(bp,
"INVALID") <= 0)
348 else if (
BIO_puts(bp,
"mgf1 with sha1 (default)") <= 0)
354 if (
BIO_puts(bp,
"Salt Length: ") <= 0)
361 else if (
BIO_puts(bp,
"20 (default)") <= 0)
367 if (
BIO_puts(bp,
"Trailer Field: ") <= 0)
369 if (pss->trailerField)
374 else if (
BIO_puts(bp,
"0xbc (default)") <= 0)
394 pss = rsa_pss_decode(sigalg, &maskHash);
395 rv = rsa_pss_param_print(bp, pss, maskHash, indent);
397 RSA_PSS_PARAMS_free(pss);
399 X509_ALGOR_free(maskHash);
403 else if (!sig &&
BIO_puts(bp,
"\n") <= 0)
410 static int rsa_pkey_ctrl(
EVP_PKEY *pkey,
int op,
long arg1,
void *arg2)
425 #ifndef OPENSSL_NO_CMS
466 const EVP_MD *mgf1md = NULL, *md = NULL;
477 pss = rsa_pss_decode(sigalg, &maskHash);
485 if (pss->maskGenAlgorithm)
507 if (pss->hashAlgorithm)
561 RSA_PSS_PARAMS_free(pss);
563 X509_ALGOR_free(maskHash);
579 const EVP_MD *sigmd, *mgf1md;
592 else if (saltlen == -2)
598 pss = RSA_PSS_PARAMS_new();
603 pss->saltLength = ASN1_INTEGER_new();
604 if (!pss->saltLength)
611 pss->hashAlgorithm = X509_ALGOR_new();
612 if (!pss->hashAlgorithm)
620 mgf1alg = X509_ALGOR_new();
625 pss->maskGenAlgorithm = X509_ALGOR_new();
626 if (!pss->maskGenAlgorithm)
649 X509_ALGOR_free(mgf1alg);
651 RSA_PSS_PARAMS_free(pss);
668 "OpenSSL RSA method",