mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-03 19:12:00 +10:00
fix(crypto): hash full size_t inputs (#11359)
This commit is contained in:
@@ -302,8 +302,8 @@ void CryptoEngine::hash(uint8_t *bytes, size_t numBytes)
|
||||
{
|
||||
SHA256 hash;
|
||||
size_t posn;
|
||||
uint8_t size = numBytes;
|
||||
uint8_t inc = 16;
|
||||
size_t size = numBytes;
|
||||
constexpr size_t inc = 16;
|
||||
hash.reset();
|
||||
for (posn = 0; posn < size; posn += inc) {
|
||||
size_t len = size - posn;
|
||||
|
||||
@@ -47,6 +47,17 @@ void test_SHA256(void)
|
||||
crypto->hash(hash, 2);
|
||||
TEST_ASSERT_EQUAL_MEMORY(hash, expected, 32);
|
||||
}
|
||||
|
||||
void test_SHA256_large_input(void)
|
||||
{
|
||||
uint8_t hash[300] = {0};
|
||||
uint8_t expected[32];
|
||||
|
||||
HexToBytes(expected, "d13d4a8b3b8add19b5970157f09d00c12cbda4fed4d74d8493156523f7069b66");
|
||||
crypto->hash(hash, sizeof(hash));
|
||||
TEST_ASSERT_EQUAL_MEMORY(hash, expected, sizeof(expected));
|
||||
}
|
||||
|
||||
void test_ECB_AES256(void)
|
||||
{
|
||||
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/AES_ECB.pdf
|
||||
@@ -357,6 +368,7 @@ void setup()
|
||||
initializeTestEnvironment();
|
||||
UNITY_BEGIN(); // IMPORTANT LINE!
|
||||
RUN_TEST(test_SHA256);
|
||||
RUN_TEST(test_SHA256_large_input);
|
||||
RUN_TEST(test_ECB_AES256);
|
||||
RUN_TEST(test_DH25519);
|
||||
RUN_TEST(test_AES_CTR);
|
||||
@@ -371,4 +383,4 @@ void setup()
|
||||
exit(UNITY_END()); // stop unit testing
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
void loop() {}
|
||||
|
||||
Reference in New Issue
Block a user