mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
Fix the checks of EVP_PKEY_CTX_set/get_* functions
Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18399)
This commit is contained in:
parent
00d5193b68
commit
2cba2e160d
@ -217,16 +217,16 @@ int dhparam_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (dsaparam) {
|
||||
if (!EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num)) {
|
||||
if (EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num) <= 0) {
|
||||
BIO_printf(bio_err, "Error, unable to set DSA prime length\n");
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (!EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, num)) {
|
||||
if (EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, num) <= 0) {
|
||||
BIO_printf(bio_err, "Error, unable to set DH prime length\n");
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, g)) {
|
||||
if (EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, g) <= 0) {
|
||||
BIO_printf(bio_err, "Error, unable to set generator\n");
|
||||
goto end;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ int dsaparam_main(int argc, char **argv)
|
||||
"Error, DSA key generation paramgen init failed\n");
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num)) {
|
||||
if (EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num) <= 0) {
|
||||
BIO_printf(bio_err,
|
||||
"Error, DSA key generation setting bit length failed\n");
|
||||
goto end;
|
||||
|
@ -244,7 +244,7 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri)
|
||||
|
||||
/* See if custom parameters set */
|
||||
kdf_type = EVP_PKEY_CTX_get_dh_kdf_type(pctx);
|
||||
if (kdf_type <= 0 || !EVP_PKEY_CTX_get_dh_kdf_md(pctx, &kdf_md))
|
||||
if (kdf_type <= 0 || EVP_PKEY_CTX_get_dh_kdf_md(pctx, &kdf_md) <= 0)
|
||||
goto err;
|
||||
|
||||
if (kdf_type == EVP_PKEY_DH_KDF_NONE) {
|
||||
|
@ -289,7 +289,7 @@ static int ecdh_cms_encrypt(CMS_RecipientInfo *ri)
|
||||
kdf_type = EVP_PKEY_CTX_get_ecdh_kdf_type(pctx);
|
||||
if (kdf_type <= 0)
|
||||
goto err;
|
||||
if (!EVP_PKEY_CTX_get_ecdh_kdf_md(pctx, &kdf_md))
|
||||
if (EVP_PKEY_CTX_get_ecdh_kdf_md(pctx, &kdf_md) <= 0)
|
||||
goto err;
|
||||
ecdh_nid = EVP_PKEY_CTX_get_ecdh_cofactor_mode(pctx);
|
||||
if (ecdh_nid < 0)
|
||||
|
@ -1091,9 +1091,9 @@ static int rsa_keygen_test(int id)
|
||||
if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", NULL))
|
||||
|| !TEST_ptr(e_bn = BN_bin2bn(tst->e, tst->e_len, NULL))
|
||||
|| !TEST_int_gt(EVP_PKEY_keygen_init(ctx), 0)
|
||||
|| !TEST_true(EVP_PKEY_CTX_set_params(ctx, params))
|
||||
|| !TEST_true(EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, tst->mod))
|
||||
|| !TEST_true(EVP_PKEY_CTX_set1_rsa_keygen_pubexp(ctx, e_bn))
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set_params(ctx, params), 0)
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, tst->mod), 0)
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set1_rsa_keygen_pubexp(ctx, e_bn), 0)
|
||||
|| !TEST_int_gt(EVP_PKEY_keygen(ctx, &pkey), 0)
|
||||
|| !TEST_true(pkey_get_bn_bytes(pkey, OSSL_PKEY_PARAM_RSA_TEST_P1,
|
||||
&p1, &p1_len))
|
||||
|
@ -1760,7 +1760,7 @@ static int test_EC_keygen_with_enc(int idx)
|
||||
if (!TEST_ptr(pctx = EVP_PKEY_CTX_new_from_name(testctx, "EC", NULL))
|
||||
|| !TEST_int_gt(EVP_PKEY_paramgen_init(pctx), 0)
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set_group_name(pctx, "P-256"), 0)
|
||||
|| !TEST_true(EVP_PKEY_CTX_set_ec_param_enc(pctx, enc))
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set_ec_param_enc(pctx, enc), 0)
|
||||
|| !TEST_true(EVP_PKEY_paramgen(pctx, ¶ms))
|
||||
|| !TEST_ptr(params))
|
||||
goto done;
|
||||
@ -1897,7 +1897,7 @@ static int test_EVP_SM2(void)
|
||||
if (!TEST_true(EVP_PKEY_paramgen_init(pctx) == 1))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, NID_sm2)))
|
||||
if (!TEST_int_gt(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, NID_sm2), 0))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_paramgen(pctx, &pkeyparams)))
|
||||
@ -3325,7 +3325,7 @@ static int test_ecpub(int idx)
|
||||
ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
|
||||
if (!TEST_ptr(ctx)
|
||||
|| !TEST_int_gt(EVP_PKEY_keygen_init(ctx), 0)
|
||||
|| !TEST_true(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid))
|
||||
|| !TEST_int_gt(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid), 0)
|
||||
|| !TEST_true(EVP_PKEY_keygen(ctx, &pkey)))
|
||||
goto done;
|
||||
len = i2d_PublicKey(pkey, NULL);
|
||||
@ -3377,10 +3377,10 @@ static int test_EVP_rsa_pss_with_keygen_bits(void)
|
||||
|
||||
md = EVP_MD_fetch(testctx, "sha256", testpropq);
|
||||
ret = TEST_ptr(md)
|
||||
&& TEST_ptr((ctx = EVP_PKEY_CTX_new_from_name(testctx, "RSA", testpropq)))
|
||||
&& TEST_ptr((ctx = EVP_PKEY_CTX_new_from_name(testctx, "RSA-PSS", testpropq)))
|
||||
&& TEST_int_gt(EVP_PKEY_keygen_init(ctx), 0)
|
||||
&& TEST_int_gt(EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 512), 0)
|
||||
&& TEST_true(EVP_PKEY_CTX_set_rsa_pss_keygen_md(ctx, md))
|
||||
&& TEST_int_gt(EVP_PKEY_CTX_set_rsa_pss_keygen_md(ctx, md), 0)
|
||||
&& TEST_true(EVP_PKEY_keygen(ctx, &pkey));
|
||||
|
||||
EVP_MD_free(md);
|
||||
|
Loading…
Reference in New Issue
Block a user