1
0
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:
Koen Zandberg 2018-10-23 14:06:15 +02:00
parent fa64817e61
commit 730286903a
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
3 changed files with 45 additions and 0 deletions

View 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;
}

View File

@ -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());

View File

@ -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
*