Latest update.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
$COMMON=rsa_ossl.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_pk1.c \
|
||||
$COMMON=rsa_ossl.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_aid.c rsa_pk1.c \
|
||||
rsa_none.c rsa_oaep.c rsa_chk.c rsa_pss.c rsa_x931.c rsa_crpt.c \
|
||||
rsa_x931g.c rsa_sp800_56b_gen.c rsa_sp800_56b_check.c
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/objects.h>
|
||||
#include "crypto/rsa.h"
|
||||
|
||||
#define ASN1_SEQUENCE 0x30
|
||||
#define ASN1_OID 0x06
|
||||
|
||||
/*
|
||||
* -- RFC 2313
|
||||
* pkcs-1 OBJECT IDENTIFIER ::= {
|
||||
* iso(1) member-body(2) US(840) rsadsi(113549) pkcs(1) 1
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* -- RFC 3279
|
||||
* md2WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 2 }
|
||||
* md5WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 }
|
||||
* sha1WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 5 }
|
||||
*/
|
||||
#define ENCODE_ALGORITHMIDENTIFIER_PKCS1(name, n) \
|
||||
static const unsigned char algorithmidentifier_##name##_der[] = { \
|
||||
ASN1_SEQUENCE, 0x0b, \
|
||||
ASN1_OID, 0x09, 1 * 40 + 2, 134, 72, 134, 247, 13, 1, 1, n \
|
||||
}
|
||||
#ifndef FIPS_MODE
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(md2, 2);
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(md5, 4);
|
||||
#endif
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(sha1, 5);
|
||||
|
||||
/*
|
||||
* -- RFC 4055
|
||||
* sha224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 14 }
|
||||
* sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 11 }
|
||||
* sha384WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 12 }
|
||||
* sha512WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 13 }
|
||||
*/
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(sha224, 14);
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(sha256, 11);
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(sha384, 12);
|
||||
ENCODE_ALGORITHMIDENTIFIER_PKCS1(sha512, 13);
|
||||
|
||||
/*
|
||||
* -- https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
||||
*
|
||||
* sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
|
||||
*
|
||||
* id-rsassa-pkcs1-v1_5-with-sha3-224 ::= { sigAlgs 13 }
|
||||
* id-rsassa-pkcs1-v1_5-with-sha3-256 ::= { sigAlgs 14 }
|
||||
* id-rsassa-pkcs1-v1_5-with-sha3-384 ::= { sigAlgs 15 }
|
||||
* id-rsassa-pkcs1-v1_5-with-sha3-512 ::= { sigAlgs 16 }
|
||||
*/
|
||||
#define ENCODE_ALGORITHMIDENTIFIER_SIGALGS(name, n) \
|
||||
static const unsigned char algorithmidentifier_##name##_der[] = { \
|
||||
ASN1_SEQUENCE, 0x0c, \
|
||||
ASN1_OID, 0x0a, 1 * 40 + 2, 16, 134, 72, 1, 101, 3, 4, 3, n \
|
||||
}
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_224, 13);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_256, 14);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_384, 15);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_512, 16);
|
||||
|
||||
#define MD_CASE(name) \
|
||||
case NID_##name: \
|
||||
*len = sizeof(algorithmidentifier_##name##_der); \
|
||||
return algorithmidentifier_##name##_der
|
||||
|
||||
const unsigned char *rsa_algorithmidentifier_encoding(int md_nid, size_t *len)
|
||||
{
|
||||
switch (md_nid) {
|
||||
#ifndef FIPS_MODE
|
||||
MD_CASE(md2);
|
||||
MD_CASE(md5);
|
||||
#endif
|
||||
MD_CASE(sha1);
|
||||
MD_CASE(sha224);
|
||||
MD_CASE(sha256);
|
||||
MD_CASE(sha384);
|
||||
MD_CASE(sha512);
|
||||
MD_CASE(sha3_224);
|
||||
MD_CASE(sha3_256);
|
||||
MD_CASE(sha3_384);
|
||||
MD_CASE(sha3_512);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -1114,7 +1114,13 @@ static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
|
||||
numexps = sk_BIGNUM_const_num(exps);
|
||||
numcoeffs = sk_BIGNUM_const_num(coeffs);
|
||||
|
||||
if (numprimes < 2 || numexps < 2 || numcoeffs < 1)
|
||||
/*
|
||||
* It's permisssible to have zero primes, i.e. no CRT params.
|
||||
* Otherwise, there must be at least two, as many exponents,
|
||||
* and one coefficient less.
|
||||
*/
|
||||
if (numprimes != 0
|
||||
&& (numprimes < 2 || numexps < 2 || numcoeffs < 1))
|
||||
goto err;
|
||||
|
||||
/* assert that an OSSL_PARAM_BLD has enough space. */
|
||||
|
||||
+87
-11
@@ -17,10 +17,12 @@
|
||||
#include <time.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/self_test.h>
|
||||
#include "rsa_local.h"
|
||||
|
||||
static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value,
|
||||
BN_GENCB *cb);
|
||||
static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg);
|
||||
static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
BIGNUM *e_value, BN_GENCB *cb, int pairwise_test);
|
||||
|
||||
/*
|
||||
* NB: this wrapper would normally be placed in rsa_lib.c and the static
|
||||
@@ -59,19 +61,21 @@ int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes,
|
||||
return 0;
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
return rsa_builtin_keygen(rsa, bits, primes, e_value, cb);
|
||||
return rsa_keygen(NULL, rsa, bits, primes, e_value, cb, 0);
|
||||
}
|
||||
|
||||
static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value,
|
||||
BN_GENCB *cb)
|
||||
static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
BIGNUM *e_value, BN_GENCB *cb, int pairwise_test)
|
||||
{
|
||||
int ok = -1;
|
||||
#ifdef FIPS_MODE
|
||||
if (primes != 2)
|
||||
return 0;
|
||||
return rsa_sp800_56b_generate_key(rsa, bits, e_value, cb);
|
||||
ok = rsa_sp800_56b_generate_key(rsa, bits, e_value, cb);
|
||||
pairwise_test = 1; /* FIPS MODE needs to always run the pairwise test */
|
||||
#else
|
||||
BIGNUM *r0 = NULL, *r1 = NULL, *r2 = NULL, *tmp, *prime;
|
||||
int ok = -1, n = 0, bitsr[RSA_MAX_PRIME_NUM], bitse = 0;
|
||||
int n = 0, bitsr[RSA_MAX_PRIME_NUM], bitse = 0;
|
||||
int i = 0, quo = 0, rmd = 0, adj = 0, retries = 0;
|
||||
RSA_PRIME_INFO *pinfo = NULL;
|
||||
STACK_OF(RSA_PRIME_INFO) *prime_infos = NULL;
|
||||
@@ -81,13 +85,13 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value,
|
||||
|
||||
if (bits < RSA_MIN_MODULUS_BITS) {
|
||||
ok = 0; /* we set our own err */
|
||||
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, RSA_R_KEY_SIZE_TOO_SMALL);
|
||||
RSAerr(0, RSA_R_KEY_SIZE_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (primes < RSA_DEFAULT_PRIME_NUM || primes > rsa_multip_cap(bits)) {
|
||||
ok = 0; /* we set our own err */
|
||||
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, RSA_R_KEY_PRIME_NUM_INVALID);
|
||||
RSAerr(0, RSA_R_KEY_PRIME_NUM_INVALID);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -392,11 +396,83 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value,
|
||||
ok = 1;
|
||||
err:
|
||||
if (ok == -1) {
|
||||
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
|
||||
RSAerr(0, ERR_LIB_BN);
|
||||
ok = 0;
|
||||
}
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ok;
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
if (pairwise_test && ok > 0) {
|
||||
OSSL_CALLBACK *stcb = NULL;
|
||||
void *stcbarg = NULL;
|
||||
|
||||
OSSL_SELF_TEST_get_callback(libctx, &stcb, &stcbarg);
|
||||
ok = rsa_keygen_pairwise_test(rsa, stcb, stcbarg);
|
||||
if (!ok) {
|
||||
/* Clear intermediate results */
|
||||
BN_clear_free(rsa->d);
|
||||
BN_clear_free(rsa->p);
|
||||
BN_clear_free(rsa->q);
|
||||
BN_clear_free(rsa->dmp1);
|
||||
BN_clear_free(rsa->dmq1);
|
||||
BN_clear_free(rsa->iqmp);
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* For RSA key generation it is not known whether the key pair will be used
|
||||
* for key transport or signatures. FIPS 140-2 IG 9.9 states that in this case
|
||||
* either a signature verification OR an encryption operation may be used to
|
||||
* perform the pairwise consistency check. The simpler encrypt/decrypt operation
|
||||
* has been chosen for this case.
|
||||
*/
|
||||
static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int ciphertxt_len;
|
||||
unsigned char *ciphertxt = NULL;
|
||||
const unsigned char plaintxt[16] = {0};
|
||||
unsigned char decoded[256];
|
||||
unsigned int decoded_len;
|
||||
unsigned int plaintxt_len = (unsigned int)sizeof(plaintxt_len);
|
||||
int padding = RSA_PKCS1_PADDING;
|
||||
OSSL_SELF_TEST *st = NULL;
|
||||
|
||||
st = OSSL_SELF_TEST_new(cb, cbarg);
|
||||
if (st == NULL)
|
||||
goto err;
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_PCT,
|
||||
OSSL_SELF_TEST_DESC_PCT_RSA_PKCS1);
|
||||
|
||||
ciphertxt_len = RSA_size(rsa);
|
||||
ciphertxt = OPENSSL_zalloc(ciphertxt_len);
|
||||
if (ciphertxt == NULL)
|
||||
goto err;
|
||||
|
||||
ciphertxt_len = RSA_public_encrypt(plaintxt_len, plaintxt, ciphertxt, rsa,
|
||||
padding);
|
||||
if (ciphertxt_len <= 0)
|
||||
goto err;
|
||||
if (ciphertxt_len == plaintxt_len
|
||||
&& memcmp(decoded, plaintxt, plaintxt_len) == 0)
|
||||
goto err;
|
||||
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, ciphertxt);
|
||||
|
||||
decoded_len = RSA_private_decrypt(ciphertxt_len, ciphertxt, decoded, rsa,
|
||||
padding);
|
||||
if (decoded_len != plaintxt_len
|
||||
|| memcmp(decoded, plaintxt, decoded_len) != 0)
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
OSSL_SELF_TEST_free(st);
|
||||
OPENSSL_free(ciphertxt);
|
||||
|
||||
return ret;
|
||||
}
|
||||
+94
-23
@@ -774,6 +774,10 @@ int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes,
|
||||
if (r == NULL)
|
||||
return 0;
|
||||
|
||||
/* If |p| is NULL, there are no CRT parameters */
|
||||
if (RSA_get0_p(r) == NULL)
|
||||
return 1;
|
||||
|
||||
sk_BIGNUM_const_push(primes, RSA_get0_p(r));
|
||||
sk_BIGNUM_const_push(primes, RSA_get0_q(r));
|
||||
sk_BIGNUM_const_push(exps, RSA_get0_dmp1(r));
|
||||
@@ -811,12 +815,14 @@ int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode)
|
||||
return -1;
|
||||
|
||||
/* TODO(3.0): Remove this eventually when no more legacy */
|
||||
if (!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
|| ctx->op.ciph.ciphprovctx == NULL)
|
||||
if ((!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
|| ctx->op.ciph.ciphprovctx == NULL)
|
||||
&& (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
|| ctx->op.sig.sigprovctx == NULL))
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_RSA_PADDING,
|
||||
pad_mode, NULL);
|
||||
|
||||
*p++ = OSSL_PARAM_construct_int(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, &pad_mode);
|
||||
*p++ = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_PAD_MODE, &pad_mode);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
return EVP_PKEY_CTX_set_params(ctx, pad_params);
|
||||
@@ -839,12 +845,14 @@ int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode)
|
||||
return -1;
|
||||
|
||||
/* TODO(3.0): Remove this eventually when no more legacy */
|
||||
if (!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
|| ctx->op.ciph.ciphprovctx == NULL)
|
||||
if ((!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
|
||||
|| ctx->op.ciph.ciphprovctx == NULL)
|
||||
&& (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
|| ctx->op.sig.sigprovctx == NULL))
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET_RSA_PADDING, 0,
|
||||
pad_mode);
|
||||
|
||||
*p++ = OSSL_PARAM_construct_int(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, pad_mode);
|
||||
*p++ = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_PAD_MODE, pad_mode);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
if (!EVP_PKEY_CTX_get_params(ctx, pad_params))
|
||||
@@ -1020,20 +1028,20 @@ int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname,
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
|
||||
return -1;
|
||||
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST,
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_MGF1_DIGEST,
|
||||
/*
|
||||
* Cast away the const. This is read
|
||||
* only so should be safe
|
||||
* Cast away the const. This is
|
||||
* read only so should be safe
|
||||
*/
|
||||
(char *)mdname, 0);
|
||||
if (mdprops != NULL) {
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(
|
||||
OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS,
|
||||
/*
|
||||
* Cast away the const. This is read
|
||||
* only so should be safe
|
||||
*/
|
||||
(char *)mdprops, 0);
|
||||
*p++ =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_MGF1_PROPERTIES,
|
||||
/*
|
||||
* Cast away the const. This is
|
||||
* read only so should be safe
|
||||
*/
|
||||
(char *)mdprops, 0);
|
||||
}
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
@@ -1059,7 +1067,7 @@ int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name,
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
|
||||
return -1;
|
||||
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST,
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_MGF1_DIGEST,
|
||||
name, namelen);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
@@ -1127,12 +1135,12 @@ int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int llen)
|
||||
(void *)label);
|
||||
|
||||
*p++ = OSSL_PARAM_construct_octet_string(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL,
|
||||
/*
|
||||
* Cast away the const. This is read
|
||||
* only so should be safe
|
||||
*/
|
||||
(void *)label,
|
||||
(size_t)llen);
|
||||
/*
|
||||
* Cast away the const. This is
|
||||
* read only so should be safe
|
||||
*/
|
||||
(void *)label,
|
||||
(size_t)llen);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
if (!EVP_PKEY_CTX_set_params(ctx, rsa_params))
|
||||
@@ -1177,4 +1185,67 @@ int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label)
|
||||
|
||||
return (int)labellen;
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen)
|
||||
{
|
||||
OSSL_PARAM pad_params[2], *p = pad_params;
|
||||
|
||||
if (ctx == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
/* Uses the same return values as EVP_PKEY_CTX_ctrl */
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* If key type not RSA or RSA-PSS return error */
|
||||
if (ctx->pmeth != NULL
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
|
||||
return -1;
|
||||
|
||||
/* TODO(3.0): Remove this eventually when no more legacy */
|
||||
if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
|| ctx->op.sig.sigprovctx == NULL)
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_RSA_PSS_SALTLEN,
|
||||
saltlen, NULL);
|
||||
|
||||
*p++ =
|
||||
OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, &saltlen);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
return EVP_PKEY_CTX_set_params(ctx, pad_params);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen)
|
||||
{
|
||||
OSSL_PARAM pad_params[2], *p = pad_params;
|
||||
|
||||
if (ctx == NULL || saltlen == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
/* Uses the same return values as EVP_PKEY_CTX_ctrl */
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* If key type not RSA or RSA-PSS return error */
|
||||
if (ctx->pmeth != NULL
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA
|
||||
&& ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
|
||||
return -1;
|
||||
|
||||
/* TODO(3.0): Remove this eventually when no more legacy */
|
||||
if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
|
||||
|| ctx->op.sig.sigprovctx == NULL)
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
|
||||
EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN,
|
||||
0, saltlen);
|
||||
|
||||
*p++ =
|
||||
OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, saltlen);
|
||||
*p++ = OSSL_PARAM_construct_end();
|
||||
|
||||
if (!EVP_PKEY_CTX_get_params(ctx, pad_params))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -122,10 +122,6 @@ struct rsa_meth_st {
|
||||
BIGNUM *e, BN_GENCB *cb);
|
||||
};
|
||||
|
||||
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,
|
||||
size_t siglen, RSA *rsa);
|
||||
/* Macros to test if a pkey or ctx is for a PSS key */
|
||||
#define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS)
|
||||
#define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/cms.h>
|
||||
#include "crypto/evp.h"
|
||||
#include "crypto/rsa.h"
|
||||
#include "rsa_local.h"
|
||||
|
||||
/* RSA pkey context structure */
|
||||
|
||||
+33
-7
@@ -17,13 +17,20 @@
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
# include <openssl/md2.h> /* uses MD2_DIGEST_LENGTH */
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_MD4
|
||||
# include <openssl/md4.h> /* uses MD4_DIGEST_LENGTH */
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
# include <openssl/md5.h> /* uses MD5_DIGEST_LENGTH */
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_MDC2
|
||||
# include <openssl/mdc2.h> /* uses MDC2_DIGEST_LENGTH */
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RMD160
|
||||
# include <openssl/ripemd.h> /* uses RIPEMD160_DIGEST_LENGTH */
|
||||
#endif
|
||||
#include <openssl/sha.h> /* uses SHA???_DIGEST_LENGTH */
|
||||
#include "crypto/rsa.h"
|
||||
#include "rsa_local.h"
|
||||
|
||||
/*
|
||||
@@ -70,7 +77,7 @@ static const unsigned char digestinfo_##name##_der[] = { \
|
||||
ASN1_OCTET_STRING, sz \
|
||||
};
|
||||
|
||||
/* MD2 and MD5 OIDs are of the form: (1 2 840 113549 2 |n|) */
|
||||
/* MD2, MD4 and MD5 OIDs are of the form: (1 2 840 113549 2 |n|) */
|
||||
#define ENCODE_DIGESTINFO_MD(name, n, sz) \
|
||||
static const unsigned char digestinfo_##name##_der[] = { \
|
||||
ASN1_SEQUENCE, 0x10 + sz, \
|
||||
@@ -84,6 +91,9 @@ static const unsigned char digestinfo_##name##_der[] = { \
|
||||
# ifndef OPENSSL_NO_MD2
|
||||
ENCODE_DIGESTINFO_MD(md2, 0x02, MD2_DIGEST_LENGTH)
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_MD4
|
||||
ENCODE_DIGESTINFO_MD(md4, 0x03, MD4_DIGEST_LENGTH)
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
ENCODE_DIGESTINFO_MD(md5, 0x05, MD5_DIGEST_LENGTH)
|
||||
# endif
|
||||
@@ -97,6 +107,18 @@ static const unsigned char digestinfo_mdc2_der[] = {
|
||||
ASN1_OCTET_STRING, MDC2_DIGEST_LENGTH
|
||||
};
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_RMD160
|
||||
/* RIPEMD160 (1 3 36 3 3 1 2) */
|
||||
static const unsigned char digestinfo_ripemd160_der[] = {
|
||||
ASN1_SEQUENCE, 0x0c + RIPEMD160_DIGEST_LENGTH,
|
||||
ASN1_SEQUENCE, 0x08,
|
||||
ASN1_OID, 0x04, 1 * 40 + 3, 36, 3, 3, 1, 2,
|
||||
ASN1_NULL, 0x00,
|
||||
ASN1_OCTET_STRING, RIPEMD160_DIGEST_LENGTH
|
||||
};
|
||||
# endif
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
/* SHA-1 (1 3 14 3 2 26) */
|
||||
static const unsigned char digestinfo_sha1_der[] = {
|
||||
ASN1_SEQUENCE, 0x0d + SHA_DIGEST_LENGTH,
|
||||
@@ -106,8 +128,6 @@ static const unsigned char digestinfo_sha1_der[] = {
|
||||
ASN1_OCTET_STRING, SHA_DIGEST_LENGTH
|
||||
};
|
||||
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
ENCODE_DIGESTINFO_SHA(sha256, 0x01, SHA256_DIGEST_LENGTH)
|
||||
ENCODE_DIGESTINFO_SHA(sha384, 0x02, SHA384_DIGEST_LENGTH)
|
||||
ENCODE_DIGESTINFO_SHA(sha512, 0x03, SHA512_DIGEST_LENGTH)
|
||||
@@ -124,9 +144,9 @@ ENCODE_DIGESTINFO_SHA(sha3_512, 0x0a, SHA512_DIGEST_LENGTH)
|
||||
*len = sizeof(digestinfo_##name##_der); \
|
||||
return digestinfo_##name##_der;
|
||||
|
||||
static const unsigned char *digestinfo_encoding(int nid, size_t *len)
|
||||
const unsigned char *rsa_digestinfo_encoding(int md_nid, size_t *len)
|
||||
{
|
||||
switch (nid) {
|
||||
switch (md_nid) {
|
||||
#ifndef FIPS_MODE
|
||||
# ifndef OPENSSL_NO_MDC2
|
||||
MD_CASE(mdc2)
|
||||
@@ -134,11 +154,17 @@ static const unsigned char *digestinfo_encoding(int nid, size_t *len)
|
||||
# ifndef OPENSSL_NO_MD2
|
||||
MD_CASE(md2)
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_MD4
|
||||
MD_CASE(md4)
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
MD_CASE(md5)
|
||||
# endif
|
||||
MD_CASE(sha1)
|
||||
# ifndef OPENSSL_NO_RMD160
|
||||
MD_CASE(ripemd160)
|
||||
# endif
|
||||
#endif /* FIPS_MODE */
|
||||
MD_CASE(sha1)
|
||||
MD_CASE(sha224)
|
||||
MD_CASE(sha256)
|
||||
MD_CASE(sha384)
|
||||
@@ -177,7 +203,7 @@ static int encode_pkcs1(unsigned char **out, size_t *out_len, int type,
|
||||
RSAerr(RSA_F_ENCODE_PKCS1, RSA_R_UNKNOWN_ALGORITHM_TYPE);
|
||||
return 0;
|
||||
}
|
||||
di_prefix = digestinfo_encoding(type, &di_prefix_len);
|
||||
di_prefix = rsa_digestinfo_encoding(type, &di_prefix_len);
|
||||
if (di_prefix == NULL) {
|
||||
RSAerr(RSA_F_ENCODE_PKCS1,
|
||||
RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
|
||||
|
||||
Reference in New Issue
Block a user