]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
SLH-DSA fixup tests to adjust the private key getter returning the
authorslontis <shane.lontis@oracle.com>
Thu, 20 Feb 2025 02:39:48 +0000 (13:39 +1100)
committerslontis <shane.lontis@oracle.com>
Sat, 22 Feb 2025 10:25:03 +0000 (21:25 +1100)
public component

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26839)

providers/fips/self_test_data.inc
test/slh_dsa.inc
test/slh_dsa_test.c

index c219c47d12317568af34c5cb13cb1910ed4889fb..c3d3e9e961f64ccdc97a24145cc96ad75840340f 100644 (file)
@@ -2859,9 +2859,11 @@ static const uint8_t slh_dsa_sha2_128f_keygen_entropy[] = {
 };
 
 /* The expected outputs for the public and private key elements */
-static const uint8_t slh_dsa_sha2_128f_keygen_priv[] = {
+static const uint8_t slh_dsa_sha2_128f_keygen_priv_pub[] = {
     0xAE, 0xD6, 0xF6, 0xF5, 0xC5, 0x40, 0x8B, 0xBF, 0xFA, 0x11, 0x36, 0xBC, 0x90, 0x49, 0xA7, 0x01,
-    0x4D, 0x4C, 0xE0, 0x71, 0x1E, 0x17, 0x6A, 0x0C, 0x8A, 0x02, 0x35, 0x08, 0xA6, 0x92, 0xC2, 0x07
+    0x4D, 0x4C, 0xE0, 0x71, 0x1E, 0x17, 0x6A, 0x0C, 0x8A, 0x02, 0x35, 0x08, 0xA6, 0x92, 0xC2, 0x07,
+    0x74, 0xD9, 0x8D, 0x50, 0x00, 0xAF, 0x53, 0xB9, 0x8F, 0x36, 0x38, 0x9A, 0x12, 0x92, 0xBE, 0xD3,
+    0xF4, 0xA6, 0x50, 0xC5, 0x6C, 0x42, 0x6F, 0xCF, 0xDB, 0x88, 0xE3, 0x35, 0x54, 0x59, 0x44, 0x0C
 };
 
 static const uint8_t slh_dsa_sha2_128f_keygen_pub[] = {
@@ -2877,7 +2879,7 @@ static const ST_KAT_PARAM slh_dsa_sha2_128f_keygen_init_params[] = {
 
 static const ST_KAT_PARAM slh_dsa_128f_keygen_expected_params[] = {
     ST_KAT_PARAM_OCTET(OSSL_PKEY_PARAM_PRIV_KEY,
-                       slh_dsa_sha2_128f_keygen_priv),
+                       slh_dsa_sha2_128f_keygen_priv_pub),
     ST_KAT_PARAM_OCTET(OSSL_PKEY_PARAM_PUB_KEY,
                        slh_dsa_sha2_128f_keygen_pub),
     ST_KAT_PARAM_END()
index 1d8294f3549bd8575ba118912dd51c70f3dc4a6f..0fa42aed415606bc480b7b0812aeb80e93f77c30 100644 (file)
@@ -9,7 +9,7 @@
 
 #define SLH_DSA_SIG_TEST_DET_ITEM(name, alg) {                                 \
     alg,                                                                       \
-    name##_pub, sizeof(name##_pub),                                            \
+    name##_priv + sizeof(name##_priv) / 2, sizeof(name##_priv) / 2,            \
     name##_priv, sizeof(name##_priv),                                          \
     name##_msg, sizeof(name##_msg),                                            \
     name##_sig_digest, sizeof(name##_sig_digest),                              \
@@ -17,7 +17,7 @@
 
 #define SLH_DSA_SIG_TEST_ITEM(name, alg) {                                     \
     alg,                                                                       \
-    name##_pub, sizeof(name##_pub),                                            \
+    name##_priv + sizeof(name##_priv) / 2, sizeof(name##_priv) / 2,            \
     name##_priv, sizeof(name##_priv),                                          \
     name##_msg, sizeof(name##_msg),                                            \
     name##_sig_digest, sizeof(name##_sig_digest),                              \
@@ -53,16 +53,11 @@ typedef struct slh_dsa_keygen_test_data_st {
 /*
  * Test vectors from
  * usnistgov/ACVP-Server/refs/heads/master/gen-val/json-files/SLH-DSA-sigGen-FIPS205/internalProjection.json
- *
- * Note that the test vectors store the private & public components in one field
- * (e.g sk)
- * The following data separates these fields.
+ * Note that the public key is the second half of the private key.
  */
 static const uint8_t slh_dsa_sha2_128s_0_priv[] = {
     0x62, 0xb1, 0x97, 0x3a, 0x4d, 0xe0, 0x96, 0x3d, 0x74, 0xc1, 0xcb, 0x30, 0xfc, 0x8f, 0x56, 0x75,
     0xcf, 0xc8, 0x48, 0x80, 0xe4, 0xf0, 0xe1, 0xb4, 0x46, 0xb4, 0xf5, 0xd1, 0x3b, 0x2d, 0x31, 0xcc,
-};
-static const uint8_t slh_dsa_sha2_128s_0_pub[] = {
     0xcb, 0x23, 0xeb, 0x45, 0x52, 0x9e, 0x00, 0xd5, 0xf5, 0xe9, 0x51, 0x50, 0x7a, 0x9b, 0x90, 0xe9,
     0x8b, 0x6e, 0x7a, 0x28, 0x4b, 0xa3, 0xf6, 0x3a, 0x69, 0xe6, 0x9a, 0x78, 0x90, 0x83, 0xbe, 0xf6,
 };
@@ -78,8 +73,6 @@ static const uint8_t slh_dsa_sha2_192f_0_priv[] = {
     0xc1, 0x0a, 0xdc, 0x69, 0x2b, 0x76, 0xff, 0x6f, 0x34, 0xa6, 0xf0, 0xc8, 0xff, 0xe2, 0xbb, 0x88,
     0xe8, 0x41, 0xeb, 0xd9, 0x2d, 0xa7, 0xff, 0xec, 0xdd, 0x3b, 0xf6, 0xc1, 0x05, 0x66, 0xa0, 0xcf,
     0x69, 0x8e, 0x39, 0x3d, 0xfb, 0x84, 0x58, 0x7d, 0x3b, 0xc8, 0xc7, 0xde, 0x58, 0x69, 0x66, 0x8c,
-};
-static const uint8_t slh_dsa_sha2_192f_0_pub[] = {
     0x36, 0xf7, 0xaa, 0x6b, 0x6f, 0x82, 0xa7, 0xf3, 0xc1, 0x09, 0xe8, 0x81, 0x73, 0xa1, 0xe5, 0xf4,
     0x0f, 0xa5, 0x29, 0xa2, 0x9f, 0x48, 0x5c, 0xcb, 0x40, 0xbb, 0x24, 0x7b, 0x9c, 0xba, 0xda, 0x95,
     0x83, 0x92, 0x42, 0x5b, 0xff, 0x8b, 0x20, 0x28, 0x9b, 0x0f, 0x11, 0xaa, 0x3a, 0x51, 0x4e, 0x54,
@@ -98,8 +91,6 @@ static const uint8_t slh_dsa_sha2_256f_0_priv[] = {
     0xe8, 0xc5, 0xad, 0x9c, 0xfe, 0xab, 0x75, 0x1b, 0x1d, 0x92, 0x11, 0x6c, 0x81, 0xd6, 0xf5, 0x2c,
     0xb0, 0x10, 0x08, 0x63, 0x37, 0xe5, 0xfb, 0x27, 0xe6, 0x74, 0xc7, 0xf6, 0xee, 0x14, 0x4c, 0xec,
     0x10, 0xee, 0xf8, 0x87, 0x80, 0xf1, 0x0f, 0x0c, 0xf3, 0xf7, 0x43, 0xc8, 0xb7, 0xdb, 0x15, 0xce,
-};
-static const uint8_t slh_dsa_sha2_256f_0_pub[] = {
     0x03, 0x90, 0xbf, 0x5e, 0xcc, 0x8f, 0xf5, 0xa0, 0x07, 0x23, 0x6c, 0x56, 0xbf, 0x9d, 0x9d, 0x46,
     0xa3, 0x53, 0x4e, 0x54, 0x58, 0x36, 0xcf, 0x7a, 0xdf, 0x20, 0x0d, 0xd2, 0x86, 0x2f, 0x91, 0x1b,
     0x74, 0x09, 0x5e, 0x73, 0xe6, 0x36, 0x41, 0xfa, 0xb2, 0x6b, 0xd7, 0x17, 0xab, 0x29, 0xbb, 0x1e,
@@ -116,8 +107,6 @@ static const uint8_t slh_dsa_sha2_256f_0_sig_digest[] = {
 static const uint8_t slh_dsa_shake_128s_0_priv[] = {
     0x4c, 0xf2, 0xbb, 0xc4, 0x7b, 0x14, 0x51, 0x80, 0xd1, 0xee, 0xa2, 0x98, 0x0c, 0xfb, 0xe2, 0xdc,
     0xc4, 0xf0, 0x70, 0xaf, 0x5b, 0xaf, 0x81, 0xab, 0x2e, 0xae, 0x38, 0x14, 0x4c, 0x35, 0x76, 0xa5,
-};
-static const uint8_t slh_dsa_shake_128s_0_pub[] = {
     0x10, 0x96, 0xaa, 0x01, 0x4c, 0x35, 0x03, 0x02, 0xe1, 0x96, 0x31, 0x7e, 0x0d, 0xbf, 0xb2, 0x91,
     0xd2, 0x4e, 0x52, 0x92, 0x09, 0xde, 0xb4, 0x97, 0x03, 0xcc, 0x3a, 0xd2, 0x9d, 0xfc, 0xe2, 0x4d,
 };
@@ -132,8 +121,6 @@ static const uint8_t slh_dsa_shake_256f_0_priv[] = {
     0x23, 0x92, 0x9d, 0xae, 0xeb, 0x86, 0x44, 0xe7, 0xe5, 0xbd, 0xb9, 0x4d, 0xf0, 0x0a, 0x8e, 0x48,
     0xa4, 0xee, 0x88, 0x08, 0xd9, 0x5d, 0x81, 0x1a, 0x10, 0x55, 0xe0, 0xb1, 0xba, 0x89, 0xe0, 0x8b,
     0xbd, 0xf7, 0x2b, 0xe2, 0x91, 0x2e, 0x2b, 0x7f, 0x6b, 0xf9, 0x73, 0xa6, 0x55, 0xcd, 0x5b, 0x1b,
-};
-static const uint8_t slh_dsa_shake_256f_0_pub[] = {
     0xf6, 0x62, 0x20, 0x15, 0x24, 0x3a, 0xbd, 0x05, 0x3b, 0x45, 0x63, 0xb9, 0x16, 0xa8, 0xf3, 0x7c,
     0x67, 0xa6, 0xe3, 0x0a, 0xd1, 0xc8, 0x5d, 0x65, 0xed, 0x7d, 0x3c, 0xcf, 0x53, 0xd0, 0x8f, 0x27,
     0xde, 0xea, 0x9d, 0x3e, 0x58, 0xe4, 0xc1, 0x86, 0xb3, 0x75, 0x70, 0x11, 0x0f, 0x35, 0xd5, 0xd4,
@@ -148,8 +135,6 @@ static const uint8_t slh_dsa_shake_256f_0_sig_digest[] = {
 static const uint8_t slh_dsa_shake_128f_0_priv[] = {
     0x75, 0x10, 0x49, 0x1b, 0x47, 0x0a, 0xe3, 0x65, 0x8e, 0xd5, 0x0a, 0xd7, 0xa4, 0xe6, 0xc5, 0x8c,
     0x86, 0x33, 0x67, 0x42, 0xc3, 0x24, 0x4b, 0x95, 0xaa, 0x33, 0x8b, 0x70, 0x89, 0xdf, 0x84, 0xb8,
-};
-static const uint8_t slh_dsa_shake_128f_0_pub[] = {
     0x3d, 0x17, 0x30, 0x69, 0x3a, 0xdd, 0xc8, 0x9b, 0xf7, 0xb8, 0x1e, 0x32, 0x13, 0x6a, 0x28, 0xc6,
     0xec, 0x8d, 0x96, 0xc4, 0x6d, 0x3b, 0xbe, 0x28, 0x12, 0xa5, 0x5b, 0x98, 0xe3, 0x89, 0x26, 0xae,
 };
index 561a7171effbc9d50073a4960006092f81aa1845..0efee5daccc3a66e25ea847bdfca08abaa421c68 100644 (file)
@@ -322,13 +322,13 @@ static int slh_dsa_keygen_test(int tst_id)
     int ret = 0;
     const SLH_DSA_KEYGEN_TEST_DATA *tst = &slh_dsa_keygen_testdata[tst_id];
     EVP_PKEY *pkey = NULL;
-    uint8_t priv[32 * 2], pub[32 * 2];
+    uint8_t priv[64 * 2], pub[32 * 2];
     size_t priv_len, pub_len;
-    size_t key_len = tst->priv_len / 2;
-    size_t n = key_len / 2;
+    size_t key_len = tst->priv_len;
+    size_t n = key_len / 4;
     int bits = 0, sec_bits = 0, sig_len = 0;
 
-    if (!TEST_ptr(pkey = do_gen_key(tst->name, tst->priv, key_len + n)))
+    if (!TEST_ptr(pkey = do_gen_key(tst->name, tst->priv, key_len - n)))
         goto err;
 
     if (!TEST_true(EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_PRIV_KEY,
@@ -338,7 +338,7 @@ static int slh_dsa_keygen_test(int tst_id)
                                                    pub, sizeof(pub), &pub_len)))
         goto err;
     if (!TEST_true(EVP_PKEY_get_int_param(pkey, OSSL_PKEY_PARAM_BITS, &bits))
-            || !TEST_int_eq(bits, 8 * key_len)
+            || !TEST_int_eq(bits, 8 * 2 * n)
             || !TEST_true(EVP_PKEY_get_int_param(pkey, OSSL_PKEY_PARAM_SECURITY_BITS,
                                                  &sec_bits))
             || !TEST_int_eq(sec_bits, 8 * n)
@@ -349,9 +349,9 @@ static int slh_dsa_keygen_test(int tst_id)
         goto err;
 
     if (!TEST_size_t_eq(priv_len, key_len)
-            || !TEST_size_t_eq(pub_len, key_len))
+            || !TEST_size_t_eq(pub_len, key_len / 2))
         goto err;
-    if (!TEST_mem_eq(pub, pub_len, tst->priv + key_len, key_len))
+    if (!TEST_mem_eq(pub, pub_len, tst->priv + 2 * n, 2 * n))
         goto err;
     ret = 1;
 err: