52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#include "sha2.h"
|
|
#include "trace.h"
|
|
#include "unity.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
void setUp(void) {}
|
|
|
|
void tearDown(void) {}
|
|
|
|
// BUG: may drop the null at end of strings
|
|
#define SAMPLE(INPUT, HASH) \
|
|
{(uint8_t[]){INPUT "\0"}, (uint8_t *)(uint32_t[])HASH}
|
|
|
|
#define TEST_VALUES_LEN 1
|
|
uint8_t *test_values[TEST_VALUES_LEN][2] = {
|
|
SAMPLE("AAAA", HASH(0x63c1dd95, 0x1ffedf6f, 0x7fd968ad, 0x4efa39b8,
|
|
0xed584f16, 0x2f46e715, 0x114ee184, 0xf8de9201)),
|
|
};
|
|
|
|
void test_sha2_check(void) {
|
|
SHA2Digest digest;
|
|
SHA2Result res;
|
|
uint8_t *input;
|
|
size_t len;
|
|
size_t i;
|
|
for (i = 0; i < TEST_VALUES_LEN; i++) {
|
|
TRACE("Hash iteration %d\n", i);
|
|
input = test_values[i][0];
|
|
len = strlen((char *)input);
|
|
TRACELN("Input:");
|
|
dump_data(input, len);
|
|
|
|
TRACELN("Call oneshot");
|
|
res = sha2_256_oneshot(input, len, digest);
|
|
TEST_ASSERT_EQUAL_MESSAGE(
|
|
shaSuccess, res,
|
|
"sha2_256_oneshot exited with a code that is not shaSuccess");
|
|
|
|
// NOTE: If it segfaults here, then the sha2_oneshot function is at fault
|
|
// anyways!!!!!!!!!!!!
|
|
TRACELN("Hash should be:");
|
|
dump_data(test_values[i][1], SHA2_256_HashBytes);
|
|
|
|
TRACELN("Hash is:");
|
|
dump_data((uint8_t *)digest, SHA2_256_HashBytes);
|
|
|
|
TEST_ASSERT_EQUAL_MEMORY(test_values[i][1], digest, SHA2_256_HashBytes);
|
|
}
|
|
}
|