Latest update (add quic)
This commit is contained in:
@@ -95,7 +95,7 @@ static int rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
static int rsa_pub_decode(EVP_PKEY *pkey, const X509_PUBKEY *pubkey)
|
||||
{
|
||||
const unsigned char *p;
|
||||
int pklen;
|
||||
@@ -1001,7 +1001,8 @@ static int rsa_cms_decrypt(CMS_RecipientInfo *ri)
|
||||
goto err;
|
||||
if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_CTX_set0_rsa_oaep_label(pkctx, label, labellen) <= 0)
|
||||
if (label != NULL
|
||||
&& EVP_PKEY_CTX_set0_rsa_oaep_label(pkctx, label, labellen) <= 0)
|
||||
goto err;
|
||||
/* Carry on */
|
||||
rv = 1;
|
||||
|
||||
+31
-9
@@ -64,16 +64,10 @@ int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes,
|
||||
return rsa_keygen(NULL, rsa, bits, primes, e_value, cb, 0);
|
||||
}
|
||||
|
||||
static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
BIGNUM *e_value, BN_GENCB *cb, int pairwise_test)
|
||||
#ifndef FIPS_MODULE
|
||||
static int rsa_multiprime_keygen(RSA *rsa, int bits, int primes,
|
||||
BIGNUM *e_value, BN_GENCB *cb)
|
||||
{
|
||||
int ok = -1;
|
||||
#ifdef FIPS_MODULE
|
||||
if (primes != 2)
|
||||
return 0;
|
||||
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 n = 0, bitsr[RSA_MAX_PRIME_NUM], bitse = 0;
|
||||
int i = 0, quo = 0, rmd = 0, adj = 0, retries = 0;
|
||||
@@ -82,6 +76,7 @@ static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
BN_CTX *ctx = NULL;
|
||||
BN_ULONG bitst = 0;
|
||||
unsigned long error = 0;
|
||||
int ok = -1;
|
||||
|
||||
if (bits < RSA_MIN_MODULUS_BITS) {
|
||||
ok = 0; /* we set our own err */
|
||||
@@ -89,6 +84,12 @@ static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* A bad value for e can cause infinite loops */
|
||||
if (e_value != NULL && !rsa_check_public_exponent(e_value)) {
|
||||
RSAerr(0, RSA_R_PUB_EXPONENT_OUT_OF_RANGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (primes < RSA_DEFAULT_PRIME_NUM || primes > rsa_multip_cap(bits)) {
|
||||
ok = 0; /* we set our own err */
|
||||
RSAerr(0, RSA_R_KEY_PRIME_NUM_INVALID);
|
||||
@@ -401,8 +402,29 @@ static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
}
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ok;
|
||||
}
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes,
|
||||
BIGNUM *e_value, BN_GENCB *cb, int pairwise_test)
|
||||
{
|
||||
int ok = 0;
|
||||
|
||||
/*
|
||||
* Only multi-prime keys or insecure keys with a small key length will use
|
||||
* the older rsa_multiprime_keygen().
|
||||
*/
|
||||
if (primes == 2 && bits >= 2048)
|
||||
ok = rsa_sp800_56b_generate_key(rsa, bits, e_value, cb);
|
||||
#ifndef FIPS_MODULE
|
||||
else
|
||||
ok = rsa_multiprime_keygen(rsa, bits, primes, e_value, cb);
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
#ifdef FIPS_MODULE
|
||||
pairwise_test = 1; /* FIPS MODE needs to always run the pairwise test */
|
||||
#endif
|
||||
if (pairwise_test && ok > 0) {
|
||||
OSSL_CALLBACK *stcb = NULL;
|
||||
void *stcbarg = NULL;
|
||||
|
||||
@@ -187,12 +187,5 @@ int rsa_padding_add_PKCS1_type_2_with_libctx(OPENSSL_CTX *libctx,
|
||||
unsigned char *to, int tlen,
|
||||
const unsigned char *from,
|
||||
int flen);
|
||||
int rsa_padding_add_PKCS1_OAEP_mgf1_with_libctx(OPENSSL_CTX *libctx,
|
||||
unsigned char *to, int tlen,
|
||||
const unsigned char *from,
|
||||
int flen,
|
||||
const unsigned char *param,
|
||||
int plen, const EVP_MD *md,
|
||||
const EVP_MD *mgf1md);
|
||||
|
||||
#endif /* OSSL_CRYPTO_RSA_LOCAL_H */
|
||||
@@ -61,13 +61,14 @@ int rsa_padding_add_PKCS1_OAEP_mgf1_with_libctx(OPENSSL_CTX *libctx,
|
||||
unsigned char seedmask[EVP_MAX_MD_SIZE];
|
||||
int mdlen, dbmask_len = 0;
|
||||
|
||||
if (md == NULL) {
|
||||
#ifndef FIPS_MODULE
|
||||
if (md == NULL)
|
||||
md = EVP_sha1();
|
||||
#else
|
||||
RSAerr(0, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
if (mgf1md == NULL)
|
||||
mgf1md = md;
|
||||
|
||||
|
||||
@@ -189,12 +189,30 @@ int rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
static int bn_is_three(const BIGNUM *bn)
|
||||
{
|
||||
BIGNUM *num = BN_dup(bn);
|
||||
int ret = (num != NULL && BN_sub_word(num, 3) && BN_is_zero(num));
|
||||
|
||||
BN_free(num);
|
||||
return ret;
|
||||
}
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
/* Check exponent is odd, and has a bitlen ranging from [17..256] */
|
||||
int rsa_check_public_exponent(const BIGNUM *e)
|
||||
{
|
||||
int bitlen = BN_num_bits(e);
|
||||
int bitlen;
|
||||
|
||||
return (BN_is_odd(e) && bitlen > 16 && bitlen < 257);
|
||||
/* For legacy purposes RSA_3 is allowed in non fips mode */
|
||||
#ifndef FIPS_MODULE
|
||||
if (bn_is_three(e))
|
||||
return 1;
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
bitlen = BN_num_bits(e);
|
||||
return (BN_is_odd(e) && bitlen > 16 && bitlen < 257);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -65,7 +65,7 @@ int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2,
|
||||
* Signature Generation and Key Agree/Transport.
|
||||
*/
|
||||
if (nbits < RSA_FIPS1864_MIN_KEYGEN_KEYSIZE) {
|
||||
RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_INVALID_KEY_LENGTH);
|
||||
RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_KEY_SIZE_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,12 +146,13 @@ err:
|
||||
int rsa_sp800_56b_validate_strength(int nbits, int strength)
|
||||
{
|
||||
int s = (int)ifc_ffc_compute_security_bits(nbits);
|
||||
|
||||
#ifdef FIPS_MODULE
|
||||
if (s < RSA_FIPS1864_MIN_KEYGEN_STRENGTH
|
||||
|| s > RSA_FIPS1864_MAX_KEYGEN_STRENGTH) {
|
||||
RSAerr(RSA_F_RSA_SP800_56B_VALIDATE_STRENGTH, RSA_R_INVALID_MODULUS);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (strength != -1 && s != strength) {
|
||||
RSAerr(RSA_F_RSA_SP800_56B_VALIDATE_STRENGTH, RSA_R_INVALID_STRENGTH);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user