Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4399,6 +4399,11 @@ if(WOLFSSL_EXAMPLES)
tests/api/test_hash.c
tests/api/test_hmac.c
tests/api/test_cmac.c
tests/api/test_siphash.c
tests/api/test_srp.c
tests/api/test_eccsi.c
tests/api/test_sakke.c
tests/api/test_hpke.c
tests/api/test_kdf.c
tests/api/test_she.c
tests/api/test_des3.c
Expand Down
11 changes: 11 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@
#include <tests/api/test_hash.h>
#include <tests/api/test_hmac.h>
#include <tests/api/test_cmac.h>
#include <tests/api/test_siphash.h>
#include <tests/api/test_srp.h>
#include <tests/api/test_eccsi.h>
#include <tests/api/test_sakke.h>
#include <tests/api/test_hpke.h>
#include <tests/api/test_kdf.h>
#include <tests/api/test_she.h>
#include <tests/api/test_des3.h>
Expand Down Expand Up @@ -37464,6 +37469,12 @@ TEST_CASE testCases[] = {
TEST_HMAC_DECLS,
/* CMAC */
TEST_CMAC_DECLS,
/* SipHash */
TEST_SIPHASH_DECLS,
TEST_SRP_DECLS,
TEST_ECCSI_DECLS,
TEST_SAKKE_DECLS,
TEST_HPKE_DECLS,
/* KDF */
TEST_KDF_DECLS,
/* SHE */
Expand Down
10 changes: 10 additions & 0 deletions tests/api/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ tests_unit_test_SOURCES += tests/api/test_hash.c
# MAC
tests_unit_test_SOURCES += tests/api/test_hmac.c
tests_unit_test_SOURCES += tests/api/test_cmac.c
tests_unit_test_SOURCES += tests/api/test_siphash.c
tests_unit_test_SOURCES += tests/api/test_srp.c
tests_unit_test_SOURCES += tests/api/test_eccsi.c
tests_unit_test_SOURCES += tests/api/test_sakke.c
tests_unit_test_SOURCES += tests/api/test_hpke.c
tests_unit_test_SOURCES += tests/api/test_kdf.c
# SHE
tests_unit_test_SOURCES += tests/api/test_she.c
Expand Down Expand Up @@ -143,6 +148,11 @@ EXTRA_DIST += tests/api/test_digest.h
EXTRA_DIST += tests/api/test_hash.h
EXTRA_DIST += tests/api/test_hmac.h
EXTRA_DIST += tests/api/test_cmac.h
EXTRA_DIST += tests/api/test_siphash.h
EXTRA_DIST += tests/api/test_srp.h
EXTRA_DIST += tests/api/test_eccsi.h
EXTRA_DIST += tests/api/test_sakke.h
EXTRA_DIST += tests/api/test_hpke.h
EXTRA_DIST += tests/api/test_kdf.h
EXTRA_DIST += tests/api/test_she.h
EXTRA_DIST += tests/api/test_des3.h
Expand Down
360 changes: 360 additions & 0 deletions tests/api/test_ascon.c

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion tests/api/test_ascon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
int test_ascon_hash256(void);
int test_ascon_aead128(void);
int test_ascon_aead128_edge_cases(void);
int test_ascon_decision_coverage(void);

#define TEST_ASCON_DECLS \
TEST_DECL_GROUP("ascon", test_ascon_hash256), \
TEST_DECL_GROUP("ascon", test_ascon_aead128), \
TEST_DECL_GROUP("ascon", test_ascon_aead128_edge_cases)
TEST_DECL_GROUP("ascon", test_ascon_aead128_edge_cases), \
TEST_DECL_GROUP("ascon", test_ascon_decision_coverage)

#endif /* TESTS_API_TEST_ASCON_H */
84 changes: 84 additions & 0 deletions tests/api/test_blake2.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,53 @@ int test_wc_Blake2b_other(void)
return EXPECT_RESULT();
}

/* MC/DC decision coverage for the argument-validation bound checks that the
* public wc_* wrappers cannot reach with a bad value on every operand:
* - blake2b_init()/blake2b_init_key() are called directly (bypassing the
* wc_* pre-checks) so the internal outlen and key/keylen guards can be
* exercised with values that a wc_* wrapper would already have rejected.
* - wc_InitBlake2b_WithKey()'s own digestSz bound is exercised by varying
* digestSz while keeping keylen valid (the existing bad-arg test only
* ever calls it with a fixed, valid digestSz).
* - wc_Blake2bFinal()'s sz > BLAKE2B_OUTBYTES side is already covered by
* test_wc_Blake2bFinal(); the sz == 0 side is exercised here by forcing
* digestSz to 0, as if Init had never (successfully) been called. */
int test_wc_blake2b_decision_coverage(void)
{
EXPECT_DECLS;
#ifdef HAVE_BLAKE2B
Blake2b blake;
byte key[BLAKE2B_KEYBYTES];
byte hash[WC_BLAKE2B_DIGEST_SIZE];

XMEMSET(&blake, 0, sizeof(blake));
XMEMSET(key, 0, sizeof(key));
XMEMSET(hash, 0, sizeof(hash));

/* The internal blake2b_init() / blake2b_init_key() outlen and key/keylen
* guards (blake2b.c:125/142/144) are unreachable through the public
* wc_* wrappers (which fully validate digestSz before narrowing to byte),
* and blake2b_init* are non-WOLFSSL_API symbols. They are covered in the
* tests/unit-mcdc/test_blake2b_whitebox.c supplement instead of here, so
* this file links cleanly against the shared library in normal CI. */

/* wc_InitBlake2b_WithKey(): digestSz == 0 || digestSz > OUTBYTES,
* isolated from the keylen truncation check by keeping keylen valid. */
ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, 0, key, BLAKE2B_KEYBYTES),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, BLAKE2B_OUTBYTES + 1, key,
BLAKE2B_KEYBYTES), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, BLAKE2B_OUTBYTES, key,
BLAKE2B_KEYBYTES), 0);

/* wc_Blake2bFinal(): sz == 0 side of "sz == 0 || sz > OUTBYTES". */
XMEMSET(&blake, 0, sizeof(blake));
ExpectIntEQ(wc_Blake2bFinal(&blake, hash, 0),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#endif
return EXPECT_RESULT();
}

/*******************************************************************************
* BLAKE2s
******************************************************************************/
Expand Down Expand Up @@ -579,3 +626,40 @@ int test_wc_Blake2s_other(void)
return EXPECT_RESULT();
}

/* MC/DC decision coverage for the argument-validation bound checks that the
* public wc_* wrappers cannot reach with a bad value on every operand. See
* test_wc_blake2b_decision_coverage() for the rationale; this is the
* BLAKE2s equivalent. */
int test_wc_blake2s_decision_coverage(void)
{
EXPECT_DECLS;
#ifdef HAVE_BLAKE2S
Blake2s blake;
byte key[BLAKE2S_KEYBYTES];
byte hash[WC_BLAKE2S_DIGEST_SIZE];

XMEMSET(&blake, 0, sizeof(blake));
XMEMSET(key, 0, sizeof(key));
XMEMSET(hash, 0, sizeof(hash));

/* Internal blake2s_init()/blake2s_init_key() guards (blake2s.c:122/140/142)
* are unreachable through the public wc_* wrappers and are non-WOLFSSL_API;
* covered in tests/unit-mcdc/test_blake2s_whitebox.c instead. */

/* wc_InitBlake2s_WithKey(): digestSz == 0 || digestSz > OUTBYTES,
* isolated from the keylen truncation check by keeping keylen valid. */
ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, 0, key, BLAKE2S_KEYBYTES),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, BLAKE2S_OUTBYTES + 1, key,
BLAKE2S_KEYBYTES), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, BLAKE2S_OUTBYTES, key,
BLAKE2S_KEYBYTES), 0);

/* wc_Blake2sFinal(): sz == 0 side of "sz == 0 || sz > OUTBYTES". */
XMEMSET(&blake, 0, sizeof(blake));
ExpectIntEQ(wc_Blake2sFinal(&blake, hash, 0),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#endif
return EXPECT_RESULT();
}

8 changes: 6 additions & 2 deletions tests/api/test_blake2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,32 @@ int test_wc_Blake2bUpdate(void);
int test_wc_Blake2bFinal(void);
int test_wc_Blake2b_KATs(void);
int test_wc_Blake2b_other(void);
int test_wc_blake2b_decision_coverage(void);

int test_wc_InitBlake2s(void);
int test_wc_InitBlake2s_WithKey(void);
int test_wc_Blake2sUpdate(void);
int test_wc_Blake2sFinal(void);
int test_wc_Blake2s_KATs(void);
int test_wc_Blake2s_other(void);
int test_wc_blake2s_decision_coverage(void);

#define TEST_BLAKE2B_DECLS \
TEST_DECL_GROUP("blake2b", test_wc_InitBlake2b), \
TEST_DECL_GROUP("blake2b", test_wc_InitBlake2b_WithKey), \
TEST_DECL_GROUP("blake2b", test_wc_Blake2bUpdate), \
TEST_DECL_GROUP("blake2b", test_wc_Blake2bFinal), \
TEST_DECL_GROUP("blake2b", test_wc_Blake2b_KATs), \
TEST_DECL_GROUP("blake2b", test_wc_Blake2b_other)
TEST_DECL_GROUP("blake2b", test_wc_Blake2b_other), \
TEST_DECL_GROUP("blake2b", test_wc_blake2b_decision_coverage)

#define TEST_BLAKE2S_DECLS \
TEST_DECL_GROUP("blake2s", test_wc_InitBlake2s), \
TEST_DECL_GROUP("blake2s", test_wc_InitBlake2s_WithKey), \
TEST_DECL_GROUP("blake2s", test_wc_Blake2sUpdate), \
TEST_DECL_GROUP("blake2s", test_wc_Blake2sFinal), \
TEST_DECL_GROUP("blake2s", test_wc_Blake2s_KATs), \
TEST_DECL_GROUP("blake2s", test_wc_Blake2s_other)
TEST_DECL_GROUP("blake2s", test_wc_Blake2s_other), \
TEST_DECL_GROUP("blake2s", test_wc_blake2s_decision_coverage)

#endif /* WOLFCRYPT_TEST_BLAKE2_H */
5 changes: 4 additions & 1 deletion tests/api/test_camellia.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ int test_wc_CamelliaSetKey(void)
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
NULL), 0);

/* Bad args. */
/* Bad args. MC/DC: exercise each operand of (cam == NULL || key == NULL)
* independently so both short-circuit halves are covered. */
ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_CamelliaSetKey(&camellia, NULL, (word32)sizeof(key32), iv),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#endif
return EXPECT_RESULT();
} /* END test_wc_CameliaSetKey */
Expand Down
70 changes: 70 additions & 0 deletions tests/api/test_des3.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,76 @@ int test_wc_Des3_EcbEncrypt(void)
return EXPECT_RESULT();
} /* END test_wc_Des3_EcbEncrypt */

/*
* MC/DC coverage for the single-DES (wc_Des_*) API. The 3DES tests above never
* touch single DES, leaving the per-operand NULL checks in wc_Des_CbcEncrypt /
* wc_Des_CbcDecrypt / wc_Des_EcbEncrypt and the (des && iv) decision in
* wc_Des_SetIV uncovered. Exercise each operand's independence pair plus a
* round trip.
*/
int test_wc_Des_CbcEncryptDecrypt(void)
{
EXPECT_DECLS;
#ifndef NO_DES3
Des des;
byte cipher[DES_BLOCK_SIZE];
byte plain[DES_BLOCK_SIZE];
const byte key[DES_BLOCK_SIZE] =
{ 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
const byte iv[DES_BLOCK_SIZE] =
{ 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
const byte vector[DES_BLOCK_SIZE] =
{ 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74 };

XMEMSET(&des, 0, sizeof(Des));
XMEMSET(cipher, 0, sizeof(cipher));
XMEMSET(plain, 0, sizeof(plain));

ExpectIntEQ(wc_Des_SetKey(&des, key, iv, DES_ENCRYPTION), 0);

/* wc_Des_CbcEncrypt: each operand of (des == NULL || out == NULL ||
* in == NULL) driven false individually so all three short-circuit halves
* are covered. */
ExpectIntEQ(wc_Des_CbcEncrypt(NULL, cipher, vector, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_CbcEncrypt(&des, NULL, vector, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_CbcEncrypt(&des, cipher, vector, sizeof(vector)), 0);

/* wc_Des_CbcDecrypt: same three operands + round-trip check. */
ExpectIntEQ(wc_Des_CbcDecrypt(NULL, plain, cipher, sizeof(cipher)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_CbcDecrypt(&des, NULL, cipher, sizeof(cipher)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_CbcDecrypt(&des, plain, NULL, sizeof(cipher)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_SetKey(&des, key, iv, DES_DECRYPTION), 0);
ExpectIntEQ(wc_Des_CbcDecrypt(&des, plain, cipher, sizeof(cipher)), 0);
ExpectBufEQ(plain, vector, sizeof(vector));

#ifdef WOLFSSL_DES_ECB
/* wc_Des_EcbEncrypt: same three operands + a good case. */
ExpectIntEQ(wc_Des_EcbEncrypt(NULL, cipher, vector, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_EcbEncrypt(&des, NULL, vector, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_EcbEncrypt(&des, cipher, NULL, sizeof(vector)),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(wc_Des_EcbEncrypt(&des, cipher, vector, sizeof(vector)), 0);
#endif

/* wc_Des_SetIV: (des && iv) both operands. True case, then each half
* driven false (des == NULL, then iv == NULL). Returns void; called for
* decision coverage only. */
wc_Des_SetIV(&des, iv);
wc_Des_SetIV(NULL, iv);
wc_Des_SetIV(&des, NULL);
#endif
return EXPECT_RESULT();
} /* END test_wc_Des_CbcEncryptDecrypt */


#include <wolfssl/wolfcrypt/random.h>

Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_des3.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int test_wc_Des3_SetKey(void);
int test_wc_Des3_CbcEncryptDecrypt(void);
int test_wc_Des3_CbcEncryptDecrypt_no_key(void);
int test_wc_Des3_EcbEncrypt(void);
int test_wc_Des_CbcEncryptDecrypt(void);
int test_wc_Des3Cbc_MonteCarlo(void);

#define TEST_DES3_DECLS \
Expand All @@ -37,6 +38,7 @@ int test_wc_Des3Cbc_MonteCarlo(void);
TEST_DECL_GROUP("des3", test_wc_Des3_CbcEncryptDecrypt), \
TEST_DECL_GROUP("des3", test_wc_Des3_CbcEncryptDecrypt_no_key), \
TEST_DECL_GROUP("des3", test_wc_Des3_EcbEncrypt), \
TEST_DECL_GROUP("des3", test_wc_Des_CbcEncryptDecrypt), \
TEST_DECL_GROUP("des3", test_wc_Des3Cbc_MonteCarlo)

#endif /* WOLFCRYPT_TEST_DES3_H */
Loading
Loading