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:15:43 +0100 |
commit | 5321333520b95a4f355916923af6c24dd10ed5dc (patch) | |
tree | ec3b4f3ee349527cf0213185518c2a88f51b685d /test | |
parent | eaae5d69eb5a8cd9c054b23cc388397cbb4ffb98 (diff) | |
download | openssl-5321333520b95a4f355916923af6c24dd10ed5dc.tar.gz |
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)
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; } |