tests: crypto: move the tinycrypt test to new ztest API

Migrate the testsuite tests/crypto/tinycrypt to the new
ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
This commit is contained in:
Enjia Mai 2022-08-22 10:31:38 +08:00 committed by Anas Nashif
parent 64f096d264
commit 66da4c2854
11 changed files with 43 additions and 132 deletions

View file

@ -13,3 +13,4 @@ CONFIG_TINYCRYPT_ECC_DH=y
CONFIG_TINYCRYPT_ECC_DSA=y
CONFIG_ZTEST_STACK_SIZE=5120
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y

View file

@ -167,7 +167,7 @@ uint32_t var_text_test(uint32_t r, const uint8_t *in, const uint8_t *out,
/*
* All NIST tests with fixed key and variable text.
*/
void test_aes_fixed_key_variable_text(void)
ZTEST(tinycrypt, test_aes_fixed_key_variable_text)
{
uint32_t result = TC_PASS;
const uint8_t key[NUM_OF_NIST_KEYS] = {
@ -1113,7 +1113,7 @@ uint32_t var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
/*
* All NIST tests with variable key and fixed text.
*/
void test_aes_variable_key_fixed_text(void)
ZTEST(tinycrypt, test_aes_variable_key_fixed_text)
{
uint32_t result = TC_PASS;
const struct kat_table kat_tbl[NUM_OF_FIXED_KEYS] = {

View file

@ -101,7 +101,7 @@ const uint8_t ciphertext[80] = {
/*
* NIST SP 800-38a CBC Test for encryption and decryption.
*/
void test_cbc_sp_800_38a_encrypt_decrypt(void)
ZTEST(tinycrypt, test_cbc_sp_800_38a_encrypt_decrypt)
{
TC_START("Performing AES128 tests:");

View file

@ -120,7 +120,7 @@ uint32_t do_test(const uint8_t *key,
return result;
}
void test_ccm_vector_1(void)
ZTEST(tinycrypt, test_ccm_vector_1)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #1 */
@ -158,7 +158,7 @@ void test_ccm_vector_1(void)
zassert_false(result, "CCM test #1 (RFC 3610 test vector #1) failed.");
}
void test_ccm_vector_2(void)
ZTEST(tinycrypt, test_ccm_vector_2)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #2 */
@ -196,7 +196,7 @@ void test_ccm_vector_2(void)
zassert_false(result, "CCM test #2 failed.");
}
void test_ccm_vector_3(void)
ZTEST(tinycrypt, test_ccm_vector_3)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #3 */
@ -236,7 +236,7 @@ void test_ccm_vector_3(void)
zassert_false(result, "CCM test #3 failed.");
}
void test_ccm_vector_4(void)
ZTEST(tinycrypt, test_ccm_vector_4)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #7 */
@ -275,7 +275,7 @@ void test_ccm_vector_4(void)
zassert_false(result, "CCM test #4 failed.");
}
void test_ccm_vector_5(void)
ZTEST(tinycrypt, test_ccm_vector_5)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #8 */
@ -314,7 +314,7 @@ void test_ccm_vector_5(void)
zassert_false(result, "CCM test #5 failed.");
}
void test_ccm_vector_6(void)
ZTEST(tinycrypt, test_ccm_vector_6)
{
uint32_t result = TC_PASS;
/* RFC 3610 test vector #9 */
@ -354,7 +354,7 @@ void test_ccm_vector_6(void)
zassert_false(result, "CCM test #6 failed.");
}
void test_ccm_vector_7(void)
ZTEST(tinycrypt, test_ccm_vector_7)
{
uint32_t result = TC_PASS;
/* Test based on RFC 3610 test vector #9 but with no associated data */
@ -415,7 +415,7 @@ void test_ccm_vector_7(void)
}
void test_ccm_vector_8(void)
ZTEST(tinycrypt, test_ccm_vector_8)
{
uint32_t result = TC_PASS;
/* Test based on RFC 3610 test vector #9 but with no payload data */

View file

@ -251,7 +251,7 @@ static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s)
* Main task to test CMAC
*/
void test_cmac_mode(void)
ZTEST(tinycrypt, test_cmac_mode)
{
uint32_t result = TC_PASS;

View file

@ -343,7 +343,7 @@ static int test_prng_vector(struct prng_vector *v)
return rc;
}
void test_ctr_prng_reseed(void)
ZTEST(tinycrypt, test_ctr_prng_reseed)
{
uint8_t expectedV1[] = {0x7E, 0xE3, 0xA0, 0xCB, 0x6D, 0x5C, 0x4B, 0xC2,
0x4B, 0x7E, 0x3C, 0x48, 0x88, 0xC3, 0x69, 0x70};
@ -427,7 +427,7 @@ void test_ctr_prng_reseed(void)
TC_PRINT("CTR PRNG reseed test succeeded\n");
}
void test_ctr_prng_uninstantiate(void)
ZTEST(tinycrypt, test_ctr_prng_uninstantiate)
{
uint8_t entropy[32] = {0}; /* value not important */
TCCtrPrng_t ctx;
@ -462,7 +462,7 @@ void test_ctr_prng_uninstantiate(void)
TC_PRINT("CTR PRNG uninstantiate test succeeded\n");
}
void test_ctr_prng_robustness(void)
ZTEST(tinycrypt, test_ctr_prng_robustness)
{
uint8_t entropy[32] = {0}; /* value not important */
uint8_t output[32];
@ -538,7 +538,7 @@ void test_ctr_prng_robustness(void)
/*
* Main task to test CTR PRNG
*/
void test_ctr_prng_vector(void)
ZTEST(tinycrypt, test_ctr_prng_vector)
{
int elements;
int rc;

View file

@ -446,7 +446,7 @@ int montecarlo_ecdh(int num_tests, bool verbose)
return TC_PASS;
}
void test_ecc_dh(void)
ZTEST(tinycrypt, test_ecc_dh)
{
unsigned int result = TC_PASS;

View file

@ -628,7 +628,7 @@ int default_CSPRNG(uint8_t *dest, unsigned int size)
return 1;
}
void test_ecc_dsa(void)
ZTEST(tinycrypt, test_ecc_dsa)
{
unsigned int result = TC_PASS;

View file

@ -42,7 +42,7 @@
#include <zephyr/test_utils.h>
#include <zephyr/ztest.h>
uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
static uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
size_t datalen, const uint8_t *expected,
size_t expectedlen)
{
@ -60,7 +60,7 @@ uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
/*
* NIST test vectors for encryption.
*/
void test_hmac_1(void)
ZTEST(tinycrypt, test_hmac_1)
{
uint32_t result = TC_PASS;
@ -94,7 +94,7 @@ void test_hmac_1(void)
zassert_false(result, "HMAC test #7 failed");
}
void test_hmac_2(void)
ZTEST(tinycrypt, test_hmac_2)
{
uint32_t result = TC_PASS;
@ -128,7 +128,7 @@ void test_hmac_2(void)
zassert_false(result, "HMAC test #7 failed");
}
void test_hmac_3(void)
ZTEST(tinycrypt, test_hmac_3)
{
uint32_t result = TC_PASS;
@ -168,7 +168,7 @@ void test_hmac_3(void)
zassert_false(result, "HMAC test #3 failed");
}
void test_hmac_4(void)
ZTEST(tinycrypt, test_hmac_4)
{
uint32_t result = TC_PASS;
@ -210,7 +210,7 @@ void test_hmac_4(void)
zassert_false(result, "HMAC test #4 failed");
}
void test_hmac_5(void)
ZTEST(tinycrypt, test_hmac_5)
{
uint32_t result = TC_PASS;
@ -244,7 +244,7 @@ void test_hmac_5(void)
zassert_false(result, "HMAC test #5 failed");
}
void test_hmac_6(void)
ZTEST(tinycrypt, test_hmac_6)
{
uint32_t result = TC_PASS;
@ -302,7 +302,7 @@ void test_hmac_6(void)
zassert_false(result, "HMAC test #6 failed");
}
void test_hmac_7(void)
ZTEST(tinycrypt, test_hmac_7)
{
uint32_t result = TC_PASS;

View file

@ -6,94 +6,4 @@
#include <zephyr/ztest.h>
extern void test_ccm_vector_1(void);
extern void test_ccm_vector_2(void);
extern void test_ccm_vector_3(void);
extern void test_ccm_vector_4(void);
extern void test_ccm_vector_5(void);
extern void test_ccm_vector_6(void);
extern void test_ccm_vector_7(void);
extern void test_ccm_vector_8(void);
extern void test_ctr_sp_800_38a_encrypt_decrypt(void);
extern void test_cbc_sp_800_38a_encrypt_decrypt(void);
extern void test_cmac_mode(void);
extern void test_ctr_prng_vector(void);
extern void test_ctr_prng_reseed(void);
extern void test_ctr_prng_uninstantiate(void);
extern void test_ctr_prng_robustness(void);
extern void test_ecc_dh(void);
extern void test_ecc_dsa(void);
extern void test_hmac_1(void);
extern void test_hmac_2(void);
extern void test_hmac_3(void);
extern void test_hmac_4(void);
extern void test_hmac_5(void);
extern void test_hmac_6(void);
extern void test_hmac_7(void);
extern void test_sha256_1(void);
extern void test_sha256_2(void);
extern void test_sha256_3(void);
extern void test_sha256_4(void);
extern void test_sha256_5(void);
extern void test_sha256_6(void);
extern void test_sha256_7(void);
extern void test_sha256_8(void);
extern void test_sha256_9(void);
extern void test_sha256_10(void);
extern void test_sha256_11(void);
extern void test_sha256_12(void);
extern void test_sha256_13_and_14(void);
extern void test_aes_key_chain(void);
extern void test_aes_vectors(void);
extern void test_aes_fixed_key_variable_text(void);
extern void test_aes_variable_key_fixed_text(void);
/**test case main entry*/
void test_main(void)
{
ztest_test_suite(test_tinycrypt,
ztest_unit_test(test_aes_key_chain),
ztest_unit_test(test_aes_vectors),
ztest_unit_test(test_aes_fixed_key_variable_text),
ztest_unit_test(test_aes_variable_key_fixed_text),
ztest_unit_test(test_sha256_1),
ztest_unit_test(test_sha256_2),
ztest_unit_test(test_sha256_3),
ztest_unit_test(test_sha256_4),
ztest_unit_test(test_sha256_5),
ztest_unit_test(test_sha256_6),
ztest_unit_test(test_sha256_7),
ztest_unit_test(test_sha256_8),
ztest_unit_test(test_sha256_9),
ztest_unit_test(test_sha256_10),
ztest_unit_test(test_sha256_11),
ztest_unit_test(test_sha256_12),
ztest_unit_test(test_sha256_13_and_14),
ztest_unit_test(test_hmac_1),
ztest_unit_test(test_hmac_2),
ztest_unit_test(test_hmac_3),
ztest_unit_test(test_hmac_4),
ztest_unit_test(test_hmac_5),
ztest_unit_test(test_hmac_6),
ztest_unit_test(test_hmac_7),
ztest_unit_test(test_ccm_vector_1),
ztest_unit_test(test_ccm_vector_2),
ztest_unit_test(test_ccm_vector_3),
ztest_unit_test(test_ccm_vector_4),
ztest_unit_test(test_ccm_vector_5),
ztest_unit_test(test_ccm_vector_6),
ztest_unit_test(test_ccm_vector_7),
ztest_unit_test(test_ccm_vector_8),
ztest_unit_test(test_ecc_dh),
ztest_unit_test(test_ecc_dsa),
ztest_unit_test(test_cmac_mode),
ztest_unit_test(test_ctr_prng_vector),
ztest_unit_test(test_ctr_prng_reseed),
ztest_unit_test(test_ctr_prng_uninstantiate),
ztest_unit_test(test_ctr_prng_robustness),
ztest_unit_test(test_ctr_sp_800_38a_encrypt_decrypt),
ztest_unit_test(test_cbc_sp_800_38a_encrypt_decrypt)
);
ztest_run_test_suite(test_tinycrypt);
}
ZTEST_SUITE(tinycrypt, NULL, NULL, NULL, NULL, NULL);

View file

@ -50,7 +50,7 @@
/*
* NIST SHA256 test vector 1.
*/
void test_sha256_1(void)
ZTEST(tinycrypt, test_sha256_1)
{
TC_START("Performing SHA256 tests (NIST tests vectors):");
@ -81,7 +81,7 @@ void test_sha256_1(void)
/*
* NIST SHA256 test vector 2.
*/
void test_sha256_2(void)
ZTEST(tinycrypt, test_sha256_2)
{
uint32_t result = TC_PASS;
@ -109,7 +109,7 @@ void test_sha256_2(void)
zassert_false(result, "SHA256 test #2 failed.");
}
void test_sha256_3(void)
ZTEST(tinycrypt, test_sha256_3)
{
uint32_t result = TC_PASS;
@ -137,7 +137,7 @@ void test_sha256_3(void)
}
void test_sha256_4(void)
ZTEST(tinycrypt, test_sha256_4)
{
uint32_t result = TC_PASS;
@ -165,7 +165,7 @@ void test_sha256_4(void)
}
void test_sha256_5(void)
ZTEST(tinycrypt, test_sha256_5)
{
uint32_t result = TC_PASS;
@ -195,7 +195,7 @@ void test_sha256_5(void)
}
void test_sha256_6(void)
ZTEST(tinycrypt, test_sha256_6)
{
uint32_t result = TC_PASS;
@ -225,7 +225,7 @@ void test_sha256_6(void)
}
void test_sha256_7(void)
ZTEST(tinycrypt, test_sha256_7)
{
uint32_t result = TC_PASS;
@ -255,7 +255,7 @@ void test_sha256_7(void)
}
void test_sha256_8(void)
ZTEST(tinycrypt, test_sha256_8)
{
uint32_t result = TC_PASS;
@ -285,7 +285,7 @@ void test_sha256_8(void)
}
void test_sha256_9(void)
ZTEST(tinycrypt, test_sha256_9)
{
uint32_t result = TC_PASS;
@ -315,7 +315,7 @@ void test_sha256_9(void)
}
void test_sha256_10(void)
ZTEST(tinycrypt, test_sha256_10)
{
uint32_t result = TC_PASS;
@ -345,7 +345,7 @@ void test_sha256_10(void)
}
void test_sha256_11(void)
ZTEST(tinycrypt, test_sha256_11)
{
uint32_t result = TC_PASS;
@ -375,7 +375,7 @@ void test_sha256_11(void)
}
void test_sha256_12(void)
ZTEST(tinycrypt, test_sha256_12)
{
uint32_t result = TC_PASS;
@ -407,7 +407,7 @@ void test_sha256_12(void)
zassert_false(result, "SHA256 test #12 failed.");
}
#if EXTREME_SLOW
void test_sha256_13(void)
ZTEST(tinycrypt, test_sha256_13)
{
uint32_t result = TC_PASS;
@ -440,7 +440,7 @@ void test_sha256_13(void)
}
void test_sha256_14(void)
ZTEST(tinycrypt, test_sha256_14)
{
uint32_t result = TC_PASS;
@ -474,7 +474,7 @@ void test_sha256_14(void)
}
#endif
void test_sha256_13_and_14(void)
ZTEST(tinycrypt, test_sha256_13_and_14)
{
#if EXTREME_SLOW
result = test_sha256_13();