diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-11-19 16:54:39 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-11-23 15:28:30 +0100 |
commit | 776822e8ff6ef52d5638a99e6dbd9820c8228aba (patch) | |
tree | 949c4e555c082f58b3b1596279ad8966bc000d12 /test | |
parent | b029591606a36e825a8a7c71a5163f9ade4f7c43 (diff) |
Add test for EVP_PKEY_sign_init_ex with RSA PSS padding
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17080)
(cherry picked from commit 5321333520b95a4f355916923af6c24dd10ed5dc)
Diffstat (limited to 'test')
-rw-r--r-- | test/evp_extra_test2.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index d932b73dd7..5be8bb5a40 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -20,9 +20,7 @@ #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/provider.h> -#ifndef OPENSSL_NO_DEPRECATED_3_0 -# include <openssl/rsa.h> -#endif +#include <openssl/rsa.h> #include <openssl/core_names.h> #include "testutil.h" #include "internal/nelem.h" @@ -818,6 +816,43 @@ static int test_pkey_export(void) return ret; } +static int test_rsa_pss_sign(void) +{ + EVP_PKEY *pkey = NULL; + EVP_PKEY_CTX *pctx = NULL; + int ret = 0; + const unsigned char *pdata = keydata[0].kder; + const char *mdname = "SHA2-256"; + OSSL_PARAM sig_params[3]; + unsigned char mdbuf[256 / 8] = { 0 }; + int padding = RSA_PKCS1_PSS_PADDING; + unsigned char *sig = NULL; + size_t sig_len = 0; + + sig_params[0] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_PAD_MODE, + &padding); + sig_params[1] = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, + (char *)mdname, 0); + sig_params[2] = OSSL_PARAM_construct_end(); + + ret = TEST_ptr(pkey = d2i_AutoPrivateKey_ex(NULL, &pdata, keydata[0].size, + mainctx, NULL)) + && TEST_ptr(pctx = EVP_PKEY_CTX_new_from_pkey(mainctx, pkey, NULL)) + && TEST_int_gt(EVP_PKEY_sign_init_ex(pctx, sig_params), 0) + && TEST_int_gt(EVP_PKEY_sign(pctx, NULL, &sig_len, mdbuf, + sizeof(mdbuf)), 0) + && TEST_int_gt(sig_len, 0) + && TEST_ptr(sig = OPENSSL_malloc(sig_len)) + && TEST_int_gt(EVP_PKEY_sign(pctx, sig, &sig_len, mdbuf, + sizeof(mdbuf)), 0); + + EVP_PKEY_CTX_free(pctx); + OPENSSL_free(sig); + EVP_PKEY_free(pkey); + + return ret; +} + int setup_tests(void) { if (!test_get_libctx(&mainctx, &nullprov, NULL, NULL, NULL)) { @@ -843,6 +878,7 @@ int setup_tests(void) ADD_TEST(test_pkcs8key_nid_bio); #endif ADD_ALL_TESTS(test_PEM_read_bio_negative, OSSL_NELEM(keydata)); + ADD_TEST(test_rsa_pss_sign); return 1; } |