mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 14:33:52 +01:00
crypto/helper: Add test for crypto_secure_wipe
The test added for crypto_secure_wipe wipes a buffer with a secret in it. Only the last byte is kept as it was. The last byte is used to check that the function doesn't write outside the supplied buffer.
This commit is contained in:
parent
fa64817e61
commit
730286903a
38
tests/unittests/tests-crypto/tests-crypto-helper.c
Normal file
38
tests/unittests/tests-crypto/tests-crypto-helper.c
Normal file
@ -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 <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@ -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());
|
||||
|
||||
@ -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
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user