From: Matt Caswell Date: Tue, 3 Feb 2026 15:26:19 +0000 (+0000) Subject: Extend the tests we have for low level RSA/DSA methods to cover EC X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2854cea108215f98c37626866c5a9c15b67b7f69;p=thirdparty%2Fopenssl.git Extend the tests we have for low level RSA/DSA methods to cover EC We want to test that if we use a custom EC_KEY_METHOD, then it still works even when we use a provider. Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz MergeDate: Fri Feb 13 07:58:17 2026 (Merged from https://github.com/openssl/openssl/pull/29960) --- diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 0082da1006d..d51d46d4c79 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -6440,6 +6440,72 @@ err: } #endif +#ifndef OPENSSL_NO_EC +static int (*orig_ec_sign)(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey); +static int (*orig_ec_sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, + BIGNUM **kinvp, BIGNUM **rp); +static ECDSA_SIG *(*orig_ec_sign_sig)(const unsigned char *dgst, + int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey); +static int tst_ec_sign(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey) +{ + sign_hits++; + return orig_ec_sign(type, dgst, dlen, sig, siglen, kinv, r, eckey); +} + +/* Test that a low level EC_KEY method still gets used even with a provider */ +static int test_low_level_ec_method(void) +{ + EC_KEY *ec = NULL; + const EC_KEY_METHOD *def = EC_KEY_get_default_method(); + EC_KEY_METHOD *method = EC_KEY_METHOD_new(def); + EVP_PKEY *pkey = NULL; + int testresult = 0; + + if (nullprov != NULL) { + testresult = TEST_skip("Test does not support a non-default library context"); + goto err; + } + + if (!TEST_ptr(method)) + goto err; + + if (!TEST_ptr(ec = EC_KEY_new_by_curve_name_ex(NULL, NULL, NID_X9_62_prime256v1))) + goto err; + if (!TEST_true(EC_KEY_generate_key(ec))) + goto err; + + EC_KEY_METHOD_get_sign(def, &orig_ec_sign, &orig_ec_sign_setup, &orig_ec_sign_sig); + EC_KEY_METHOD_set_sign(method, tst_ec_sign, orig_ec_sign_setup, orig_ec_sign_sig); + if (!TEST_true(EC_KEY_set_method(ec, method))) + goto err; + + pkey = EVP_PKEY_new(); + if (!TEST_ptr(pkey)) + goto err; + if (!TEST_int_gt(EVP_PKEY_assign_EC_KEY(pkey, ec), 0)) + goto err; + ec = NULL; + + if (!do_sign_with_method(pkey)) + goto err; + + testresult = 1; +err: + EC_KEY_free(ec); + EVP_PKEY_free(pkey); + EC_KEY_METHOD_free(method); + return testresult; +} +#endif + int setup_tests(void) { char *config_file = NULL; @@ -6616,6 +6682,9 @@ int setup_tests(void) #ifndef OPENSSL_NO_DSA ADD_TEST(test_low_level_dsa_method); #endif +#ifndef OPENSSL_NO_EC + ADD_TEST(test_low_level_ec_method); +#endif return 1; }