-/* Generalized public key test routine. Signs and verifies the data
- * supplied in tbs using mesage digest md and setting RSA padding mode
- * pad_mode. If the 'kat' parameter is not NULL it will
- * additionally check the signature matches it: a known answer test
- * The string "fail_str" is used for identification purposes in case
- * of failure.
- */
-
-int fips_pkey_signature_test(EVP_PKEY *pkey,
- const unsigned char *tbs, int tbslen,
- const unsigned char *kat, unsigned int katlen,
- const EVP_MD *digest, int pad_mode,
- const char *fail_str)
- {
- int ret = 0;
- unsigned char sigtmp[256], *sig = sigtmp;
- unsigned int siglen;
- DSA_SIG *dsig = NULL;
- ECDSA_SIG *esig = NULL;
- EVP_MD_CTX mctx;
- FIPS_md_ctx_init(&mctx);
-
- if ((pkey->type == EVP_PKEY_RSA)
- && ((size_t)RSA_size(pkey->pkey.rsa) > sizeof(sigtmp)))
- {
- sig = OPENSSL_malloc(RSA_size(pkey->pkey.rsa));
- if (!sig)
- {
- FIPSerr(FIPS_F_FIPS_PKEY_SIGNATURE_TEST,ERR_R_MALLOC_FAILURE);
- return 0;
- }
- }
-
- if (tbslen == -1)
- tbslen = strlen((char *)tbs);
-
- if (digest == NULL)
- digest = EVP_sha256();
-
- if (!FIPS_digestinit(&mctx, digest))
- goto error;
- if (!FIPS_digestupdate(&mctx, tbs, tbslen))
- goto error;
- if (pkey->type == EVP_PKEY_RSA)
- {
- if (!FIPS_rsa_sign_ctx(pkey->pkey.rsa, &mctx,
- pad_mode, 0, NULL, sig, &siglen))
- goto error;
- }
- else if (pkey->type == EVP_PKEY_DSA)
- {
- dsig = FIPS_dsa_sign_ctx(pkey->pkey.dsa, &mctx);
- if (!dsig)
- goto error;
- }
- else if (pkey->type == EVP_PKEY_EC)
- {
- esig = FIPS_ecdsa_sign_ctx(pkey->pkey.ec, &mctx);
- if (!esig)
- goto error;
- }
-
- if (kat && ((siglen != katlen) || memcmp(kat, sig, katlen)))
- goto error;
-#if 0