Skip to content

Commit 60cd605

Browse files
committed
wolfcrypt/test/test.c and wolfcrypt/test/test.h:
* add correct gating around pbkdf1_test(), pkcs12_pbkdf_test(), and scrypt_test() prototypes; * add unit tests for wc_PBKDF_max_iterations_set() and wc_PBKDF_max_iterations_get() in pbkdf2_test(); * fix pkcs12_test() to skip the evilPkcs12 test if evil_p12 can't be parsed for any reason, mirroring the new stanza around evil_p12 in pwdbased_test().
1 parent 3fa1ee4 commit 60cd605

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,18 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
729729
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
730730
#endif
731731

732+
#if defined(HAVE_PBKDF1) && !defined(NO_SHA)
732733
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
734+
#endif
735+
#if defined(HAVE_PKCS12) && !defined(NO_SHA256)
733736
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
737+
#endif
734738
#if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
735739
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
736740
#endif
741+
#if !defined(NO_PWDBASED) && defined(HAVE_SCRYPT)
737742
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
743+
#endif
738744
#ifdef HAVE_ECC
739745
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
740746
#if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
@@ -30789,7 +30795,31 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
3078930795
if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
3079030796
return WC_TEST_RET_ENC_NC;
3079130797

30792-
return 0;
30798+
{
30799+
int cur_pbkdf_limit = wc_PBKDF_max_iterations_set(iterations - 1);
30800+
if (cur_pbkdf_limit <= 0)
30801+
return WC_TEST_RET_ENC_EC(cur_pbkdf_limit);
30802+
ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
30803+
salt, (int)sizeof(salt), iterations,
30804+
kLen, WC_SHA256, HEAP_HINT, devId);
30805+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
30806+
return WC_TEST_RET_ENC_EC(ret);
30807+
ret = wc_PBKDF_max_iterations_set(-1);
30808+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
30809+
return WC_TEST_RET_ENC_EC(ret);
30810+
ret = wc_PBKDF_max_iterations_set(0);
30811+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
30812+
return WC_TEST_RET_ENC_EC(ret);
30813+
ret = wc_PBKDF_max_iterations_get();
30814+
if (ret != iterations - 1)
30815+
return WC_TEST_RET_ENC_NC;
30816+
ret = wc_PBKDF_max_iterations_set(cur_pbkdf_limit);
30817+
if (ret != iterations - 1)
30818+
return WC_TEST_RET_ENC_EC(ret);
30819+
ret = 0;
30820+
}
30821+
30822+
return ret;
3079330823

3079430824
}
3079530825
#endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
@@ -31014,12 +31044,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
3101431044
goto out;
3101531045
}
3101631046
ret = wc_d2i_PKCS12(evil_p12, (word32)sizeof(evil_p12), evilPkcs12);
31017-
if (ret != 0) {
31018-
wc_PKCS12_free(evilPkcs12);
31019-
ret = WC_TEST_RET_ENC_EC(ret);
31020-
goto out;
31021-
}
31022-
{
31047+
if (ret == 0) {
3102331048
byte* evilKey = NULL;
3102431049
byte* evilCert = NULL;
3102531050
word32 evilKeySz = 0, evilCertSz = 0;
@@ -31030,14 +31055,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
3103031055
XFREE(evilCert, HEAP_HINT, DYNAMIC_TYPE_PKCS);
3103131056
if (evilCa)
3103231057
wc_FreeCertList(evilCa, HEAP_HINT);
31058+
wc_PKCS12_free(evilPkcs12);
31059+
/* Must have been rejected (not hung) */
31060+
if (ret == 0) {
31061+
ret = WC_TEST_RET_ENC_NC;
31062+
goto out;
31063+
}
31064+
ret = 0; /* rejection is the expected outcome */
3103331065
}
31034-
wc_PKCS12_free(evilPkcs12);
31035-
/* Must have been rejected (not hung) */
31036-
if (ret == 0) {
31037-
ret = WC_TEST_RET_ENC_NC;
31038-
goto out;
31039-
}
31040-
ret = 0; /* rejection is the expected outcome */
3104131066
}
3104231067

3104331068
out:

wolfcrypt/test/test.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,18 @@ extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
262262
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
263263
#endif
264264

265+
#if defined(HAVE_PBKDF1) && !defined(NO_SHA)
265266
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
267+
#endif
268+
#if defined(HAVE_PKCS12) && !defined(NO_SHA256)
266269
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
270+
#endif
267271
#if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
268272
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
269273
#endif
274+
#if !defined(NO_PWDBASED) && defined(HAVE_SCRYPT)
270275
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
276+
#endif
271277
#ifdef HAVE_ECC
272278
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
273279
#if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \

0 commit comments

Comments
 (0)