]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
fips: upgrade self-test KATs to reduce SHA-1/SHA-224 usage
authorDimitri John Ledkov <dimitri.ledkov@surgut.co.uk>
Wed, 20 Aug 2025 01:26:09 +0000 (02:26 +0100)
committerPauli <ppzgs1@gmail.com>
Thu, 21 Aug 2025 03:03:54 +0000 (13:03 +1000)
FIPS 140-3 IG states that SHA-224 needs standalone KAT, if it is
implemented without SHA-256. As OpenSSL implements SHA-256, upgrade
existing higher level KAT from SHA-224 to SHA-256 without adding
SHA-224 digest KAT.

Upgrade KATs that use SHA-1 to SHA-256, and add explicit SHA-1 KAT.

SHA-1 and SHA-224 are promised to be deprecated by 2030, as per draft
[NIST SP 800-131A Rev. 3](https://csrc.nist.gov/pubs/sp/800/131/a/r3/ipd).

With upgrades to these KATs it makes it easier to build a modules with
SHA-1 and SHA-224 marked as unapproved services, or removed
altogether.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28307)

providers/fips/self_test_data.inc

index fd81cf0d9384b5dd386978b49373e83c6232e286..ee15947a3b2af9b636dc0f7e41ece62160f031a4 100644 (file)
@@ -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,11 +193,17 @@ 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",
@@ -484,7 +496,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,
@@ -503,8 +515,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),
@@ -513,7 +525,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,
@@ -521,8 +533,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),
@@ -929,51 +941,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[] =
@@ -1004,15 +1038,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)
     }
 };