mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
89 lines
2.5 KiB
C
89 lines
2.5 KiB
C
/*
|
|
* Copyright (C) 2023 TU Dresden
|
|
* 2024 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
|
|
* @{
|
|
*
|
|
* @brief Tests the SHA3 gluecode for all variants (SHA3-256, SHA3-384, SHA3-512)
|
|
*
|
|
* @author Katharina Volkenand <katharina_marlene.volkenand@msx.tu-dresden.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
static const uint8_t msg[] = "Hello World!";
|
|
static const size_t msg_len = sizeof(msg)-1; // exclude NULL-byte
|
|
|
|
static const uint8_t hash_sha3_256[] ={
|
|
0xd0, 0xe4, 0x74, 0x86, 0xbb, 0xf4, 0xc1, 0x6a, 0xca, 0xc2, 0x6f, 0x8b,
|
|
0x65, 0x35, 0x92, 0x97, 0x3c, 0x13, 0x62, 0x90, 0x9f, 0x90, 0x26, 0x28,
|
|
0x77, 0x08, 0x9f, 0x9c, 0x8a, 0x45, 0x36, 0xaf
|
|
};
|
|
|
|
static const uint8_t hash_sha3_384[] = {
|
|
0xf3, 0x24, 0xcb, 0xd4, 0x21, 0x32, 0x6a, 0x2a, 0xba, 0xed, 0xf6, 0xf3,
|
|
0x95, 0xd1, 0xa5,0x1e, 0x18, 0x9d, 0x4a, 0x71, 0xc7, 0x55, 0xf5, 0x31,
|
|
0x28, 0x9e, 0x51, 0x9f, 0x07, 0x9b, 0x22, 0x46, 0x64, 0x96, 0x1e, 0x38,
|
|
0x5a, 0xfc, 0xc3, 0x7d, 0xa3, 0x48, 0xbd, 0x85, 0x9f, 0x34, 0xfd, 0x1c
|
|
};
|
|
|
|
static const uint8_t hash_sha3_512[] = {
|
|
0x32, 0x40, 0x0b, 0x5e, 0x89, 0x82, 0x2d, 0xe2, 0x54, 0xe8, 0xd5, 0xd9,
|
|
0x42, 0x52, 0xc5, 0x2b, 0xdc, 0xb2, 0x7a, 0x35, 0x62, 0xca, 0x59, 0x3e,
|
|
0x98, 0x03, 0x64, 0xd9, 0x84, 0x8b, 0x80, 0x41, 0xb9, 0x8e, 0xab, 0xe1,
|
|
0x6c, 0x1a, 0x67, 0x97, 0x48, 0x49, 0x41, 0xd2, 0x37, 0x68, 0x64, 0xa1,
|
|
0xb0, 0xe2, 0x48, 0xb0, 0xf7, 0xaf, 0x8b, 0x15, 0x55, 0xa7, 0x78, 0xc3,
|
|
0x36, 0xa5, 0xbf, 0x48
|
|
};
|
|
|
|
/**
|
|
* @brief Compares the computed hashes with the expected hashes.
|
|
* Hashes are computed using the PSA algorithm dispatch.
|
|
*
|
|
* @return psa_status_t
|
|
*/
|
|
psa_status_t example_sha3_glue(void) {
|
|
|
|
psa_status_t status = PSA_ERROR_DOES_NOT_EXIST;
|
|
|
|
status = psa_hash_compare(
|
|
PSA_ALG_SHA3_256,
|
|
msg,
|
|
msg_len,
|
|
hash_sha3_256,
|
|
sizeof(hash_sha3_256));
|
|
if (status != PSA_SUCCESS) {
|
|
return status;
|
|
}
|
|
|
|
status = psa_hash_compare(
|
|
PSA_ALG_SHA3_384,
|
|
msg,
|
|
msg_len,
|
|
hash_sha3_384,
|
|
sizeof(hash_sha3_384));
|
|
if (status != PSA_SUCCESS) {
|
|
return status;
|
|
}
|
|
|
|
status = psa_hash_compare(
|
|
PSA_ALG_SHA3_512,
|
|
msg,
|
|
msg_len,
|
|
hash_sha3_512,
|
|
sizeof(hash_sha3_512));
|
|
if (status != PSA_SUCCESS) {
|
|
return status;
|
|
}
|
|
return PSA_SUCCESS;
|
|
}
|