mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-08 13:41:28 +00:00
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
![]() |
#include "CryptoEngine.h"
|
||
|
|
||
|
#include <unity.h>
|
||
|
|
||
|
void setUp(void)
|
||
|
{
|
||
|
// set stuff up here
|
||
|
}
|
||
|
|
||
|
void tearDown(void)
|
||
|
{
|
||
|
// clean stuff up here
|
||
|
}
|
||
|
|
||
|
void test_SHA256(void)
|
||
|
{
|
||
|
uint8_t hash2[32] = {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
|
||
|
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55};
|
||
|
uint8_t hash[32] = {0};
|
||
|
crypto->hash(hash, 0);
|
||
|
TEST_ASSERT_EQUAL_MEMORY(hash, hash2, 32);
|
||
|
}
|
||
|
void test_ECB_AES256(void)
|
||
|
{
|
||
|
uint8_t key[] = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
|
||
|
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4};
|
||
|
uint8_t plain1[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
|
||
|
uint8_t scratch[16] = {0};
|
||
|
|
||
|
uint8_t cipher1[] = {0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8};
|
||
|
crypto->aesSetKey(key, 32);
|
||
|
crypto->aesEncrypt(plain1, scratch); // Does 16 bytes at a time
|
||
|
TEST_ASSERT_EQUAL_MEMORY(scratch, cipher1, 16);
|
||
|
}
|
||
|
|
||
|
void setup()
|
||
|
{
|
||
|
// NOTE!!! Wait for >2 secs
|
||
|
// if board doesn't support software reset via Serial.DTR/RTS
|
||
|
delay(2000);
|
||
|
|
||
|
UNITY_BEGIN(); // IMPORTANT LINE!
|
||
|
RUN_TEST(test_SHA256);
|
||
|
RUN_TEST(test_ECB_AES256);
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
UNITY_END(); // stop unit testing
|
||
|
}
|