From 7c5dc6b20a3eb64f4019390be701be714b6805d8 Mon Sep 17 00:00:00 2001 From: Jarno Lamsa Date: Mon, 26 Aug 2019 13:12:35 +0300 Subject: [PATCH] Add test suite for tinycrypt Initially add a test for ECDH-part. --- tests/CMakeLists.txt | 1 + tests/suites/test_suite_tinycrypt.data | 2 ++ tests/suites/test_suite_tinycrypt.function | 35 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/suites/test_suite_tinycrypt.data create mode 100644 tests/suites/test_suite_tinycrypt.function diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5938a5fc84..2ea77e7e7e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -133,6 +133,7 @@ add_test_suite(poly1305) add_test_suite(shax) add_test_suite(ssl) add_test_suite(timing) +add_test_suite(tinycrypt) add_test_suite(rsa) add_test_suite(version) add_test_suite(xtea) diff --git a/tests/suites/test_suite_tinycrypt.data b/tests/suites/test_suite_tinycrypt.data new file mode 100644 index 0000000000..85d5992760 --- /dev/null +++ b/tests/suites/test_suite_tinycrypt.data @@ -0,0 +1,2 @@ +Tinycrypt ECDH +test_ecdh: diff --git a/tests/suites/test_suite_tinycrypt.function b/tests/suites/test_suite_tinycrypt.function new file mode 100644 index 0000000000..eb347ea493 --- /dev/null +++ b/tests/suites/test_suite_tinycrypt.function @@ -0,0 +1,35 @@ +/* BEGIN_HEADER */ + +#include "tinycrypt/ecc.h" +#include "tinycrypt/ecc_dh.h" +#include "tinycrypt/ecc_dsa.h" + +/* END_HEADER */ + +/* BEGIN_DEPENDENCIES + * depends_on:MBEDTLS_USE_TINYCRYPT + * END_DEPENDENCIES + */ + +/* BEGIN_CASE depends_on:MBEDTLS_USE_TINYCRYPT */ +void test_ecdh() +{ + uint8_t private1[NUM_ECC_BYTES] = {0}; + uint8_t private2[NUM_ECC_BYTES] = {0}; + uint8_t public1[2*NUM_ECC_BYTES] = {0}; + uint8_t public2[2*NUM_ECC_BYTES] = {0}; + uint8_t secret1[NUM_ECC_BYTES] = {0}; + uint8_t secret2[NUM_ECC_BYTES] = {0}; + + const struct uECC_Curve_t * curve = uECC_secp256r1(); + + TEST_ASSERT( uECC_make_key( public1, private1, curve ) != 0 ); + TEST_ASSERT( uECC_make_key( public2, private2, curve ) != 0 ); + + TEST_ASSERT( uECC_shared_secret( public2, private1, secret1, curve ) != 0 ); + + TEST_ASSERT( uECC_shared_secret( public1, private2, secret2, curve ) != 0 ); + + TEST_ASSERT( memcmp( secret1, secret2, sizeof( secret1 ) ) == 0 ); +} +/* END_CASE */