Skip to content

Commit 3e6a2f1

Browse files
committed
test/:
* fixes for NO_DH; * fixes in test_wc_ed448_import_public() and test_wc_Ed448DecisionCoverage() for FIPS v6; * fixes in tests/api/test_sha3.c for KMAC keysize in FIPS builds.
1 parent 8c40ca7 commit 3e6a2f1

5 files changed

Lines changed: 55 additions & 2 deletions

File tree

tests/api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30039,17 +30039,21 @@ static int test_wolfSSL_crypto_policy_ciphers(void)
3003930039
found = crypto_policy_cipher_found(ssl, "AES_128", 0);
3004030040
ExpectIntEQ(found, !is_future);
3004130041

30042+
#ifndef NO_DH
3004230043
found = crypto_policy_cipher_found(ssl, "TLS_DHE_RSA_WITH_AES", 1);
3004330044
ExpectIntEQ(found, !is_future);
30045+
#endif
3004430046

3004530047
found = crypto_policy_cipher_found(ssl, "_SHA", -1);
3004630048
ExpectIntEQ(found, !is_future);
3004730049
#else
3004830050
found = crypto_policy_cipher_found(ssl, "AES128", 0);
3004930051
ExpectIntEQ(found, !is_future);
3005030052

30053+
#ifndef NO_DH
3005130054
found = crypto_policy_cipher_found(ssl, "DHE-RSA-AES", 1);
3005230055
ExpectIntEQ(found, !is_future);
30056+
#endif
3005330057

3005430058
found = crypto_policy_cipher_found(ssl, "-SHA", -1);
3005530059
ExpectIntEQ(found, !is_future);

tests/api/test_dtls.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,28 @@ int test_dtls12_basic_connection_id(void)
6363
#endif
6464
#endif /* WOLFSSL_AES_128 && WOLFSSL_STATIC_RSA */
6565
#if defined(WOLFSSL_AES_128)
66+
#ifndef NO_DH
6667
"DHE-RSA-AES128-SHA256",
68+
#endif
6769
"ECDHE-RSA-AES128-SHA256",
6870
#ifdef HAVE_AESGCM
71+
#ifndef NO_DH
6972
"DHE-RSA-AES128-GCM-SHA256",
73+
#endif
7074
"ECDHE-RSA-AES128-GCM-SHA256",
7175
#endif
7276
#endif /* WOLFSSL_AES_128 */
7377
#endif /* NO_SHA256 */
7478
#endif /* NO_RSA */
7579
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(HAVE_FIPS)
80+
#ifndef NO_DH
7681
"DHE-RSA-CHACHA20-POLY1305",
7782
"DHE-RSA-CHACHA20-POLY1305-OLD",
83+
#endif
7884
"ECDHE-RSA-CHACHA20-POLY1305",
7985
"ECDHE-RSA-CHACHA20-POLY1305-OLD",
8086
#endif
87+
#ifndef NO_DH
8188
#ifndef NO_PSK
8289
"DHE-PSK-AES128-CBC-SHA256",
8390
#ifdef WOLFSSL_AES_256
@@ -88,6 +95,7 @@ int test_dtls12_basic_connection_id(void)
8895
#endif
8996
"DHE-PSK-AES128-CCM",
9097
#endif
98+
#endif /* !NO_DH */
9199
};
92100
size_t i;
93101
struct {

tests/api/test_ed448.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ int test_wc_ed448_import_public(void)
253253
ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey),
254254
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
255255

256+
#if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)
256257
/* MC/DC: wc_ed448_import_public_ex()'s tri-state length check
257258
* (inLen != PUB_KEY_SIZE && inLen != PUB_KEY_SIZE+1 &&
258259
* inLen != 2*PUB_KEY_SIZE+1) -- close the third operand's FALSE side
@@ -297,6 +298,7 @@ int test_wc_ed448_import_public(void)
297298
ExpectIntEQ(wc_ed448_import_public_ex(uncompressed,
298299
ED448_PUB_KEY_SIZE, &pubKey, 1), 0);
299300
}
301+
#endif
300302

301303
DoExpectIntEQ(wc_FreeRng(&rng), 0);
302304
wc_ed448_free(&pubKey);
@@ -1089,6 +1091,7 @@ int test_wc_Ed448DecisionCoverage(void)
10891091
&key, NULL, 0), 0);
10901092
ExpectIntEQ(verify, 1);
10911093

1094+
#if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)
10921095
/* type == Ed448ph && inLen != ED448_PREHASH_SIZE -> BAD_LENGTH_E
10931096
* (sign_hash forwards hashLen as inLen with type Ed448ph). */
10941097
sigLen = sizeof(sig);
@@ -1103,6 +1106,7 @@ int test_wc_Ed448DecisionCoverage(void)
11031106
* TRUE, msgLen != PREHASH_SIZE FALSE) for the length operand. */
11041107
ExpectIntEQ(wc_ed448ph_verify_hash(sig, sigLen, badhash, sizeof(badhash),
11051108
&verify, &key, NULL, 0), WC_NO_ERR_TRACE(BAD_LENGTH_E));
1109+
#endif
11061110

11071111
DoExpectIntEQ(wc_FreeRng(&rng), 0);
11081112
wc_ed448_free(&key);

tests/api/test_evp_pkey.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,8 @@ int test_wolfSSL_EVP_PKEY_print_public(void)
24982498
/*
24992499
* test DH public key print
25002500
*/
2501-
#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
2501+
#if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
2502+
defined(USE_CERT_BUFFERS_2048)
25022503

25032504
ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
25042505
sizeof_dh_pub_key_der_2048));
@@ -2555,7 +2556,7 @@ int test_wolfSSL_EVP_PKEY_print_public(void)
25552556
rbio = NULL;
25562557
wbio = NULL;
25572558

2558-
#endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
2559+
#endif /* !NO_DH && WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
25592560

25602561
/* to prevent "unused variable" warning */
25612562
(void)pkey;

tests/api/test_sha3.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,16 @@ int test_wc_Kmac128_api(void)
18691869
EXPECT_DECLS;
18701870
#ifdef WOLFSSL_KMAC128
18711871
wc_Kmac kmac;
1872+
#ifdef HAVE_FIPS
1873+
static const byte key[KMAC_FIPS_MIN_KEY] =
1874+
{ 0x00, 0x01, 0x02, 0x03,
1875+
0x00, 0x01, 0x02, 0x03,
1876+
0x00, 0x01, 0x02, 0x03,
1877+
0x00, 0x01
1878+
};
1879+
#else
18721880
static const byte key[4] = { 0x00, 0x01, 0x02, 0x03 };
1881+
#endif
18731882
static const byte msg[4] = { 0x00, 0x01, 0x02, 0x03 };
18741883
byte out[200];
18751884
byte out2[200];
@@ -1881,9 +1890,16 @@ int test_wc_Kmac128_api(void)
18811890
INVALID_DEVID), BAD_FUNC_ARG);
18821891
ExpectIntEQ(wc_InitKmac128(&kmac, key, (word32)sizeof(key), NULL, 4,
18831892
HEAP_HINT, INVALID_DEVID), BAD_FUNC_ARG);
1893+
1894+
#ifdef HAVE_FIPS
1895+
ExpectIntEQ(wc_InitKmac128(&kmac, NULL, 0, NULL, 0, HEAP_HINT,
1896+
INVALID_DEVID), KMAC_MIN_KEYLEN_E);
1897+
#else
18841898
/* NULL key with zero length is allowed. */
18851899
ExpectIntEQ(wc_InitKmac128(&kmac, NULL, 0, NULL, 0, HEAP_HINT,
18861900
INVALID_DEVID), 0);
1901+
#endif
1902+
18871903
wc_Kmac128_Free(&kmac);
18881904

18891905
/* wc_Kmac128_Update argument checks. */
@@ -2149,7 +2165,16 @@ int test_wc_Kmac256_api(void)
21492165
EXPECT_DECLS;
21502166
#ifdef WOLFSSL_KMAC256
21512167
wc_Kmac kmac;
2168+
#ifdef HAVE_FIPS
2169+
static const byte key[KMAC_FIPS_MIN_KEY] =
2170+
{ 0x00, 0x01, 0x02, 0x03,
2171+
0x00, 0x01, 0x02, 0x03,
2172+
0x00, 0x01, 0x02, 0x03,
2173+
0x00, 0x01
2174+
};
2175+
#else
21522176
static const byte key[4] = { 0x00, 0x01, 0x02, 0x03 };
2177+
#endif
21532178
static const byte msg[4] = { 0x00, 0x01, 0x02, 0x03 };
21542179
byte out[200];
21552180
byte out2[200];
@@ -2161,8 +2186,10 @@ int test_wc_Kmac256_api(void)
21612186
INVALID_DEVID), BAD_FUNC_ARG);
21622187
ExpectIntEQ(wc_InitKmac256(&kmac, key, (word32)sizeof(key), NULL, 4,
21632188
HEAP_HINT, INVALID_DEVID), BAD_FUNC_ARG);
2189+
#ifndef HAVE_FIPS
21642190
ExpectIntEQ(wc_InitKmac256(&kmac, NULL, 0, NULL, 0, HEAP_HINT,
21652191
INVALID_DEVID), 0);
2192+
#endif
21662193
wc_Kmac256_Free(&kmac);
21672194

21682195
/* wc_Kmac256_Update argument checks. */
@@ -2478,7 +2505,16 @@ int test_wc_Kmac_Copy(void)
24782505
#ifdef WOLFSSL_KMAC128
24792506
wc_Kmac kmac;
24802507
wc_Kmac copy;
2508+
#ifdef HAVE_FIPS
2509+
static const byte key[KMAC_FIPS_MIN_KEY] =
2510+
{ 0x00, 0x01, 0x02, 0x03,
2511+
0x00, 0x01, 0x02, 0x03,
2512+
0x00, 0x01, 0x02, 0x03,
2513+
0x00, 0x01
2514+
};
2515+
#else
24812516
static const byte key[4] = { 0x00, 0x01, 0x02, 0x03 };
2517+
#endif
24822518
static const byte msg[8] = {
24832519
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
24842520
};

0 commit comments

Comments
 (0)