35 #ifdef HAVE_XKEY_PROVIDER
37 #include <openssl/core_names.h>
38 #include <openssl/evp.h>
43 static const char *test_msg =
"Lorem ipsum dolor sit amet, consectetur "
44 "adipisici elit, sed eiusmod tempor incidunt "
45 "ut labore et dolore magna aliqua.";
60 OSSL_PARAM params[2] = {OSSL_PARAM_END};
61 const char *mdname =
"SHA256";
63 if (EVP_PKEY_get_id(privkey) == EVP_PKEY_RSA)
65 const char *padmode =
"pss";
66 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,
68 params[1] = OSSL_PARAM_construct_end();
70 else if (EVP_PKEY_get_id(privkey) == EVP_PKEY_EC)
72 params[0] = OSSL_PARAM_construct_end();
76 print_error(
"Unknown key type in digest_sign_verify()");
80 EVP_PKEY_CTX *pctx = NULL;
81 EVP_MD_CTX *mctx = EVP_MD_CTX_new();
84 || EVP_DigestSignInit_ex(mctx, &pctx, mdname,
tls_libctx, NULL, privkey, params) <= 0)
88 print_error(
"Failed to initialize EVP_DigestSignInit_ex()\n");
93 if (EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)) != 1)
95 print_error(
"EVP_DigestSign: failed to get required signature size");
98 assert_true(siglen > 0);
100 if ((sig = test_calloc(1, siglen)) == NULL)
102 print_error(
"Out of memory");
105 if (EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)) != 1)
107 print_error(
"EVP_DigestSign: signing failed");
115 EVP_MD_CTX_free(mctx);
116 mctx = EVP_MD_CTX_new();
119 || EVP_DigestVerifyInit_ex(mctx, &pctx, mdname,
tls_libctx, NULL, pubkey, params) <= 0)
121 print_error(
"Failed to initialize EVP_DigestVerifyInit_ex()");
124 if (EVP_DigestVerify(mctx, sig, siglen, (uint8_t *)test_msg, strlen(test_msg)) != 1)
126 print_error(
"EVP_DigestVerify failed");
134 EVP_MD_CTX_free(mctx);