mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests: add pkg_cryptoauthlib_compare_sha256
This commit is contained in:
parent
529f3c8b61
commit
7842c3dc6f
11
tests/pkg_cryptoauthlib_compare_sha256/Makefile
Normal file
11
tests/pkg_cryptoauthlib_compare_sha256/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
# Test fails to build for these boards fails due to
|
||||
# redefinition of define AES_COUNT in library, which
|
||||
# is also defined in efm32 header files
|
||||
BOARD_BLACKLIST := stk3600 stk3700
|
||||
|
||||
USEPKG += cryptoauthlib
|
||||
USEMODULE += hashes
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
89
tests/pkg_cryptoauthlib_compare_sha256/main.c
Normal file
89
tests/pkg_cryptoauthlib_compare_sha256/main.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2019 HAW Hamburg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief This test was written to compare the runtime of the RIOT software
|
||||
* implementation and the CryptoAuth hardware implementation of SHA-256.
|
||||
*
|
||||
* @author Lena Boeckmann <lena.boeckmann@haw-hamburg.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hashes/sha256.h"
|
||||
#include "atca.h"
|
||||
#include "atca_params.h"
|
||||
|
||||
#define SHA256_HASH_SIZE (32)
|
||||
|
||||
/**
|
||||
* Function to call RIOT software implementation of SHA-256
|
||||
*/
|
||||
static int test_riot_sha256(uint8_t *teststring, uint16_t len,
|
||||
uint8_t *expected,
|
||||
uint8_t *result)
|
||||
{
|
||||
sha256_context_t ctx;
|
||||
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, (void *)teststring, len);
|
||||
sha256_final(&ctx, result);
|
||||
return memcmp(expected, result, SHA256_HASH_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to call CryptoAuth hardware implementation of SHA-256
|
||||
*/
|
||||
static int test_atca_sha(uint8_t *teststring, uint16_t len, uint8_t *expected,
|
||||
uint8_t *result)
|
||||
{
|
||||
atcab_sha_start();
|
||||
atcab_sha_end(result, len, teststring);
|
||||
return memcmp(expected, result, SHA256_HASH_SIZE);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t teststring[] = "chili cheese fries";
|
||||
uint8_t expected[] =
|
||||
{ 0x36, 0x46, 0xEF, 0xD6, 0x27, 0x6C, 0x0D, 0xCB, 0x4B, 0x07, 0x73, 0x41,
|
||||
0x88, 0xF4, 0x17, 0xB4, 0x38, 0xAA, 0xCF, 0xC6, 0xAE, 0xEF, 0xFA, 0xBE,
|
||||
0xF3, 0xA8, 0x5D, 0x67, 0x42, 0x0D, 0xFE, 0xE5 };
|
||||
|
||||
uint8_t result[SHA256_HASH_SIZE]; /* +3 to fit 1 byte length and 2 bytes checksum */
|
||||
|
||||
memset(result, 0, SHA256_HASH_SIZE); /* alles in result auf 0 setzen */
|
||||
|
||||
uint16_t test_string_size = (sizeof(teststring) - 1); /* -1 to ignore \0 */
|
||||
|
||||
if (test_riot_sha256(teststring, test_string_size, expected, result) == 0) {
|
||||
printf("RIOT SHA256: Success\n");
|
||||
}
|
||||
else {
|
||||
printf("RIOT SHA256: Failure.\n");
|
||||
}
|
||||
atca_delay_us(10);
|
||||
memset(result, 0, SHA256_HASH_SIZE);
|
||||
|
||||
if (test_atca_sha(teststring, test_string_size, expected, result) == 0) {
|
||||
printf("ATCA SHA256: Success\n");
|
||||
}
|
||||
else {
|
||||
printf("ATCA SHA256: Failure.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user