Skip to content

Commit 5b28299

Browse files
adjust test case for CI tests after additional sanity check
1 parent 915c59c commit 5b28299

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

tests/api/test_evp_cipher.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ int test_wolfssl_EVP_sm4_ecb(void)
21952195
};
21962196
byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
21972197
byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
2198-
EVP_CIPHER_CTX* ctx;
2198+
EVP_CIPHER_CTX* ctx = NULL;
21992199
int outSz;
22002200

22012201
XMEMSET(key, 0, sizeof(key));
@@ -2251,7 +2251,7 @@ int test_wolfssl_EVP_sm4_cbc(void)
22512251
};
22522252
byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
22532253
byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
2254-
EVP_CIPHER_CTX* ctx;
2254+
EVP_CIPHER_CTX* ctx = NULL;
22552255
int outSz;
22562256

22572257
XMEMSET(key, 0, sizeof(key));
@@ -2319,7 +2319,7 @@ int test_wolfssl_EVP_sm4_ctr(void)
23192319
byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
23202320
byte cipherText[sizeof(plainText)];
23212321
byte decryptedText[sizeof(plainText)];
2322-
EVP_CIPHER_CTX* ctx;
2322+
EVP_CIPHER_CTX* ctx = NULL;
23232323
int outSz;
23242324

23252325
XMEMSET(key, 0, sizeof(key));

wolfcrypt/test/test.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36413,7 +36413,12 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
3641336413
#if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
3641436414
!defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
3641536415
#ifdef HAVE_ECC_SIGN
36416-
/* test DSA sign hash with zeros */
36416+
/* WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST: build rejects all-zero digest,
36417+
* so test expects failure. */
36418+
#ifdef WOLFSSL_SM2
36419+
if (curve_id != ECC_SM2P256V1)
36420+
#endif
36421+
{
3641736422
for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
3641836423
digest[i] = 0;
3641936424
}
@@ -36427,13 +36432,17 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
3642736432
ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
3642836433
userA);
3642936434
} while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
36435+
#ifdef WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST
3643036436
if (ret == 0) {
3643136437
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
3643236438
}
3643336439
else {
36434-
/* reset ret value, was expecting a failure */
3643536440
ret = 0;
3643636441
}
36442+
#else
36443+
if (ret != 0)
36444+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
36445+
#endif
3643736446
TEST_SLEEP();
3643836447

3643936448
#ifdef HAVE_ECC_VERIFY
@@ -36446,17 +36455,24 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif
3644636455
ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
3644736456
&verify, userA);
3644836457
} while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
36458+
#ifdef WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST
3644936459
if (ret == 0) {
3645036460
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
3645136461
}
3645236462
else {
36453-
/* reset ret value, was expecting a failure */
3645436463
ret = 0;
3645536464
}
3645636465
if (verify == 1)
3645736466
ERROR_OUT(WC_TEST_RET_ENC_NC, done);
36467+
#else
36468+
if (ret != 0)
36469+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
36470+
if (verify != 1)
36471+
ERROR_OUT(WC_TEST_RET_ENC_NC, done);
36472+
#endif
3645836473
TEST_SLEEP();
3645936474
#endif /* HAVE_ECC_VERIFY */
36475+
}
3646036476

3646136477
/* test DSA sign hash with sequence (0,1,2,3,4,...) */
3646236478
for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {

wolfssl/wolfcrypt/settings.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,20 @@ extern void uITRON4_free(void *p) ;
35093509
#undef NO_DH
35103510
#endif
35113511

3512+
/* Base wolfCrypt rejects an all-zero ECC digest on sign/verify. Builds whose
3513+
* sign/verify path can't enforce that (HW offload firmware) */
3514+
#if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && \
3515+
!defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
3516+
#define WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST
3517+
#if defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050) || \
3518+
defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
3519+
defined(WOLFSSL_KCAPI_ECC) || defined(WOLFSSL_SILABS_SE_ACCEL) || \
3520+
defined(WOLFSSL_XILINX_CRYPT_VERSAL) || defined(PLUTON_CRYPTO_ECC) || \
3521+
(defined(HAVE_FIPS) && FIPS_VERSION3_LT(7,0,0))
3522+
#undef WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST
3523+
#endif
3524+
#endif
3525+
35123526
/* Asynchronous Crypto */
35133527
#ifdef WOLFSSL_ASYNC_CRYPT
35143528
#if !defined(HAVE_CAVIUM) && !defined(HAVE_INTEL_QA) && \

0 commit comments

Comments
 (0)