diff --git a/tests/crypto/ecc_dh/prj.conf b/tests/crypto/ecc_dh/prj.conf index 4d9bf9baad3..7f122a3a0e2 100644 --- a/tests/crypto/ecc_dh/prj.conf +++ b/tests/crypto/ecc_dh/prj.conf @@ -4,4 +4,5 @@ CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TINYCRYPT=y CONFIG_TINYCRYPT_ECC_DH=y -CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_ZTEST_STACKSIZE=2048 +CONFIG_ZTEST=y diff --git a/tests/crypto/ecc_dh/src/Makefile b/tests/crypto/ecc_dh/src/Makefile index 63da0cfbb33..0d5c660f3f6 100644 --- a/tests/crypto/ecc_dh/src/Makefile +++ b/tests/crypto/ecc_dh/src/Makefile @@ -1,3 +1,5 @@ +include ${ZEPHYR_BASE}/tests/Makefile.test ccflags-y += -I$(ZEPHYR_BASE)/tests/include -obj-y = test_ecc_utils.o test_ecc_dh.o +obj-y = test_ecc_utils.o +obj-y += main.o ecc_dh.o diff --git a/tests/crypto/ecc_dh/src/test_ecc_dh.c b/tests/crypto/ecc_dh/src/ecc_dh.c similarity index 93% rename from tests/crypto/ecc_dh/src/test_ecc_dh.c rename to tests/crypto/ecc_dh/src/ecc_dh.c index 196d5b25355..5358c56e59b 100644 --- a/tests/crypto/ecc_dh/src/test_ecc_dh.c +++ b/tests/crypto/ecc_dh/src/ecc_dh.c @@ -21,7 +21,8 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE.*/ + * POSSIBILITY OF SUCH DAMAGE. + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -65,6 +66,7 @@ #include #include #include +#include int ecdh_vectors(char **qx_vec, char **qy_vec, char **d_vec, char **z_vec, int tests, int verbose) @@ -96,18 +98,15 @@ int ecdh_vectors(char **qx_vec, char **qy_vec, char **d_vec, char **z_vec, rc = uECC_shared_secret(pub_bytes, private_bytes, z_bytes, curve); - if (rc == TC_CRYPTO_FAIL) { - TC_ERROR("ECDH failure, exit.\n"); - result = TC_FAIL; - return result;; - } + /**TESTPOINT: Check for ECDH failure*/ + zassert_equal(rc, TC_CRYPTO_SUCCESS, "ECDH failure, exit"); uECC_vli_bytesToNative(z, z_bytes, NUM_ECC_BYTES); result = check_ecc_result(i, "Z", exp_z, z, NUM_ECC_WORDS, verbose); - if (result == TC_FAIL) { - return result; - } + + /**TESTPOINT: Check result*/ + zassert_false(result, "ECDH test failed"); } return result; } @@ -234,12 +233,9 @@ int cavp_ecdh(bool verbose) TC_PRINT("NIST-p256\n"); result = ecdh_vectors(x, y, d, Z, 25, verbose); - if (result == TC_FAIL) { - goto exitTest1; - } -exitTest1: - TC_END_RESULT(result); + /**TESTPOINT: Check result*/ + zassert_false(result, "ECDH test failed"); return result; } @@ -292,12 +288,9 @@ int cavp_keygen(bool verbose) TC_PRINT("NIST-p256\n"); result = keygen_vectors(d, x, y, 10, verbose); - if (result == TC_FAIL) { - goto exitTest1; - } -exitTest1: - TC_END_RESULT(result); + /**TESTPOINT: Check result*/ + zassert_false(result, "ECC KeyGen test failed"); return result; } @@ -348,14 +341,11 @@ int pkv_vectors(char **qx_vec, char **qy_vec, int res_vec[], int tests, } result = check_code(i, exp_rc, rc, verbose); - if (result == TC_FAIL) { - goto exitTest1; - } - } -exitTest1: - TC_END_RESULT(result); - return result; + /**TESTPOINT: Check result*/ + zassert_false(result, "PubKey verification failed"); + } + return result; } int cavp_pkv(bool verbose) @@ -424,21 +414,15 @@ int montecarlo_ecdh(int num_tests, bool verbose) if (!uECC_make_key(public1, private1, curve) || !uECC_make_key(public2, private2, curve)) { - TC_ERROR("uECC_make_key() failed\n"); - result = TC_FAIL; - goto exitTest1; + zassert_true(0, "uECC_make_key() failed"); } if (!uECC_shared_secret(public2, private1, secret1, curve)) { - TC_ERROR("shared_secret() failed (1)\n"); - result = TC_FAIL; - goto exitTest1;; + zassert_true(0, "shared_secret() failed (1)"); } if (!uECC_shared_secret(public1, private2, secret2, curve)) { - TC_ERROR("shared_secret() failed (2)\n"); - result = TC_FAIL; - goto exitTest1; + zassert_true(0, "shared_secret() failed (2)"); } if (memcmp(secret1, secret2, sizeof(secret1)) != 0) { @@ -460,9 +444,6 @@ int montecarlo_ecdh(int num_tests, bool verbose) } TC_PRINT("\n"); - -exitTest1: - TC_END_RESULT(result); return result; } @@ -483,7 +464,7 @@ int default_CSPRNG(u8_t *dest, unsigned int size) return 1; } -int main(void) +void test_ecc_dh(void) { unsigned int result = TC_PASS; @@ -496,34 +477,27 @@ int main(void) TC_PRINT("Performing cavp_ecdh test:\n"); result = cavp_ecdh(verbose); - if (result == TC_FAIL) { /* terminate test */ - TC_ERROR("cavp_ecdh test failed.\n"); - goto exitTest; - } + + /**TESTPOINT: Check cavp_ecdh*/ + zassert_false(result, "cavp_ecdh test failed"); + TC_PRINT("Performing cavp_keygen test:\n"); result = cavp_keygen(verbose); - if (result == TC_FAIL) { /* terminate test */ - TC_ERROR("cavp_keygen test failed.\n"); - goto exitTest; - } + + /**TESTPOINT: Check cavp_keygen*/ + zassert_false(result, "cavp_keygen test failed"); + TC_PRINT("Performing cavp_pkv test:\n"); result = cavp_pkv(verbose); - if (result == TC_FAIL) { /* terminate test */ - TC_ERROR("cavp_pkv failed.\n"); - goto exitTest; - } + + /**TESTPOINT: Check cavp_pkv*/ + zassert_false(result, "cavp_pkv test failed"); + TC_PRINT("Performing montecarlo_ecdh test:\n"); result = montecarlo_ecdh(10, verbose); - if (result == TC_FAIL) { /* terminate test */ - TC_ERROR("montecarlo_ecdh test failed.\n"); - goto exitTest; - } + + /**TESTPOINT: Check cavp_ecdh*/ + zassert_false(result, "montecarlo_ecdh test failed"); TC_PRINT("All EC-DH tests succeeded!\n"); - -exitTest: - TC_END_RESULT(result); - TC_END_REPORT(result); - - return 0; } diff --git a/tests/crypto/ecc_dh/src/main.c b/tests/crypto/ecc_dh/src/main.c new file mode 100644 index 00000000000..c82170b61ff --- /dev/null +++ b/tests/crypto/ecc_dh/src/main.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +extern void test_ecc_dh(void); + +/**test case main entry*/ +void test_main(void *p1, void *p2, void *p3) +{ + ztest_test_suite(test_ecc_dh_fn, + ztest_unit_test(test_ecc_dh)); + ztest_run_test_suite(test_ecc_dh_fn); +}