diff options
author | Roberto Hueso Gomez <roberto@robertohueso.org> | 2022-08-01 02:08:47 +0200 |
---|---|---|
committer | Nicola Tuveri <nic.tuv@gmail.com> | 2022-08-04 12:17:08 +0300 |
commit | d93f154d5a524e6ed71ff276447de7fe11d85949 (patch) | |
tree | fb62d821a97a142431ef21b88b4122045e12d4b8 /test/ec_internal_test.c | |
parent | b304b3e8f7397c3e949e3664e6ceaee5dc811b32 (diff) |
Add test for EC_KEY_set_private_key()
This tests the behavior and API of the EC_KEY_set_private_key function.
It tests compliance with legacy features related to NULL private keys
too.
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18942)
Diffstat (limited to 'test/ec_internal_test.c')
-rw-r--r-- | test/ec_internal_test.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ec_internal_test.c b/test/ec_internal_test.c index 57092942a1..5076f9894d 100644 --- a/test/ec_internal_test.c +++ b/test/ec_internal_test.c @@ -260,6 +260,39 @@ static int underflow_test(void) #endif /* + * Tests behavior of the EC_KEY_set_private_key + */ +static int set_private_key(void) +{ + EC_KEY *key = NULL, *aux_key = NULL; + int testresult = 0; + + key = EC_KEY_new_by_curve_name(NID_secp224r1); + aux_key = EC_KEY_new_by_curve_name(NID_secp224r1); + if (!TEST_ptr(key) + || !TEST_ptr(aux_key) + || !TEST_int_eq(EC_KEY_generate_key(key), 1) + || !TEST_int_eq(EC_KEY_generate_key(aux_key), 1)) + goto err; + + /* Test setting a valid private key */ + if (!TEST_int_eq(EC_KEY_set_private_key(key, aux_key->priv_key), 1)) + goto err; + + /* Test compliance with legacy behavior for NULL private keys */ + if (!TEST_int_eq(EC_KEY_set_private_key(key, NULL), 0) + || !TEST_ptr_null(key->priv_key)) + goto err; + + testresult = 1; + + err: + EC_KEY_free(key); + EC_KEY_free(aux_key); + return testresult; +} + +/* * Tests behavior of the decoded_from_explicit_params flag and API */ static int decoded_flag_test(void) @@ -416,6 +449,7 @@ int setup_tests(void) #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 ADD_TEST(underflow_test); #endif + ADD_TEST(set_private_key); ADD_TEST(decoded_flag_test); ADD_ALL_TESTS(ecpkparams_i2d2i_test, crv_len); |