mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
Add FIPS self test updates
After reviewing the FIPS 140-3 IG self tests requirements the following were added: - TDES Decryption (Not sure why this was missing) - DH changed to use ffdhe2048 instead of P,Q,G params. - Signature code has been changed to use a msg rather than a digest as input. (Since some digests dont provide the one shot API, the EVP_DigestSignFinal and EVP_DigestVerifyFinal needed to be exposed to the FIPS provider). The code is now shared between ED and the other key types. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/25217)
This commit is contained in:
parent
e113a92e29
commit
96de408228
@ -493,11 +493,13 @@ int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen)
|
||||
{
|
||||
int sctx = 0, r = 0;
|
||||
#ifndef FIPS_MODULE
|
||||
int sctx = 0;
|
||||
#endif
|
||||
int r = 0;
|
||||
EVP_PKEY_CTX *dctx = NULL, *pctx = ctx->pctx;
|
||||
|
||||
if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISED) != 0) {
|
||||
@ -511,12 +513,14 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
if (sigret != NULL && (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) == 0) {
|
||||
/* try dup */
|
||||
dctx = EVP_PKEY_CTX_dup(pctx);
|
||||
if (dctx != NULL)
|
||||
pctx = dctx;
|
||||
}
|
||||
#endif
|
||||
r = pctx->op.sig.signature->digest_sign_final(pctx->op.sig.algctx,
|
||||
sigret, siglen,
|
||||
sigret == NULL ? 0 : *siglen);
|
||||
@ -527,6 +531,10 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
return r;
|
||||
|
||||
legacy:
|
||||
#ifdef FIPS_MODULE
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR);
|
||||
return 0;
|
||||
#else
|
||||
if (pctx == NULL || pctx->pmeth == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
@ -598,8 +606,8 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
@ -640,13 +648,14 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen,
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
size_t siglen)
|
||||
{
|
||||
#ifndef FIPS_MODULE
|
||||
int vctx = 0;
|
||||
unsigned int mdlen = 0;
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
#endif
|
||||
int r = 0;
|
||||
EVP_PKEY_CTX *dctx = NULL, *pctx = ctx->pctx;
|
||||
|
||||
@ -661,12 +670,14 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISE) == 0) {
|
||||
/* try dup */
|
||||
dctx = EVP_PKEY_CTX_dup(pctx);
|
||||
if (dctx != NULL)
|
||||
pctx = dctx;
|
||||
}
|
||||
#endif
|
||||
r = pctx->op.sig.signature->digest_verify_final(pctx->op.sig.algctx,
|
||||
sig, siglen);
|
||||
if (dctx == NULL)
|
||||
@ -676,6 +687,10 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
return r;
|
||||
|
||||
legacy:
|
||||
#ifdef FIPS_MODULE
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR);
|
||||
return 0;
|
||||
#else
|
||||
if (pctx == NULL || pctx->pmeth == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
@ -715,8 +730,8 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
if (vctx || !r)
|
||||
return r;
|
||||
return EVP_PKEY_verify(pctx, sig, siglen, md, mdlen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
|
||||
size_t siglen, const unsigned char *tbs, size_t tbslen)
|
||||
|
@ -45,7 +45,9 @@ typedef struct st_kat_st {
|
||||
#define CIPHER_MODE_ALL (CIPHER_MODE_ENCRYPT | CIPHER_MODE_DECRYPT)
|
||||
|
||||
/* FIPS 140-3 only allows DSA verification for legacy purposes */
|
||||
#define ST_PARAM_VERIFY_ONLY "verify_only"
|
||||
#define SIGNATURE_MODE_VERIFY_ONLY 1
|
||||
#define SIGNATURE_MODE_SIGN_ONLY 2
|
||||
#define SIGNATURE_MODE_ONESHOT 4
|
||||
|
||||
typedef ST_KAT ST_KAT_DIGEST;
|
||||
typedef struct st_kat_cipher_st {
|
||||
@ -108,7 +110,10 @@ typedef struct st_kat_sign_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
const char *mdalgorithm;
|
||||
int mode;
|
||||
const ST_KAT_PARAM *key;
|
||||
const unsigned char *msg;
|
||||
size_t msg_len;
|
||||
const unsigned char *entropy;
|
||||
size_t entropy_len;
|
||||
const unsigned char *nonce;
|
||||
@ -117,7 +122,6 @@ typedef struct st_kat_sign_st {
|
||||
size_t persstr_len;
|
||||
const unsigned char *sig_expected; /* Set to NULL if this value changes */
|
||||
size_t sig_expected_len;
|
||||
int oneshot;
|
||||
const ST_KAT_PARAM *init;
|
||||
} ST_KAT_SIGN;
|
||||
|
||||
@ -244,6 +248,23 @@ static const unsigned char aes_128_ecb_ct[] = {
|
||||
0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65
|
||||
};
|
||||
|
||||
/*
|
||||
* TDES-ECB test data from
|
||||
* https://github.com/usnistgov/ACVP-Server/blob/master/gen-val/json-files/ACVP-TDES-ECB-1.0
|
||||
* Decrypt
|
||||
*/
|
||||
static const unsigned char tdes_key[] = {
|
||||
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
||||
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE
|
||||
};
|
||||
static const unsigned char tdes_ct[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
|
||||
};
|
||||
static const unsigned char tdes_pt[] = {
|
||||
0x4B, 0xAB, 0x3B, 0xE1, 0x50, 0x2E, 0x3B, 0x36
|
||||
};
|
||||
|
||||
static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
{
|
||||
{
|
||||
@ -267,6 +288,16 @@ static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
},
|
||||
CIPHER_MODE_DECRYPT,
|
||||
ITM(aes_128_ecb_key)
|
||||
},
|
||||
{
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_CIPHER_TDES,
|
||||
"DES-EDE3-ECB",
|
||||
ITM(tdes_pt),
|
||||
ITM(tdes_ct)
|
||||
},
|
||||
CIPHER_MODE_DECRYPT,
|
||||
ITM(tdes_key)
|
||||
}
|
||||
};
|
||||
|
||||
@ -879,80 +910,6 @@ static const ST_KAT_DRBG st_kat_drbg_tests[] =
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* DH KAT */
|
||||
static const unsigned char dh_p[] = {
|
||||
0xdc, 0xca, 0x15, 0x11, 0xb2, 0x31, 0x32, 0x25,
|
||||
0xf5, 0x21, 0x16, 0xe1, 0x54, 0x27, 0x89, 0xe0,
|
||||
0x01, 0xf0, 0x42, 0x5b, 0xcc, 0xc7, 0xf3, 0x66,
|
||||
0xf7, 0x40, 0x64, 0x07, 0xf1, 0xc9, 0xfa, 0x8b,
|
||||
0xe6, 0x10, 0xf1, 0x77, 0x8b, 0xb1, 0x70, 0xbe,
|
||||
0x39, 0xdb, 0xb7, 0x6f, 0x85, 0xbf, 0x24, 0xce,
|
||||
0x68, 0x80, 0xad, 0xb7, 0x62, 0x9f, 0x7c, 0x6d,
|
||||
0x01, 0x5e, 0x61, 0xd4, 0x3f, 0xa3, 0xee, 0x4d,
|
||||
0xe1, 0x85, 0xf2, 0xcf, 0xd0, 0x41, 0xff, 0xde,
|
||||
0x9d, 0x41, 0x84, 0x07, 0xe1, 0x51, 0x38, 0xbb,
|
||||
0x02, 0x1d, 0xae, 0xb3, 0x5f, 0x76, 0x2d, 0x17,
|
||||
0x82, 0xac, 0xc6, 0x58, 0xd3, 0x2b, 0xd4, 0xb0,
|
||||
0x23, 0x2c, 0x92, 0x7d, 0xd3, 0x8f, 0xa0, 0x97,
|
||||
0xb3, 0xd1, 0x85, 0x9f, 0xa8, 0xac, 0xaf, 0xb9,
|
||||
0x8f, 0x06, 0x66, 0x08, 0xfc, 0x64, 0x4e, 0xc7,
|
||||
0xdd, 0xb6, 0xf0, 0x85, 0x99, 0xf9, 0x2a, 0xc1,
|
||||
0xb5, 0x98, 0x25, 0xda, 0x84, 0x32, 0x07, 0x7d,
|
||||
0xef, 0x69, 0x56, 0x46, 0x06, 0x3c, 0x20, 0x82,
|
||||
0x3c, 0x95, 0x07, 0xab, 0x6f, 0x01, 0x76, 0xd4,
|
||||
0x73, 0x0d, 0x99, 0x0d, 0xbb, 0xe6, 0x36, 0x1c,
|
||||
0xd8, 0xb2, 0xb9, 0x4d, 0x3d, 0x2f, 0x32, 0x9b,
|
||||
0x82, 0x09, 0x9b, 0xd6, 0x61, 0xf4, 0x29, 0x50,
|
||||
0xf4, 0x03, 0xdf, 0x3e, 0xde, 0x62, 0xa3, 0x31,
|
||||
0x88, 0xb0, 0x27, 0x98, 0xba, 0x82, 0x3f, 0x44,
|
||||
0xb9, 0x46, 0xfe, 0x9d, 0xf6, 0x77, 0xa0, 0xc5,
|
||||
0xa1, 0x23, 0x8e, 0xaa, 0x97, 0xb7, 0x0f, 0x80,
|
||||
0xda, 0x8c, 0xac, 0x88, 0xe0, 0x92, 0xb1, 0x12,
|
||||
0x70, 0x60, 0xff, 0xbf, 0x45, 0x57, 0x99, 0x94,
|
||||
0x01, 0x1d, 0xc2, 0xfa, 0xa5, 0xe7, 0xf6, 0xc7,
|
||||
0x62, 0x45, 0xe1, 0xcc, 0x31, 0x22, 0x31, 0xc1,
|
||||
0x7d, 0x1c, 0xa6, 0xb1, 0x90, 0x07, 0xef, 0x0d,
|
||||
0xb9, 0x9f, 0x9c, 0xb6, 0x0e, 0x1d, 0x5f, 0x69
|
||||
};
|
||||
static const unsigned char dh_q[] = {
|
||||
0x89, 0x8b, 0x22, 0x67, 0x17, 0xef, 0x03, 0x9e,
|
||||
0x60, 0x3e, 0x82, 0xe5, 0xc7, 0xaf, 0xe4, 0x83,
|
||||
0x74, 0xac, 0x5f, 0x62, 0x5c, 0x54, 0xf1, 0xea,
|
||||
0x11, 0xac, 0xb5, 0x7d
|
||||
};
|
||||
static const unsigned char dh_g[] = {
|
||||
0x5e, 0xf7, 0xb8, 0x8f, 0x2d, 0xf6, 0x01, 0x39,
|
||||
0x35, 0x1d, 0xfb, 0xfe, 0x12, 0x66, 0x80, 0x5f,
|
||||
0xdf, 0x35, 0x6c, 0xdf, 0xd1, 0x3a, 0x4d, 0xa0,
|
||||
0x05, 0x0c, 0x7e, 0xde, 0x24, 0x6d, 0xf5, 0x9f,
|
||||
0x6a, 0xbf, 0x96, 0xad, 0xe5, 0xf2, 0xb2, 0x8f,
|
||||
0xfe, 0x88, 0xd6, 0xbc, 0xe7, 0xf7, 0x89, 0x4a,
|
||||
0x3d, 0x53, 0x5f, 0xc8, 0x21, 0x26, 0xdd, 0xd4,
|
||||
0x24, 0x87, 0x2e, 0x16, 0xb8, 0x38, 0xdf, 0x8c,
|
||||
0x51, 0xe9, 0x01, 0x6f, 0x88, 0x9c, 0x7c, 0x20,
|
||||
0x3e, 0x98, 0xa8, 0xb6, 0x31, 0xf9, 0xc7, 0x25,
|
||||
0x63, 0xd3, 0x8a, 0x49, 0x58, 0x9a, 0x07, 0x53,
|
||||
0xd3, 0x58, 0xe7, 0x83, 0x31, 0x8c, 0xef, 0xd9,
|
||||
0x67, 0x7c, 0x7b, 0x2d, 0xbb, 0x77, 0xd6, 0xdc,
|
||||
0xe2, 0xa1, 0x96, 0x37, 0x95, 0xca, 0x64, 0xb9,
|
||||
0x2d, 0x1c, 0x9a, 0xac, 0x6d, 0x0e, 0x8d, 0x43,
|
||||
0x1d, 0xe5, 0xe5, 0x00, 0x60, 0xdf, 0xf7, 0x86,
|
||||
0x89, 0xc9, 0xec, 0xa1, 0xc1, 0x24, 0x8c, 0x16,
|
||||
0xed, 0x09, 0xc7, 0xad, 0x41, 0x2a, 0x17, 0x40,
|
||||
0x6d, 0x2b, 0x52, 0x5a, 0xa1, 0xca, 0xbb, 0x23,
|
||||
0x7b, 0x97, 0x34, 0xec, 0x7b, 0x8c, 0xe3, 0xfa,
|
||||
0xe0, 0x2f, 0x29, 0xc5, 0xef, 0xed, 0x30, 0xd6,
|
||||
0x91, 0x87, 0xda, 0x10, 0x9c, 0x2c, 0x9f, 0xe2,
|
||||
0xaa, 0xdb, 0xb0, 0xc2, 0x2a, 0xf5, 0x4c, 0x61,
|
||||
0x66, 0x55, 0x00, 0x0c, 0x43, 0x1c, 0x6b, 0x4a,
|
||||
0x37, 0x97, 0x63, 0xb0, 0xa9, 0x16, 0x58, 0xef,
|
||||
0xc8, 0x4e, 0x8b, 0x06, 0x35, 0x8c, 0x8b, 0x4f,
|
||||
0x21, 0x37, 0x10, 0xfd, 0x10, 0x17, 0x2c, 0xf3,
|
||||
0x9b, 0x83, 0x0c, 0x2d, 0xd8, 0x4a, 0x0c, 0x8a,
|
||||
0xb8, 0x25, 0x16, 0xec, 0xab, 0x99, 0x5f, 0xa4,
|
||||
0x21, 0x5e, 0x02, 0x3e, 0x4e, 0xcf, 0x80, 0x74,
|
||||
0xc3, 0x9d, 0x6c, 0x88, 0xb7, 0x0d, 0x1e, 0xe4,
|
||||
0xe9, 0x6f, 0xdc, 0x20, 0xea, 0x11, 0x5c, 0x32
|
||||
};
|
||||
static const unsigned char dh_priv[] = {
|
||||
0x14, 0x33, 0xe0, 0xb5, 0xa9, 0x17, 0xb6, 0x0a,
|
||||
0x30, 0x23, 0xf2, 0xf8, 0xaa, 0x2c, 0x2d, 0x70,
|
||||
@ -1028,45 +985,44 @@ static const unsigned char dh_peer_pub[] = {
|
||||
0x34, 0xf9, 0x67, 0x39, 0xf1, 0x7f, 0xf4, 0x8b
|
||||
};
|
||||
|
||||
static const unsigned char dh_secret_expected[] = {
|
||||
0x08, 0xff, 0x33, 0xbb, 0x2e, 0xcf, 0xf4, 0x9a,
|
||||
0x7d, 0x4a, 0x79, 0x12, 0xae, 0xb1, 0xbb, 0x6a,
|
||||
0xb5, 0x11, 0x64, 0x1b, 0x4a, 0x76, 0x77, 0x0c,
|
||||
0x8c, 0xc1, 0xbc, 0xc2, 0x33, 0x34, 0x3d, 0xfe,
|
||||
0x70, 0x0d, 0x11, 0x81, 0x3d, 0x2c, 0x9e, 0xd2,
|
||||
0x3b, 0x21, 0x1c, 0xa9, 0xe8, 0x78, 0x69, 0x21,
|
||||
0xed, 0xca, 0x28, 0x3c, 0x68, 0xb1, 0x61, 0x53,
|
||||
0xfa, 0x01, 0xe9, 0x1a, 0xb8, 0x2c, 0x90, 0xdd,
|
||||
0xab, 0x4a, 0x95, 0x81, 0x67, 0x70, 0xa9, 0x87,
|
||||
0x10, 0xe1, 0x4c, 0x92, 0xab, 0x83, 0xb6, 0xe4,
|
||||
0x6e, 0x1e, 0x42, 0x6e, 0xe8, 0x52, 0x43, 0x0d,
|
||||
0x61, 0x87, 0xda, 0xa3, 0x72, 0x0a, 0x6b, 0xcd,
|
||||
0x73, 0x23, 0x5c, 0x6b, 0x0f, 0x94, 0x1f, 0x33,
|
||||
0x64, 0xf5, 0x04, 0x20, 0x55, 0x1a, 0x4b, 0xfe,
|
||||
0xaf, 0xe2, 0xbc, 0x43, 0x85, 0x05, 0xa5, 0x9a,
|
||||
0x4a, 0x40, 0xda, 0xca, 0x7a, 0x89, 0x5a, 0x73,
|
||||
0xdb, 0x57, 0x5c, 0x74, 0xc1, 0x3a, 0x23, 0xad,
|
||||
0x88, 0x32, 0x95, 0x7d, 0x58, 0x2d, 0x38, 0xf0,
|
||||
0xa6, 0x16, 0x5f, 0xb0, 0xd7, 0xe9, 0xb8, 0x79,
|
||||
0x9e, 0x42, 0xfd, 0x32, 0x20, 0xe3, 0x32, 0xe9,
|
||||
0x81, 0x85, 0xa0, 0xc9, 0x42, 0x97, 0x57, 0xb2,
|
||||
0xd0, 0xd0, 0x2c, 0x17, 0xdb, 0xaa, 0x1f, 0xf6,
|
||||
0xed, 0x93, 0xd7, 0xe7, 0x3e, 0x24, 0x1e, 0xae,
|
||||
0xd9, 0x0c, 0xaf, 0x39, 0x4d, 0x2b, 0xc6, 0x57,
|
||||
0x0f, 0x18, 0xc8, 0x1f, 0x2b, 0xe5, 0xd0, 0x1a,
|
||||
0x2c, 0xa9, 0x9f, 0xf1, 0x42, 0xb5, 0xd9, 0x63,
|
||||
0xf9, 0xf5, 0x00, 0x32, 0x5e, 0x75, 0x56, 0xf9,
|
||||
0x58, 0x49, 0xb3, 0xff, 0xc7, 0x47, 0x94, 0x86,
|
||||
0xbe, 0x1d, 0x45, 0x96, 0xa3, 0x10, 0x6b, 0xd5,
|
||||
0xcb, 0x4f, 0x61, 0xc5, 0x7e, 0xc5, 0xf1, 0x00,
|
||||
0xfb, 0x7a, 0x0c, 0x82, 0xa1, 0x0b, 0x82, 0x52,
|
||||
0x6a, 0x97, 0xd1, 0xd9, 0x7d, 0x98, 0xea, 0xf6
|
||||
static const unsigned char dh_secret_expected[256] = {
|
||||
0xa0, 0x38, 0x64, 0x37, 0xdf, 0x2d, 0x2c, 0x78,
|
||||
0x49, 0xb9, 0xa7, 0x77, 0xfb, 0xc1, 0x69, 0x94,
|
||||
0x85, 0xc5, 0x5a, 0xbc, 0x8d, 0x43, 0x32, 0x23,
|
||||
0x94, 0xf5, 0xba, 0xb4, 0x5f, 0x22, 0x4b, 0x4e,
|
||||
0xc4, 0xfd, 0x89, 0x41, 0x56, 0x41, 0xe8, 0x9f,
|
||||
0x2d, 0x0d, 0x26, 0x33, 0x60, 0x13, 0x8a, 0x20,
|
||||
0xf1, 0x7e, 0xb3, 0x76, 0x38, 0x03, 0x0e, 0x48,
|
||||
0x4f, 0x27, 0x8c, 0x32, 0xdb, 0x66, 0x5c, 0xbf,
|
||||
0x7f, 0xc7, 0xeb, 0xc6, 0x2d, 0xfd, 0x00, 0x08,
|
||||
0xb0, 0x98, 0x4e, 0xad, 0x68, 0x65, 0xca, 0x9e,
|
||||
0x78, 0xe1, 0xaa, 0xb7, 0x8e, 0x08, 0x4d, 0x67,
|
||||
0xa6, 0x15, 0x16, 0xbb, 0x41, 0xac, 0x15, 0xb5,
|
||||
0x08, 0x92, 0x5d, 0x25, 0x1d, 0x7f, 0xf3, 0x1b,
|
||||
0x5c, 0xea, 0x21, 0x6b, 0xe5, 0x00, 0x4d, 0xb6,
|
||||
0x8e, 0xae, 0x84, 0xb4, 0xee, 0xf7, 0xcc, 0xdd,
|
||||
0x64, 0x19, 0x4e, 0x25, 0xce, 0x37, 0x4f, 0xde,
|
||||
0xb6, 0x21, 0xba, 0xd9, 0xc0, 0x7a, 0x87, 0xc7,
|
||||
0x90, 0x0a, 0x78, 0x8b, 0xdd, 0xbc, 0x68, 0x77,
|
||||
0x2d, 0xa6, 0xdf, 0x4d, 0x2e, 0xca, 0xdc, 0x86,
|
||||
0xb6, 0x1e, 0x54, 0x2b, 0x3a, 0xa9, 0x52, 0x67,
|
||||
0xf3, 0x1a, 0x35, 0xb7, 0x5a, 0xcd, 0x99, 0x59,
|
||||
0xe9, 0x07, 0x6f, 0xd7, 0xd7, 0x96, 0x8a, 0x47,
|
||||
0xdf, 0x9f, 0x51, 0x1b, 0x04, 0xa9, 0x45, 0x30,
|
||||
0x89, 0x8a, 0x3f, 0x7e, 0xca, 0xfc, 0x05, 0x2d,
|
||||
0x18, 0x77, 0x8f, 0x45, 0x25, 0x39, 0xdb, 0xf2,
|
||||
0x13, 0x36, 0x31, 0xdb, 0x50, 0x65, 0x63, 0x4a,
|
||||
0xae, 0x3e, 0xd1, 0x3e, 0xde, 0xc1, 0x32, 0x4b,
|
||||
0x78, 0x19, 0x03, 0x70, 0x0a, 0xc2, 0xa2, 0x6f,
|
||||
0x9b, 0xd4, 0xa6, 0x1d, 0x47, 0xf2, 0xa6, 0x91,
|
||||
0x61, 0x4a, 0x74, 0xf8, 0x70, 0x39, 0x42, 0x72,
|
||||
0xd5, 0x58, 0x7f, 0xcd, 0x16, 0xeb, 0x82, 0x0c,
|
||||
0x2c, 0xf4, 0xd0, 0x95, 0x22, 0xf9, 0xbe, 0x99,
|
||||
};
|
||||
|
||||
static const char dh_ffdhe2048[] = "ffdhe2048";
|
||||
static const ST_KAT_PARAM dh_group[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_P, dh_p),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_Q, dh_q),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_G, dh_g),
|
||||
ST_KAT_PARAM_UTF8STRING(OSSL_PKEY_PARAM_GROUP_NAME, dh_ffdhe2048),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
@ -1361,6 +1317,8 @@ static const ST_KAT_PARAM rsa_enc_params[] = {
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
static const unsigned char rsa_sig_msg[] = "Hello World!";
|
||||
|
||||
static const unsigned char rsa_expected_sig[256] = {
|
||||
0xad, 0xbe, 0x2a, 0xaf, 0x16, 0x85, 0xc5, 0x00,
|
||||
0x91, 0x3e, 0xd0, 0x49, 0xfb, 0x3a, 0x81, 0xb9,
|
||||
@ -1509,6 +1467,10 @@ static const ST_KAT_PARAM ecdsa_bin_key[] = {
|
||||
# endif /* OPENSSL_NO_EC2M */
|
||||
|
||||
# ifndef OPENSSL_NO_ECX
|
||||
static const unsigned char ecx_sig_msg[] = {
|
||||
0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd, 0x66,
|
||||
0x81, 0x1e, 0x29, 0x15
|
||||
};
|
||||
static const unsigned char ed25519_pub[] = {
|
||||
0xfc, 0x51, 0xcd, 0x8e, 0x62, 0x18, 0xa1, 0xa3,
|
||||
0x8d, 0xa4, 0x7e, 0xd0, 0x02, 0x30, 0xf0, 0x58,
|
||||
@ -1709,14 +1671,12 @@ static const unsigned char dsa_expected_sig[] = {
|
||||
0x34, 0x8d, 0x9e, 0x88, 0x08, 0x06
|
||||
};
|
||||
|
||||
static int verify_only = 1;
|
||||
static const ST_KAT_PARAM dsa_key[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_P, dsa_p),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_Q, dsa_q),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_G, dsa_g),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PUB_KEY, dsa_pub),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PRIV_KEY, dsa_priv),
|
||||
ST_KAT_PARAM_INT(ST_PARAM_VERIFY_ONLY, verify_only),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
#endif /* OPENSSL_NO_DSA */
|
||||
@ -1740,9 +1700,9 @@ static const unsigned char sig_kat_persstr[] = {
|
||||
static const ST_KAT_SIGN st_kat_sign_tests[] = {
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_RSA,
|
||||
"RSA",
|
||||
"SHA-256",
|
||||
"RSA", "SHA-256", 0,
|
||||
rsa_crt_key,
|
||||
ITM_STR(rsa_sig_msg),
|
||||
ITM(sig_kat_entropyin),
|
||||
ITM(sig_kat_nonce),
|
||||
ITM(sig_kat_persstr),
|
||||
@ -1751,9 +1711,9 @@ static const ST_KAT_SIGN st_kat_sign_tests[] = {
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_ECDSA,
|
||||
"EC",
|
||||
"SHA-256",
|
||||
"EC", "SHA-256", 0,
|
||||
ecdsa_prime_key,
|
||||
ITM_STR(rsa_sig_msg),
|
||||
ITM(sig_kat_entropyin),
|
||||
ITM(sig_kat_nonce),
|
||||
ITM(sig_kat_persstr),
|
||||
@ -1762,9 +1722,9 @@ static const ST_KAT_SIGN st_kat_sign_tests[] = {
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_ECDSA,
|
||||
"EC",
|
||||
"SHA-256",
|
||||
"EC", "SHA-256", 0,
|
||||
ecdsa_bin_key,
|
||||
ITM_STR(rsa_sig_msg),
|
||||
ITM(sig_kat_entropyin),
|
||||
ITM(sig_kat_nonce),
|
||||
ITM(sig_kat_persstr),
|
||||
@ -1774,30 +1734,28 @@ static const ST_KAT_SIGN st_kat_sign_tests[] = {
|
||||
# ifndef OPENSSL_NO_ECX
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_EDDSA,
|
||||
"ED448",
|
||||
NULL,
|
||||
"ED448", NULL, SIGNATURE_MODE_ONESHOT,
|
||||
ed448_key,
|
||||
ITM(ecx_sig_msg),
|
||||
NULL, 0, NULL, 0, NULL, 0,
|
||||
ITM(ed448_expected_sig),
|
||||
1
|
||||
},
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_EDDSA,
|
||||
"ED25519",
|
||||
NULL,
|
||||
"ED25519", NULL, SIGNATURE_MODE_ONESHOT,
|
||||
ed25519_key,
|
||||
ITM(ecx_sig_msg),
|
||||
NULL, 0, NULL, 0, NULL, 0,
|
||||
ITM(ed25519_expected_sig),
|
||||
1
|
||||
},
|
||||
# endif /* OPENSSL_NO_ECX */
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_DSA,
|
||||
"DSA",
|
||||
"SHA-256",
|
||||
"DSA", "SHA-256", SIGNATURE_MODE_VERIFY_ONLY,
|
||||
dsa_key,
|
||||
ITM_STR(rsa_sig_msg),
|
||||
ITM(sig_kat_entropyin),
|
||||
ITM(sig_kat_nonce),
|
||||
ITM(sig_kat_persstr),
|
||||
|
@ -375,12 +375,15 @@ static int self_test_ka(const ST_KAT_KAS *t,
|
||||
OSSL_PARAM *params = NULL;
|
||||
OSSL_PARAM *params_peer = NULL;
|
||||
unsigned char secret[256];
|
||||
size_t secret_len = sizeof(secret);
|
||||
size_t secret_len = t->expected_len;
|
||||
OSSL_PARAM_BLD *bld = NULL;
|
||||
BN_CTX *bnctx = NULL;
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_KA, t->desc);
|
||||
|
||||
if (secret_len > sizeof(secret))
|
||||
goto err;
|
||||
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
@ -443,105 +446,6 @@ err:
|
||||
}
|
||||
#endif /* !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_EC) */
|
||||
|
||||
static int self_test_sign(const ST_KAT_SIGN *t,
|
||||
OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
OSSL_PARAM *params = NULL, *params_sig = NULL;
|
||||
OSSL_PARAM_BLD *bld = NULL;
|
||||
EVP_PKEY_CTX *sctx = NULL, *kctx = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
unsigned char sig[256];
|
||||
BN_CTX *bnctx = NULL;
|
||||
size_t siglen = sizeof(sig);
|
||||
static const unsigned char dgst[] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
const char *typ = OSSL_SELF_TEST_TYPE_KAT_SIGNATURE;
|
||||
|
||||
if (t->sig_expected == NULL)
|
||||
typ = OSSL_SELF_TEST_TYPE_PCT_SIGNATURE;
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, typ, t->desc);
|
||||
|
||||
if (!set_kat_drbg(libctx, t->entropy, t->entropy_len,
|
||||
t->nonce, t->nonce_len, t->persstr, t->persstr_len))
|
||||
goto err;
|
||||
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
|
||||
bld = OSSL_PARAM_BLD_new();
|
||||
if (bld == NULL)
|
||||
goto err;
|
||||
|
||||
if (!add_params(bld, t->key, bnctx))
|
||||
goto err;
|
||||
params = OSSL_PARAM_BLD_to_param(bld);
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DSA key into */
|
||||
kctx = EVP_PKEY_CTX_new_from_name(libctx, t->algorithm, "");
|
||||
if (kctx == NULL || params == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_fromdata_init(kctx) <= 0
|
||||
|| EVP_PKEY_fromdata(kctx, &pkey, EVP_PKEY_KEYPAIR, params) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to use for the signing operation */
|
||||
sctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (sctx == NULL)
|
||||
goto err;
|
||||
|
||||
/* set signature parameters */
|
||||
if (!OSSL_PARAM_BLD_push_utf8_string(bld, OSSL_SIGNATURE_PARAM_DIGEST,
|
||||
t->mdalgorithm,
|
||||
strlen(t->mdalgorithm) + 1))
|
||||
goto err;
|
||||
params_sig = OSSL_PARAM_BLD_to_param(bld);
|
||||
|
||||
/* Skip the sign for legacy algorithms that only support the verify operation */
|
||||
if (OSSL_PARAM_locate(params, ST_PARAM_VERIFY_ONLY) == NULL) {
|
||||
if (EVP_PKEY_sign_init(sctx) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_sign(sctx, sig, &siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
memcpy(sig, t->sig_expected, t->sig_expected_len);
|
||||
siglen = t->sig_expected_len;
|
||||
}
|
||||
if (EVP_PKEY_verify_init(sctx) <= 0
|
||||
|| EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
|
||||
if (t->sig_expected != NULL
|
||||
&& (siglen != t->sig_expected_len
|
||||
|| memcmp(sig, t->sig_expected, t->sig_expected_len) != 0))
|
||||
goto err;
|
||||
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, sig);
|
||||
if (EVP_PKEY_verify(sctx, sig, siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_free(bnctx);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(sctx);
|
||||
OSSL_PARAM_free(params);
|
||||
OSSL_PARAM_free(params_sig);
|
||||
OSSL_PARAM_BLD_free(bld);
|
||||
if (!reset_main_drbg(libctx))
|
||||
ret = 0;
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ECX
|
||||
static int self_test_digest_sign(const ST_KAT_SIGN *t,
|
||||
OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
|
||||
{
|
||||
@ -554,10 +458,7 @@ static int self_test_digest_sign(const ST_KAT_SIGN *t,
|
||||
unsigned char sig[256];
|
||||
BN_CTX *bnctx = NULL;
|
||||
size_t siglen = sizeof(sig);
|
||||
static const unsigned char in[] = {
|
||||
0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd, 0x66,
|
||||
0x81, 0x1e, 0x29, 0x15
|
||||
};
|
||||
int oneshot = 0;
|
||||
const char *typ = OSSL_SELF_TEST_TYPE_KAT_SIGNATURE;
|
||||
|
||||
if (t->sig_expected == NULL)
|
||||
@ -565,6 +466,12 @@ static int self_test_digest_sign(const ST_KAT_SIGN *t,
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, typ, t->desc);
|
||||
|
||||
if (t->entropy != NULL) {
|
||||
if (!set_kat_drbg(libctx, t->entropy, t->entropy_len,
|
||||
t->nonce, t->nonce_len, t->persstr, t->persstr_len))
|
||||
goto err;
|
||||
}
|
||||
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
@ -591,24 +498,48 @@ static int self_test_digest_sign(const ST_KAT_SIGN *t,
|
||||
goto err;
|
||||
|
||||
mctx = EVP_MD_CTX_new();
|
||||
if (mctx == NULL
|
||||
|| EVP_DigestSignInit_ex(mctx, NULL, NULL, libctx, NULL,
|
||||
pkey, paramsinit) <= 0)
|
||||
if (mctx == NULL)
|
||||
goto err;
|
||||
|
||||
if (EVP_DigestSign(mctx, sig, &siglen, in, sizeof(in)) <= 0)
|
||||
goto err;
|
||||
if (t->sig_expected != NULL
|
||||
&& (siglen != t->sig_expected_len
|
||||
|| memcmp(sig, t->sig_expected, t->sig_expected_len) != 0))
|
||||
goto err;
|
||||
oneshot = ((t->mode & SIGNATURE_MODE_ONESHOT) != 0);
|
||||
|
||||
if (EVP_DigestVerifyInit_ex(mctx, NULL, NULL, libctx, NULL,
|
||||
pkey, paramsinit) <= 0)
|
||||
goto err;
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, sig);
|
||||
if (EVP_DigestVerify(mctx, sig, siglen, in, sizeof(in)) <= 0)
|
||||
goto err;
|
||||
if ((t->mode & SIGNATURE_MODE_VERIFY_ONLY) != 0) {
|
||||
memcpy(sig, t->sig_expected, t->sig_expected_len);
|
||||
siglen = t->sig_expected_len;
|
||||
} else {
|
||||
if (EVP_DigestSignInit_ex(mctx, NULL, t->mdalgorithm, libctx, NULL,
|
||||
pkey, paramsinit) <= 0)
|
||||
goto err;
|
||||
|
||||
if (oneshot) {
|
||||
if (EVP_DigestSign(mctx, sig, &siglen, t->msg, t->msg_len) <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
if (EVP_DigestSignUpdate(mctx, t->msg, t->msg_len) <= 0
|
||||
|| EVP_DigestSignFinal(mctx, sig, &siglen) <= 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (t->sig_expected != NULL
|
||||
&& (siglen != t->sig_expected_len
|
||||
|| memcmp(sig, t->sig_expected, t->sig_expected_len) != 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((t->mode & SIGNATURE_MODE_SIGN_ONLY) == 0) {
|
||||
if (EVP_DigestVerifyInit_ex(mctx, NULL, t->mdalgorithm, libctx, NULL,
|
||||
pkey, paramsinit) <= 0)
|
||||
goto err;
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, sig);
|
||||
if (oneshot) {
|
||||
if (EVP_DigestVerify(mctx, sig, siglen, t->msg, t->msg_len) <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
if (EVP_DigestVerifyUpdate(mctx, t->msg, t->msg_len) <= 0
|
||||
|| EVP_DigestVerifyFinal(mctx, sig, siglen) <= 0)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_free(bnctx);
|
||||
@ -619,10 +550,13 @@ err:
|
||||
OSSL_PARAM_free(paramsinit);
|
||||
OSSL_PARAM_BLD_free(bldkey);
|
||||
OSSL_PARAM_BLD_free(bldinit);
|
||||
if (t->entropy != NULL) {
|
||||
if (!reset_main_drbg(libctx))
|
||||
ret = 0;
|
||||
}
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_ECX */
|
||||
|
||||
/*
|
||||
* Test an encrypt or decrypt KAT..
|
||||
@ -789,20 +723,10 @@ static int self_test_kas(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
|
||||
static int self_test_signatures(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
const ST_KAT_SIGN *t;
|
||||
|
||||
for (i = 0; ret && i < (int)OSSL_NELEM(st_kat_sign_tests); ++i) {
|
||||
t = st_kat_sign_tests + i;
|
||||
#ifndef OPENSSL_NO_ECX
|
||||
if (t->oneshot) {
|
||||
if (!self_test_digest_sign(t, st, libctx))
|
||||
ret = 0;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (!self_test_sign(t, st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_sign_tests); ++i) {
|
||||
if (!self_test_digest_sign(&st_kat_sign_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user