diff --git a/tests/unittests/tests-crypto/tests-crypto-helper.c b/tests/unittests/tests-crypto/tests-crypto-helper.c new file mode 100644 index 0000000000..c9cf8d781a --- /dev/null +++ b/tests/unittests/tests-crypto/tests-crypto-helper.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2018 Koen Zandberg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#include + +#include "embUnit/embUnit.h" +#include "crypto/helper.h" + +#define VALUE 0xAA + +/* Secret to wipe */ +static uint8_t secret[20]; + +void test_crypto_wipe(void) +{ + memset(secret, VALUE, sizeof(secret)); + /* Wipe everything except the last byte */ + crypto_secure_wipe(secret, sizeof(secret) - 1); + for (size_t i = 0; i < (sizeof(secret) - 1); i++) { + TEST_ASSERT_EQUAL_INT(0, secret[i]); + } + /* Check last byte */ + TEST_ASSERT_EQUAL_INT(VALUE, secret[19]); +} + +Test *tests_crypto_helper_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(test_crypto_wipe), + }; + EMB_UNIT_TESTCALLER(crypto_helper_tests, NULL, NULL, fixtures); + return (Test *) &crypto_helper_tests; +} diff --git a/tests/unittests/tests-crypto/tests-crypto.c b/tests/unittests/tests-crypto/tests-crypto.c index d1c1ce2aaf..38910467b2 100644 --- a/tests/unittests/tests-crypto/tests-crypto.c +++ b/tests/unittests/tests-crypto/tests-crypto.c @@ -11,6 +11,7 @@ void tests_crypto(void) { + TESTS_RUN(tests_crypto_helper_tests()); TESTS_RUN(tests_crypto_chacha_tests()); TESTS_RUN(tests_crypto_aes_tests()); TESTS_RUN(tests_crypto_cipher_tests()); diff --git a/tests/unittests/tests-crypto/tests-crypto.h b/tests/unittests/tests-crypto/tests-crypto.h index db49773288..aa25a82a89 100644 --- a/tests/unittests/tests-crypto/tests-crypto.h +++ b/tests/unittests/tests-crypto/tests-crypto.h @@ -33,6 +33,12 @@ extern "C" { */ void tests_crypto(void); +/** + * @brief Generates tests for helper functions + * + * @return embUnit tests + */ +Test *tests_crypto_helper_tests(void); /** * @brief Generates tests for crypto/chacha.h *