aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssl/providers/fips
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/providers/fips')
-rw-r--r--crypto/openssl/providers/fips/fipsprov.c9
-rw-r--r--crypto/openssl/providers/fips/include/fips/fipsindicator.h3
-rw-r--r--crypto/openssl/providers/fips/self_test.c13
-rw-r--r--crypto/openssl/providers/fips/self_test_data.inc277
-rw-r--r--crypto/openssl/providers/fips/self_test_kats.c100
5 files changed, 288 insertions, 114 deletions
diff --git a/crypto/openssl/providers/fips/fipsprov.c b/crypto/openssl/providers/fips/fipsprov.c
index 4b9a0574625d..e260b5b6652e 100644
--- a/crypto/openssl/providers/fips/fipsprov.c
+++ b/crypto/openssl/providers/fips/fipsprov.c
@@ -65,6 +65,7 @@ static OSSL_FUNC_core_vset_error_fn *c_vset_error;
static OSSL_FUNC_core_set_error_mark_fn *c_set_error_mark;
static OSSL_FUNC_core_clear_last_error_mark_fn *c_clear_last_error_mark;
static OSSL_FUNC_core_pop_error_to_mark_fn *c_pop_error_to_mark;
+static OSSL_FUNC_core_count_to_mark_fn *c_count_to_mark;
static OSSL_FUNC_CRYPTO_malloc_fn *c_CRYPTO_malloc;
static OSSL_FUNC_CRYPTO_zalloc_fn *c_CRYPTO_zalloc;
static OSSL_FUNC_CRYPTO_free_fn *c_CRYPTO_free;
@@ -797,6 +798,9 @@ int OSSL_provider_init_int(const OSSL_CORE_HANDLE *handle,
case OSSL_FUNC_CORE_POP_ERROR_TO_MARK:
set_func(c_pop_error_to_mark, OSSL_FUNC_core_pop_error_to_mark(in));
break;
+ case OSSL_FUNC_CORE_COUNT_TO_MARK:
+ set_func(c_count_to_mark, OSSL_FUNC_core_count_to_mark(in));
+ break;
case OSSL_FUNC_CRYPTO_MALLOC:
set_func(c_CRYPTO_malloc, OSSL_FUNC_CRYPTO_malloc(in));
break;
@@ -1035,6 +1039,11 @@ int ERR_pop_to_mark(void)
return c_pop_error_to_mark(NULL);
}
+int ERR_count_to_mark(void)
+{
+ return c_count_to_mark != NULL ? c_count_to_mark(NULL) : 0;
+}
+
/*
* This must take a library context, since it's called from the depths
* of crypto/initthread.c code, where it's (correctly) assumed that the
diff --git a/crypto/openssl/providers/fips/include/fips/fipsindicator.h b/crypto/openssl/providers/fips/include/fips/fipsindicator.h
index 045d2108d549..9b2b5b49a7fa 100644
--- a/crypto/openssl/providers/fips/include/fips/fipsindicator.h
+++ b/crypto/openssl/providers/fips/include/fips/fipsindicator.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -134,6 +134,7 @@ int ossl_fips_ind_digest_exch_check(OSSL_FIPS_IND *ind, int id, OSSL_LIB_CTX *li
int ossl_fips_ind_digest_sign_check(OSSL_FIPS_IND *ind, int id,
OSSL_LIB_CTX *libctx,
int nid, int sha1_allowed,
+ int sha512_trunc_allowed,
const char *desc,
OSSL_FIPS_IND_CHECK_CB *config_check_f);
diff --git a/crypto/openssl/providers/fips/self_test.c b/crypto/openssl/providers/fips/self_test.c
index ef7be26ca722..456efd139e94 100644
--- a/crypto/openssl/providers/fips/self_test.c
+++ b/crypto/openssl/providers/fips/self_test.c
@@ -424,9 +424,18 @@ void SELF_TEST_disable_conditional_error_state(void)
void ossl_set_error_state(const char *type)
{
- int cond_test = (type != NULL && strcmp(type, OSSL_SELF_TEST_TYPE_PCT) == 0);
+ int cond_test = 0;
+ int import_pct = 0;
- if (!cond_test || (FIPS_conditional_error_check == 1)) {
+ if (type != NULL) {
+ cond_test = strcmp(type, OSSL_SELF_TEST_TYPE_PCT) == 0;
+ import_pct = strcmp(type, OSSL_SELF_TEST_TYPE_PCT_IMPORT) == 0;
+ }
+
+ if (import_pct) {
+ /* Failure to import is transient to avoid a DoS attack */
+ ERR_raise(ERR_LIB_PROV, PROV_R_FIPS_MODULE_IMPORT_PCT_ERROR);
+ } else if (!cond_test || (FIPS_conditional_error_check == 1)) {
set_fips_state(FIPS_STATE_ERROR);
ERR_raise(ERR_LIB_PROV, PROV_R_FIPS_MODULE_ENTERING_ERROR_STATE);
} else {
diff --git a/crypto/openssl/providers/fips/self_test_data.inc b/crypto/openssl/providers/fips/self_test_data.inc
index 5cbb5352a596..6abab0a7a173 100644
--- a/crypto/openssl/providers/fips/self_test_data.inc
+++ b/crypto/openssl/providers/fips/self_test_data.inc
@@ -169,6 +169,12 @@ typedef struct st_kat_kem_st {
} ST_KAT_KEM;
/*- DIGEST SELF TEST DATA */
+static const unsigned char sha1_pt[] = "abc";
+static const unsigned char sha1_digest[] = {
+ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A,
+ 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C,
+ 0x9C, 0xD0, 0xD8, 0x9D
+};
static const unsigned char sha512_pt[] = "abc";
static const unsigned char sha512_digest[] = {
0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, 0xCC, 0x41, 0x73, 0x49,
@@ -187,12 +193,18 @@ static const unsigned char sha3_256_digest[] = {
/*
* Note:
- * SHA1 and SHA256 are tested by higher level algorithms so a
+ * SHA256 is tested by higher level algorithms so a
* CAST is not needed.
*/
static const ST_KAT_DIGEST st_kat_digest_tests[] =
{
{
+ OSSL_SELF_TEST_DESC_MD_SHA1,
+ "SHA1",
+ ITM_STR(sha1_pt),
+ ITM(sha1_digest),
+ },
+ {
OSSL_SELF_TEST_DESC_MD_SHA2,
"SHA512",
ITM_STR(sha512_pt),
@@ -208,28 +220,6 @@ static const ST_KAT_DIGEST st_kat_digest_tests[] =
/*- CIPHER TEST DATA */
-/* DES3 test data */
-static const unsigned char des_ede3_cbc_pt[] = {
- 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
- 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
- 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
- 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51
-};
-static const unsigned char des_ede3_cbc_key[] = {
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
- 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
-};
-static const unsigned char des_ede3_cbc_iv[] = {
- 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17
-};
-static const unsigned char des_ede3_cbc_ct[] = {
- 0x20, 0x79, 0xC3, 0xD5, 0x3A, 0xA7, 0x63, 0xE1,
- 0x93, 0xB7, 0x9E, 0x25, 0x69, 0xAB, 0x52, 0x62,
- 0x51, 0x65, 0x70, 0x48, 0x1F, 0x25, 0xB5, 0x0F,
- 0x73, 0xC0, 0xBD, 0xA8, 0x5C, 0x8E, 0x0D, 0xA7
-};
-
/* AES-256 GCM test data */
static const unsigned char aes_256_gcm_key[] = {
0x92, 0xe1, 0x1d, 0xcd, 0xaa, 0x86, 0x6f, 0x5c,
@@ -364,7 +354,7 @@ static const ST_KAT_PARAM hkdf_params[] = {
ST_KAT_PARAM_END()
};
-static const char sskdf_digest[] = "SHA224";
+static const char sskdf_digest[] = "SHA256";
static const unsigned char sskdf_secret[] = {
0x6d, 0xbd, 0xc2, 0x3f, 0x04, 0x54, 0x88, 0xe4,
0x06, 0x27, 0x57, 0xb0, 0x6b, 0x9e, 0xba, 0xe1,
@@ -383,8 +373,8 @@ static const unsigned char sskdf_otherinfo[] = {
0x9b, 0x1e, 0xe0, 0xec, 0x3f, 0x8d, 0xbe
};
static const unsigned char sskdf_expected[] = {
- 0xa4, 0x62, 0xde, 0x16, 0xa8, 0x9d, 0xe8, 0x46,
- 0x6e, 0xf5, 0x46, 0x0b, 0x47, 0xb8
+ 0x27, 0xce, 0x57, 0xed, 0xb1, 0x7e, 0x1f, 0xf2,
+ 0xe4, 0x79, 0x2e, 0x84, 0x8b, 0x04, 0xf1, 0xae
};
static const ST_KAT_PARAM sskdf_params[] = {
ST_KAT_PARAM_UTF8STRING(OSSL_KDF_PARAM_DIGEST, sskdf_digest),
@@ -393,7 +383,7 @@ static const ST_KAT_PARAM sskdf_params[] = {
ST_KAT_PARAM_END()
};
-static const char x942kdf_digest[] = "SHA1";
+static const char x942kdf_digest[] = "SHA256";
static const char x942kdf_cekalg[] = "AES-128-WRAP";
static const unsigned char x942kdf_secret[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -401,8 +391,8 @@ static const unsigned char x942kdf_secret[] = {
0x10, 0x11, 0x12, 0x13
};
static const unsigned char x942kdf_expected[] = {
- 0xd6, 0xd6, 0xb0, 0x94, 0xc1, 0x02, 0x7a, 0x7d,
- 0xe6, 0xe3, 0x11, 0x72, 0x94, 0xa3, 0x53, 0x64
+ 0x79, 0x66, 0xa0, 0x38, 0x22, 0x28, 0x1e, 0xa3,
+ 0xeb, 0x08, 0xd9, 0xbc, 0x69, 0x5b, 0xd8, 0xff
};
static const ST_KAT_PARAM x942kdf_params[] = {
ST_KAT_PARAM_UTF8STRING(OSSL_KDF_PARAM_DIGEST, x942kdf_digest),
@@ -809,51 +799,73 @@ static const unsigned char drbg_ctr_aes128_pr_df_expected[] = {
/*
* HMAC_DRBG.rsp
*
- * [SHA-1]
+ * [SHA-256]
* [PredictionResistance = True]
- * [EntropyInputLen = 128]
- * [NonceLen = 64]
- * [PersonalizationStringLen = 128]
- * [AdditionalInputLen = 128]
- * [ReturnedBitsLen = 640]
+ * [EntropyInputLen = 256]
+ * [NonceLen = 128]
+ * [PersonalizationStringLen = 256]
+ * [AdditionalInputLen = 256]
+ * [ReturnedBitsLen = 1024]
*
* COUNT = 0
*/
-static const unsigned char drbg_hmac_sha1_pr_entropyin[] = {
- 0x68, 0x0f, 0xac, 0xe9, 0x0d, 0x7b, 0xca, 0x21, 0xd4, 0xa0, 0xed, 0xb7,
- 0x79, 0x9e, 0xe5, 0xd8
-};
-static const unsigned char drbg_hmac_sha1_pr_nonce[] = {
- 0xb7, 0xbe, 0x9e, 0xed, 0xdd, 0x0e, 0x3b, 0x4b
-};
-static const unsigned char drbg_hmac_sha1_pr_persstr[] = {
- 0xf5, 0x8c, 0x40, 0xae, 0x70, 0xf7, 0xa5, 0x56, 0x48, 0xa9, 0x31, 0xa0,
- 0xa9, 0x31, 0x3d, 0xd7
-};
-static const unsigned char drbg_hmac_sha1_pr_entropyinpr0[] = {
- 0x7c, 0xaf, 0xe2, 0x31, 0x63, 0x0a, 0xa9, 0x5a, 0x74, 0x2c, 0x4e, 0x5f,
- 0x5f, 0x22, 0xc6, 0xa4
-};
-static const unsigned char drbg_hmac_sha1_pr_entropyinpr1[] = {
- 0x1c, 0x0d, 0x77, 0x92, 0x89, 0x88, 0x27, 0x94, 0x8a, 0x58, 0x9f, 0x82,
- 0x2d, 0x1a, 0xf7, 0xa6
-};
-static const unsigned char drbg_hmac_sha1_pr_addin0[] = {
- 0xdc, 0x36, 0x63, 0xf0, 0x62, 0x78, 0x9c, 0xd1, 0x5c, 0xbb, 0x20, 0xc3,
- 0xc1, 0x8c, 0xd9, 0xd7
-};
-static const unsigned char drbg_hmac_sha1_pr_addin1[] = {
- 0xfe, 0x85, 0xb0, 0xab, 0x14, 0xc6, 0x96, 0xe6, 0x9c, 0x24, 0xe7, 0xb5,
- 0xa1, 0x37, 0x12, 0x0c
-};
-static const unsigned char drbg_hmac_sha1_pr_expected[] = {
- 0x68, 0x00, 0x4b, 0x3a, 0x28, 0xf7, 0xf0, 0x1c, 0xf9, 0xe9, 0xb5, 0x71,
- 0x20, 0x79, 0xef, 0x80, 0x87, 0x1b, 0x08, 0xb9, 0xa9, 0x1b, 0xcd, 0x2b,
- 0x9f, 0x09, 0x4d, 0xa4, 0x84, 0x80, 0xb3, 0x4c, 0xaf, 0xd5, 0x59, 0x6b,
- 0x0c, 0x0a, 0x48, 0xe1, 0x48, 0xda, 0xbc, 0x6f, 0x77, 0xb8, 0xff, 0xaf,
- 0x18, 0x70, 0x28, 0xe1, 0x04, 0x13, 0x7a, 0x4f, 0xeb, 0x1c, 0x72, 0xb0,
- 0xc4, 0x4f, 0xe8, 0xb1, 0xaf, 0xab, 0xa5, 0xbc, 0xfd, 0x86, 0x67, 0xf2,
- 0xf5, 0x5b, 0x46, 0x06, 0x63, 0x2e, 0x3c, 0xbc
+static const unsigned char drbg_hmac_sha2_pr_entropyin[] = {
+ 0xca, 0x85, 0x19, 0x11, 0x34, 0x93, 0x84, 0xbf,
+ 0xfe, 0x89, 0xde, 0x1c, 0xbd, 0xc4, 0x6e, 0x68,
+ 0x31, 0xe4, 0x4d, 0x34, 0xa4, 0xfb, 0x93, 0x5e,
+ 0xe2, 0x85, 0xdd, 0x14, 0xb7, 0x1a, 0x74, 0x88
+};
+static const unsigned char drbg_hmac_sha2_pr_nonce[] = {
+ 0x65, 0x9b, 0xa9, 0x6c, 0x60, 0x1d, 0xc6, 0x9f,
+ 0xc9, 0x02, 0x94, 0x08, 0x05, 0xec, 0x0c, 0xa8
+};
+static const unsigned char drbg_hmac_sha2_pr_persstr[] = {
+ 0xe7, 0x2d, 0xd8, 0x59, 0x0d, 0x4e, 0xd5, 0x29,
+ 0x55, 0x15, 0xc3, 0x5e, 0xd6, 0x19, 0x9e, 0x9d,
+ 0x21, 0x1b, 0x8f, 0x06, 0x9b, 0x30, 0x58, 0xca,
+ 0xa6, 0x67, 0x0b, 0x96, 0xef, 0x12, 0x08, 0xd0
+};
+static const unsigned char drbg_hmac_sha2_pr_entropyinpr0[] = {
+ 0x5c, 0xac, 0xc6, 0x81, 0x65, 0xa2, 0xe2, 0xee,
+ 0x20, 0x81, 0x2f, 0x35, 0xec, 0x73, 0xa7, 0x9d,
+ 0xbf, 0x30, 0xfd, 0x47, 0x54, 0x76, 0xac, 0x0c,
+ 0x44, 0xfc, 0x61, 0x74, 0xcd, 0xac, 0x2b, 0x55
+};
+static const unsigned char drbg_hmac_sha2_pr_entropyinpr1[] = {
+ 0x8d, 0xf0, 0x13, 0xb4, 0xd1, 0x03, 0x52, 0x30,
+ 0x73, 0x91, 0x7d, 0xdf, 0x6a, 0x86, 0x97, 0x93,
+ 0x05, 0x9e, 0x99, 0x43, 0xfc, 0x86, 0x54, 0x54,
+ 0x9e, 0x7a, 0xb2, 0x2f, 0x7c, 0x29, 0xf1, 0x22
+};
+static const unsigned char drbg_hmac_sha2_pr_addin0[] = {
+ 0x79, 0x3a, 0x7e, 0xf8, 0xf6, 0xf0, 0x48, 0x2b,
+ 0xea, 0xc5, 0x42, 0xbb, 0x78, 0x5c, 0x10, 0xf8,
+ 0xb7, 0xb4, 0x06, 0xa4, 0xde, 0x92, 0x66, 0x7a,
+ 0xb1, 0x68, 0xec, 0xc2, 0xcf, 0x75, 0x73, 0xc6
+};
+static const unsigned char drbg_hmac_sha2_pr_addin1[] = {
+ 0x22, 0x38, 0xcd, 0xb4, 0xe2, 0x3d, 0x62, 0x9f,
+ 0xe0, 0xc2, 0xa8, 0x3d, 0xd8, 0xd5, 0x14, 0x4c,
+ 0xe1, 0xa6, 0x22, 0x9e, 0xf4, 0x1d, 0xab, 0xe2,
+ 0xa9, 0x9f, 0xf7, 0x22, 0xe5, 0x10, 0xb5, 0x30
+};
+static const unsigned char drbg_hmac_sha2_pr_expected[] = {
+ 0xb1, 0xd1, 0x7c, 0x00, 0x2a, 0x7f, 0xeb, 0xd2,
+ 0x84, 0x12, 0xd8, 0xe5, 0x8a, 0x7f, 0x32, 0x31,
+ 0x8e, 0x4e, 0xe3, 0x60, 0x5a, 0x99, 0xb0, 0x5b,
+ 0x05, 0xd5, 0x93, 0x56, 0xd5, 0xf0, 0xc6, 0xb4,
+ 0x96, 0x0a, 0x4b, 0x8f, 0x96, 0x3b, 0x7e, 0xfa,
+ 0x55, 0xbb, 0x68, 0x72, 0xfb, 0xea, 0xc7, 0xb9,
+ 0x9b, 0x78, 0xde, 0xa8, 0xf3, 0x53, 0x19, 0x73,
+ 0x63, 0x7c, 0x94, 0x6a, 0x9c, 0xab, 0x33, 0x49,
+ 0x74, 0x4b, 0x24, 0xa0, 0x85, 0x1d, 0xd4, 0x7f,
+ 0x2b, 0x3b, 0x46, 0x0c, 0x2c, 0x61, 0x84, 0x6e,
+ 0x91, 0x18, 0x1d, 0x62, 0xd4, 0x2c, 0x60, 0xa4,
+ 0xef, 0xda, 0x5e, 0xd5, 0x79, 0x02, 0xbf, 0xd7,
+ 0x02, 0xb3, 0x49, 0xc5, 0x49, 0x52, 0xc7, 0xf6,
+ 0x44, 0x76, 0x9d, 0x8e, 0xf4, 0x01, 0x5e, 0xcc,
+ 0x5f, 0x5b, 0xbd, 0x4a, 0xf0, 0x61, 0x34, 0x68,
+ 0x8e, 0x30, 0x05, 0x0e, 0x04, 0x97, 0xfb, 0x0a
};
static const ST_KAT_DRBG st_kat_drbg_tests[] =
@@ -884,15 +896,15 @@ static const ST_KAT_DRBG st_kat_drbg_tests[] =
},
{
OSSL_SELF_TEST_DESC_DRBG_HMAC,
- "HMAC-DRBG", "digest", "SHA1",
- ITM(drbg_hmac_sha1_pr_entropyin),
- ITM(drbg_hmac_sha1_pr_nonce),
- ITM(drbg_hmac_sha1_pr_persstr),
- ITM(drbg_hmac_sha1_pr_entropyinpr0),
- ITM(drbg_hmac_sha1_pr_entropyinpr1),
- ITM(drbg_hmac_sha1_pr_addin0),
- ITM(drbg_hmac_sha1_pr_addin1),
- ITM(drbg_hmac_sha1_pr_expected)
+ "HMAC-DRBG", "digest", "SHA256",
+ ITM(drbg_hmac_sha2_pr_entropyin),
+ ITM(drbg_hmac_sha2_pr_nonce),
+ ITM(drbg_hmac_sha2_pr_persstr),
+ ITM(drbg_hmac_sha2_pr_entropyinpr0),
+ ITM(drbg_hmac_sha2_pr_entropyinpr1),
+ ITM(drbg_hmac_sha2_pr_addin0),
+ ITM(drbg_hmac_sha2_pr_addin1),
+ ITM(drbg_hmac_sha2_pr_expected)
}
};
@@ -907,38 +919,39 @@ static const unsigned char dh_priv[] = {
0x40, 0xb8, 0xfc, 0xe6
};
static const unsigned char dh_pub[] = {
- 0x95, 0xdd, 0x33, 0x8d, 0x29, 0xe5, 0x71, 0x04,
- 0x92, 0xb9, 0x18, 0x31, 0x7b, 0x72, 0xa3, 0x69,
- 0x36, 0xe1, 0x95, 0x1a, 0x2e, 0xe5, 0xa5, 0x59,
- 0x16, 0x99, 0xc0, 0x48, 0x6d, 0x0d, 0x4f, 0x9b,
- 0xdd, 0x6d, 0x5a, 0x3f, 0x6b, 0x98, 0x89, 0x0c,
- 0x62, 0xb3, 0x76, 0x52, 0xd3, 0x6e, 0x71, 0x21,
- 0x11, 0xe6, 0x8a, 0x73, 0x55, 0x37, 0x25, 0x06,
- 0x99, 0xef, 0xe3, 0x30, 0x53, 0x73, 0x91, 0xfb,
- 0xc2, 0xc5, 0x48, 0xbc, 0x5a, 0xc3, 0xe5, 0xb2,
- 0x33, 0x86, 0xc3, 0xee, 0xf5, 0xeb, 0x43, 0xc0,
- 0x99, 0xd7, 0x0a, 0x52, 0x02, 0x68, 0x7e, 0x83,
- 0x96, 0x42, 0x48, 0xfc, 0xa9, 0x1f, 0x40, 0x90,
- 0x8e, 0x8f, 0xb3, 0x31, 0x93, 0x15, 0xf6, 0xd2,
- 0x60, 0x6d, 0x7f, 0x7c, 0xd5, 0x2c, 0xc6, 0xe7,
- 0xc5, 0x84, 0x3a, 0xfb, 0x22, 0x51, 0x9c, 0xf0,
- 0xf0, 0xf9, 0xd3, 0xa0, 0xa4, 0xe8, 0xc8, 0x88,
- 0x99, 0xef, 0xed, 0xe7, 0x36, 0x43, 0x51, 0xfb,
- 0x6a, 0x36, 0x3e, 0xe7, 0x17, 0xe5, 0x44, 0x5a,
- 0xda, 0xb4, 0xc9, 0x31, 0xa6, 0x48, 0x39, 0x97,
- 0xb8, 0x7d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0x8a, 0x72, 0x90,
+ 0x10, 0xac, 0x51, 0x3a, 0x96, 0x43, 0xdf, 0x6f,
+ 0xea
};
static const unsigned char dh_peer_pub[] = {
0x1f, 0xc1, 0xda, 0x34, 0x1d, 0x1a, 0x84, 0x6a,
@@ -1295,6 +1308,18 @@ static const ST_KAT_PARAM rsa_priv_key[] = {
ST_KAT_PARAM_END()
};
+/*-
+ * Using OSSL_PKEY_RSA_PAD_MODE_NONE directly in the expansion of the
+ * ST_KAT_PARAM_UTF8STRING macro below causes a failure on ancient
+ * HP/UX PA-RISC compilers.
+ */
+static const char pad_mode_none[] = OSSL_PKEY_RSA_PAD_MODE_NONE;
+
+static const ST_KAT_PARAM rsa_enc_params[] = {
+ ST_KAT_PARAM_UTF8STRING(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, pad_mode_none),
+ ST_KAT_PARAM_END()
+};
+
static const unsigned char rsa_sig_msg[] = "Hello World!";
static const unsigned char rsa_expected_sig[256] = {
@@ -3484,3 +3509,33 @@ static const ST_KAT_ASYM_KEYGEN st_kat_asym_keygen_tests[] = {
# endif
};
#endif /* !OPENSSL_NO_ML_DSA || !OPENSSL_NO_SLH_DSA */
+
+static const ST_KAT_ASYM_CIPHER st_kat_asym_cipher_tests[] = {
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_ENC,
+ "RSA",
+ 1,
+ rsa_pub_key,
+ rsa_enc_params,
+ ITM(rsa_asym_plaintext_encrypt),
+ ITM(rsa_asym_expected_encrypt),
+ },
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_DEC,
+ "RSA",
+ 0,
+ rsa_priv_key,
+ rsa_enc_params,
+ ITM(rsa_asym_expected_encrypt),
+ ITM(rsa_asym_plaintext_encrypt),
+ },
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_DEC,
+ "RSA",
+ 0,
+ rsa_crt_key,
+ rsa_enc_params,
+ ITM(rsa_asym_expected_encrypt),
+ ITM(rsa_asym_plaintext_encrypt),
+ },
+};
diff --git a/crypto/openssl/providers/fips/self_test_kats.c b/crypto/openssl/providers/fips/self_test_kats.c
index 35ecb43598ee..acb0b85f7343 100644
--- a/crypto/openssl/providers/fips/self_test_kats.c
+++ b/crypto/openssl/providers/fips/self_test_kats.c
@@ -813,6 +813,93 @@ err:
#endif
/*
+ * Test an encrypt or decrypt KAT..
+ *
+ * FIPS 140-2 IG D.9 states that separate KAT tests are needed for encrypt
+ * and decrypt..
+ */
+static int self_test_asym_cipher(const ST_KAT_ASYM_CIPHER *t, OSSL_SELF_TEST *st,
+ OSSL_LIB_CTX *libctx)
+{
+ int ret = 0;
+ OSSL_PARAM *keyparams = NULL, *initparams = NULL;
+ OSSL_PARAM_BLD *keybld = NULL, *initbld = NULL;
+ EVP_PKEY_CTX *encctx = NULL, *keyctx = NULL;
+ EVP_PKEY *key = NULL;
+ BN_CTX *bnctx = NULL;
+ unsigned char out[256];
+ size_t outlen = sizeof(out);
+
+ OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_ASYM_CIPHER, t->desc);
+
+ bnctx = BN_CTX_new_ex(libctx);
+ if (bnctx == NULL)
+ goto err;
+
+ /* Load a public or private key from data */
+ keybld = OSSL_PARAM_BLD_new();
+ if (keybld == NULL
+ || !add_params(keybld, t->key, bnctx))
+ goto err;
+ keyparams = OSSL_PARAM_BLD_to_param(keybld);
+ keyctx = EVP_PKEY_CTX_new_from_name(libctx, t->algorithm, NULL);
+ if (keyctx == NULL || keyparams == NULL)
+ goto err;
+ if (EVP_PKEY_fromdata_init(keyctx) <= 0
+ || EVP_PKEY_fromdata(keyctx, &key, EVP_PKEY_KEYPAIR, keyparams) <= 0)
+ goto err;
+
+ /* Create a EVP_PKEY_CTX to use for the encrypt or decrypt operation */
+ encctx = EVP_PKEY_CTX_new_from_pkey(libctx, key, NULL);
+ if (encctx == NULL
+ || (t->encrypt && EVP_PKEY_encrypt_init(encctx) <= 0)
+ || (!t->encrypt && EVP_PKEY_decrypt_init(encctx) <= 0))
+ goto err;
+
+ /* Add any additional parameters such as padding */
+ if (t->postinit != NULL) {
+ initbld = OSSL_PARAM_BLD_new();
+ if (initbld == NULL)
+ goto err;
+ if (!add_params(initbld, t->postinit, bnctx))
+ goto err;
+ initparams = OSSL_PARAM_BLD_to_param(initbld);
+ if (initparams == NULL)
+ goto err;
+ if (EVP_PKEY_CTX_set_params(encctx, initparams) <= 0)
+ goto err;
+ }
+
+ if (t->encrypt) {
+ if (EVP_PKEY_encrypt(encctx, out, &outlen,
+ t->in, t->in_len) <= 0)
+ goto err;
+ } else {
+ if (EVP_PKEY_decrypt(encctx, out, &outlen,
+ t->in, t->in_len) <= 0)
+ goto err;
+ }
+ /* Check the KAT */
+ OSSL_SELF_TEST_oncorrupt_byte(st, out);
+ if (outlen != t->expected_len
+ || memcmp(out, t->expected, t->expected_len) != 0)
+ goto err;
+
+ ret = 1;
+err:
+ BN_CTX_free(bnctx);
+ EVP_PKEY_free(key);
+ EVP_PKEY_CTX_free(encctx);
+ EVP_PKEY_CTX_free(keyctx);
+ OSSL_PARAM_free(keyparams);
+ OSSL_PARAM_BLD_free(keybld);
+ OSSL_PARAM_free(initparams);
+ OSSL_PARAM_BLD_free(initbld);
+ OSSL_SELF_TEST_onend(st, ret);
+ return ret;
+}
+
+/*
* Test a data driven list of KAT's for digest algorithms.
* All tests are run regardless of if they fail or not.
* Return 0 if any test fails.
@@ -853,6 +940,17 @@ static int self_test_kems(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
return ret;
}
+static int self_test_asym_ciphers(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
+{
+ int i, ret = 1;
+
+ for (i = 0; i < (int)OSSL_NELEM(st_kat_asym_cipher_tests); ++i) {
+ if (!self_test_asym_cipher(&st_kat_asym_cipher_tests[i], st, libctx))
+ ret = 0;
+ }
+ return ret;
+}
+
static int self_test_kdfs(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
{
int i, ret = 1;
@@ -1092,6 +1190,8 @@ int SELF_TEST_kats(OSSL_SELF_TEST *st, OSSL_LIB_CTX *libctx)
ret = 0;
if (!self_test_kems(st, libctx))
ret = 0;
+ if (!self_test_asym_ciphers(st, libctx))
+ ret = 0;
RAND_set0_private(libctx, saved_rand);
return ret;