Skip to content

Commit b455461

Browse files
committed
tests: expect the FIPS v7 ECDH curve refusal (from #11359)
1 parent b358ee3 commit b455461

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎tests/api/test_ecc.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,13 @@ int test_wc_ecc_shared_secret_at_infinity(void)
808808
EXPECT_DECLS;
809809
#ifdef TEST_ECC_SHARED_SECRET_AT_INFINITY
810810
#if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && \
811-
(ECC_MIN_KEY_SZ <= 224) && !defined(WOLFSSL_SP_MATH)
811+
(ECC_MIN_KEY_SZ <= 224) && !defined(WOLFSSL_SP_MATH) && \
812+
!(FIPS_VERSION3_GE(7,0,0) && defined(WC_HAVE_FIPS_INDICATOR) && \
813+
!defined(FIPS_NO_WRAPPERS))
812814
/* secp224r1 is not single precision accelerated, so this drives the
813-
* software ECDH path even in SP builds that offload P-256. */
815+
* software ECDH path even in SP builds that offload P-256. The v7
816+
* module refuses ECDH on P-224 (outside its KAS-ECC-SSC curve set), so
817+
* there the P-256 case below carries the identity check. */
814818
ExpectIntEQ(ecc_shared_secret_inf_case(
815819
"b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21",
816820
"bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34",

‎wolfcrypt/test/test.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54685,6 +54685,7 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5468554685
WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
5468654686
WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
5468754687
word32 y;
54688+
int doEcdh = 1;
5468854689
#endif
5468954690
#ifndef WC_NO_RNG
5469054691
#ifdef HAVE_ECC_KEY_EXPORT
@@ -54854,7 +54855,27 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5485454855
if (ret != 0)
5485554856
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
5485654857
#endif
54858+
#if FIPS_VERSION3_GE(7,0,0) && defined(WC_HAVE_FIPS_INDICATOR) && \
54859+
!defined(FIPS_NO_WRAPPERS)
54860+
/* v7 refuses ECDH outside P-256, P-384 and P-521: expect the refusal and
54861+
* skip only the shared secret steps for this curve. */
54862+
if (userA->dp != NULL &&
54863+
userA->dp->id != ECC_SECP256R1 &&
54864+
userA->dp->id != ECC_SECP384R1 &&
54865+
userA->dp->id != ECC_SECP521R1) {
54866+
x = ECC_SHARED_SIZE;
54867+
PRIVATE_KEY_UNLOCK();
54868+
ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
54869+
PRIVATE_KEY_LOCK();
54870+
if (ret != WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
54871+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
54872+
ret = 0;
54873+
doEcdh = 0;
54874+
}
54875+
#endif
5485754876

54877+
if (doEcdh)
54878+
{
5485854879
x = ECC_SHARED_SIZE;
5485954880
PRIVATE_KEY_UNLOCK();
5486054881
do {
@@ -54932,6 +54953,7 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5493254953
wc_ecc_set_flags(userA, 0);
5493354954
wc_ecc_set_flags(userB, 0);
5493454955
#endif /* HAVE_ECC_CDH */
54956+
}
5493554957
#endif /* HAVE_ECC_DHE */
5493654958
#endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
5493754959

@@ -54962,6 +54984,8 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5496254984
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
5496354985
!defined(WOLFSSL_MICROCHIP_TA100)
5496454986
#ifdef HAVE_ECC_DHE
54987+
if (doEcdh)
54988+
{
5496554989
y = ECC_SHARED_SIZE;
5496654990
PRIVATE_KEY_UNLOCK();
5496754991
do {
@@ -54978,6 +55002,7 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5497855002
if (XMEMCMP(sharedA, sharedB, y))
5497955003
ERROR_OUT(WC_TEST_RET_ENC_NC, done);
5498055004
TEST_SLEEP();
55005+
}
5498155006
#endif /* HAVE_ECC_DHE */
5498255007

5498355008
#ifdef HAVE_COMP_KEY
@@ -55015,6 +55040,8 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5501555040
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
5501655041

5501755042
#ifdef HAVE_ECC_DHE
55043+
if (doEcdh)
55044+
{
5501855045
y = ECC_SHARED_SIZE;
5501955046
PRIVATE_KEY_UNLOCK();
5502055047
do {
@@ -55031,6 +55058,7 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
5503155058
if (XMEMCMP(sharedA, sharedB, y))
5503255059
ERROR_OUT(WC_TEST_RET_ENC_NC, done);
5503355060
TEST_SLEEP();
55061+
}
5503455062
#endif /* HAVE_ECC_DHE */
5503555063
}
5503655064
#endif /* HAVE_COMP_KEY */

0 commit comments

Comments
 (0)