Latest update.
This commit is contained in:
@@ -458,6 +458,9 @@ static int rsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
|
||||
static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
{
|
||||
X509_ALGOR *alg = NULL;
|
||||
const EVP_MD *md;
|
||||
const EVP_MD *mgf1md;
|
||||
int min_saltlen;
|
||||
|
||||
switch (op) {
|
||||
|
||||
@@ -497,6 +500,16 @@ static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
#endif
|
||||
|
||||
case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
|
||||
if (pkey->pkey.rsa->pss != NULL) {
|
||||
if (!rsa_pss_get_param(pkey->pkey.rsa->pss, &md, &mgf1md,
|
||||
&min_saltlen)) {
|
||||
RSAerr(0, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
*(int *)arg2 = EVP_MD_type(md);
|
||||
/* Return of 2 indicates this MD is mandatory */
|
||||
return 2;
|
||||
}
|
||||
*(int *)arg2 = NID_sha256;
|
||||
return 1;
|
||||
|
||||
|
||||
+3
-106
@@ -13,109 +13,6 @@
|
||||
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
static const ERR_STRING_DATA RSA_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_CHECK_PADDING_MD, 0), "check_padding_md"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_ENCODE_PKCS1, 0), "encode_pkcs1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_INT_RSA_VERIFY, 0), "int_rsa_verify"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_OLD_RSA_PRIV_DECODE, 0),
|
||||
"old_rsa_priv_decode"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_PSS_INIT, 0), "pkey_pss_init"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_CTRL, 0), "pkey_rsa_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_CTRL_STR, 0), "pkey_rsa_ctrl_str"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_SIGN, 0), "pkey_rsa_sign"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_VERIFY, 0), "pkey_rsa_verify"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_VERIFYRECOVER, 0),
|
||||
"pkey_rsa_verifyrecover"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_ALGOR_TO_MD, 0), "rsa_algor_to_md"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_BUILTIN_KEYGEN, 0), "rsa_builtin_keygen"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_CHECK_KEY, 0), "RSA_check_key"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_CHECK_KEY_EX, 0), "RSA_check_key_ex"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_CMS_DECRYPT, 0), "rsa_cms_decrypt"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_CMS_VERIFY, 0), "rsa_cms_verify"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, 0),
|
||||
"rsa_fips186_4_gen_prob_primes"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_ITEM_VERIFY, 0), "rsa_item_verify"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_METH_DUP, 0), "RSA_meth_dup"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_METH_NEW, 0), "RSA_meth_new"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_METH_SET1_NAME, 0), "RSA_meth_set1_name"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_MGF1_TO_MD, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_MULTIP_INFO_NEW, 0),
|
||||
"rsa_multip_info_new"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NEW_METHOD, 0), "RSA_new_method"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NULL, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NULL_PRIVATE_DECRYPT, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NULL_PRIVATE_ENCRYPT, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NULL_PUBLIC_DECRYPT, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_NULL_PUBLIC_ENCRYPT, 0), ""},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_OSSL_PRIVATE_DECRYPT, 0),
|
||||
"rsa_ossl_private_decrypt"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, 0),
|
||||
"rsa_ossl_private_encrypt"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_OSSL_PUBLIC_DECRYPT, 0),
|
||||
"rsa_ossl_public_decrypt"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, 0),
|
||||
"rsa_ossl_public_encrypt"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_NONE, 0),
|
||||
"RSA_padding_add_none"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, 0),
|
||||
"RSA_padding_add_PKCS1_OAEP"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1, 0),
|
||||
"RSA_padding_add_PKCS1_OAEP_mgf1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_PSS, 0),
|
||||
"RSA_padding_add_PKCS1_PSS"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1, 0),
|
||||
"RSA_padding_add_PKCS1_PSS_mgf1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1, 0),
|
||||
"RSA_padding_add_PKCS1_type_1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2, 0),
|
||||
"RSA_padding_add_PKCS1_type_2"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_SSLV23, 0),
|
||||
"RSA_padding_add_SSLv23"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_ADD_X931, 0),
|
||||
"RSA_padding_add_X931"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_NONE, 0),
|
||||
"RSA_padding_check_none"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, 0),
|
||||
"RSA_padding_check_PKCS1_OAEP"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1, 0),
|
||||
"RSA_padding_check_PKCS1_OAEP_mgf1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 0),
|
||||
"RSA_padding_check_PKCS1_type_1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, 0),
|
||||
"RSA_padding_check_PKCS1_type_2"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_SSLV23, 0),
|
||||
"RSA_padding_check_SSLv23"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PADDING_CHECK_X931, 0),
|
||||
"RSA_padding_check_X931"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PARAM_DECODE, 0), "rsa_param_decode"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PRINT, 0), "RSA_print"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PRINT_FP, 0), "RSA_print_fp"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PRIV_DECODE, 0), "rsa_priv_decode"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PRIV_ENCODE, 0), "rsa_priv_encode"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PSS_GET_PARAM, 0), "rsa_pss_get_param"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PSS_TO_CTX, 0), "rsa_pss_to_ctx"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_PUB_DECODE, 0), "rsa_pub_decode"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SETUP_BLINDING, 0), "RSA_setup_blinding"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SIGN, 0), "RSA_sign"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SIGN_ASN1_OCTET_STRING, 0),
|
||||
"RSA_sign_ASN1_OCTET_STRING"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, 0),
|
||||
"rsa_sp800_56b_check_keypair"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SP800_56B_CHECK_PUBLIC, 0),
|
||||
"rsa_sp800_56b_check_public"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SP800_56B_PAIRWISE_TEST, 0),
|
||||
"rsa_sp800_56b_pairwise_test"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_SP800_56B_VALIDATE_STRENGTH, 0),
|
||||
"rsa_sp800_56b_validate_strength"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_VERIFY, 0), "RSA_verify"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, 0),
|
||||
"RSA_verify_ASN1_OCTET_STRING"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 0),
|
||||
"RSA_verify_PKCS1_PSS_mgf1"},
|
||||
{ERR_PACK(ERR_LIB_RSA, RSA_F_SETUP_TBUF, 0), "setup_tbuf"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static const ERR_STRING_DATA RSA_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_ALGORITHM_MISMATCH), "algorithm mismatch"},
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_BAD_E_VALUE), "bad e value"},
|
||||
@@ -189,6 +86,8 @@ static const ERR_STRING_DATA RSA_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_LAST_OCTET_INVALID), "last octet invalid"},
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_MGF1_DIGEST_NOT_ALLOWED),
|
||||
"mgf1 digest not allowed"},
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_MISSING_PRIVATE_KEY),
|
||||
"missing private key"},
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_MODULUS_TOO_LARGE), "modulus too large"},
|
||||
{ERR_PACK(ERR_LIB_RSA, 0, RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R),
|
||||
"mp coefficient not inverse of r"},
|
||||
@@ -256,10 +155,8 @@ static const ERR_STRING_DATA RSA_str_reasons[] = {
|
||||
int ERR_load_RSA_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
if (ERR_func_error_string(RSA_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings_const(RSA_str_functs);
|
||||
if (ERR_reason_error_string(RSA_str_reasons[0].error) == NULL)
|
||||
ERR_load_strings_const(RSA_str_reasons);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
+12
-3
@@ -325,6 +325,7 @@ int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
|
||||
if (d != NULL) {
|
||||
BN_clear_free(r->d);
|
||||
r->d = d;
|
||||
BN_set_flags(r->d, BN_FLG_CONSTTIME);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -342,10 +343,12 @@ int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
|
||||
if (p != NULL) {
|
||||
BN_clear_free(r->p);
|
||||
r->p = p;
|
||||
BN_set_flags(r->p, BN_FLG_CONSTTIME);
|
||||
}
|
||||
if (q != NULL) {
|
||||
BN_clear_free(r->q);
|
||||
r->q = q;
|
||||
BN_set_flags(r->q, BN_FLG_CONSTTIME);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -364,14 +367,17 @@ int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
|
||||
if (dmp1 != NULL) {
|
||||
BN_clear_free(r->dmp1);
|
||||
r->dmp1 = dmp1;
|
||||
BN_set_flags(r->dmp1, BN_FLG_CONSTTIME);
|
||||
}
|
||||
if (dmq1 != NULL) {
|
||||
BN_clear_free(r->dmq1);
|
||||
r->dmq1 = dmq1;
|
||||
BN_set_flags(r->dmq1, BN_FLG_CONSTTIME);
|
||||
}
|
||||
if (iqmp != NULL) {
|
||||
BN_clear_free(r->iqmp);
|
||||
r->iqmp = iqmp;
|
||||
BN_set_flags(r->iqmp, BN_FLG_CONSTTIME);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -403,12 +409,15 @@ int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[],
|
||||
if (pinfo == NULL)
|
||||
goto err;
|
||||
if (primes[i] != NULL && exps[i] != NULL && coeffs[i] != NULL) {
|
||||
BN_free(pinfo->r);
|
||||
BN_free(pinfo->d);
|
||||
BN_free(pinfo->t);
|
||||
BN_clear_free(pinfo->r);
|
||||
BN_clear_free(pinfo->d);
|
||||
BN_clear_free(pinfo->t);
|
||||
pinfo->r = primes[i];
|
||||
pinfo->d = exps[i];
|
||||
pinfo->t = coeffs[i];
|
||||
BN_set_flags(pinfo->r, BN_FLG_CONSTTIME);
|
||||
BN_set_flags(pinfo->d, BN_FLG_CONSTTIME);
|
||||
BN_set_flags(pinfo->t, BN_FLG_CONSTTIME);
|
||||
} else {
|
||||
rsa_multip_info_free(pinfo);
|
||||
goto err;
|
||||
|
||||
@@ -321,6 +321,11 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (rsa->d == NULL) {
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, RSA_R_MISSING_PRIVATE_KEY);
|
||||
BN_free(d);
|
||||
goto err;
|
||||
}
|
||||
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
|
||||
|
||||
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
|
||||
@@ -438,6 +443,11 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (rsa->d == NULL) {
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_MISSING_PRIVATE_KEY);
|
||||
BN_free(d);
|
||||
goto err;
|
||||
}
|
||||
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
|
||||
|
||||
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
|
||||
@@ -460,6 +470,8 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
goto err;
|
||||
|
||||
j = BN_bn2binpad(ret, buf, num);
|
||||
if (j < 0)
|
||||
goto err;
|
||||
|
||||
switch (padding) {
|
||||
case RSA_PKCS1_PADDING:
|
||||
@@ -559,6 +571,8 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,
|
||||
goto err;
|
||||
|
||||
i = BN_bn2binpad(ret, buf, num);
|
||||
if (i < 0)
|
||||
goto err;
|
||||
|
||||
switch (padding) {
|
||||
case RSA_PKCS1_PADDING:
|
||||
|
||||
Reference in New Issue
Block a user