1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

unittests/tests-hashes: add two FIPS test cases fot sha256

This commit is contained in:
PeterKietzmann 2020-06-10 09:40:03 +02:00
parent d9c73bef51
commit e5e3724a45

View File

@ -134,6 +134,25 @@ static const unsigned char hlong_sequence[] =
0x6a, 0x78, 0x21, 0x73, 0x54, 0x89, 0x61, 0x85,
0xb1, 0x4a, 0x3a, 0x84, 0xf7, 0xcd, 0x80, 0x66};
/**
* @brief expected hash for "abc"
* (from FIPS 180-2 Appendix B.1)
*/
static const unsigned char h_fips_oneblock[] =
{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad};
/**
* @brief expected hash for "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
* (from FIPS 180-2 Appendix B.2)
*/
static const unsigned char h_fips_multiblock[] =
{0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1};
static int calc_and_compare_hash(const char *str, const unsigned char *expected)
{
static unsigned char hash[SHA256_DIGEST_LENGTH];
@ -232,6 +251,20 @@ static void test_hashes_sha256_hash_long_sequence(void)
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hlong_sequence));
}
static void test_hashes_sha256_hash_sequence_abc(void)
{
char *teststring = "abc";
TEST_ASSERT(calc_and_compare_hash(teststring, h_fips_oneblock));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h_fips_oneblock));
}
static void test_hashes_sha256_hash_sequence_abc_long(void)
{
char *teststring = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
TEST_ASSERT(calc_and_compare_hash(teststring, h_fips_multiblock));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h_fips_multiblock));
}
Test *tests_hashes_sha256_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -247,6 +280,9 @@ Test *tests_hashes_sha256_tests(void)
new_TestFixture(test_hashes_sha256_hash_sequence_failing_compare),
new_TestFixture(test_hashes_sha256_hash_long_sequence),
new_TestFixture(test_hashes_sha256_hash_sequence_abc),
new_TestFixture(test_hashes_sha256_hash_sequence_abc_long),
};
EMB_UNIT_TESTCALLER(hashes_sha256_tests, NULL, NULL,