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

unittests/hashes: Mark input strings as static const

This commit is contained in:
Koen Zandberg 2020-06-25 13:48:35 +02:00
parent a665fcc542
commit 9210630e1a
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
5 changed files with 53 additions and 51 deletions

View File

@ -39,7 +39,7 @@
/* an exact multiple of 512 bits */
#define TEST4 TEST4a TEST4b
static char *_testarray[TEST_CASES_NUM] =
static const char *_testarray[TEST_CASES_NUM] =
{
TEST1,
TEST2,
@ -49,7 +49,7 @@ static char *_testarray[TEST_CASES_NUM] =
static long int _repeatcount[TEST_CASES_NUM] = { 1, 1, 1000000, 10 };
static char *_resultarray[TEST_CASES_NUM + 2] =
static const char *_resultarray[TEST_CASES_NUM + 2] =
{
"A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D",
"84 98 3E 44 1C 3B D2 6E BA AE 4A A1 F9 51 29 E5 E5 46 70 F1",
@ -70,14 +70,14 @@ static char *_resultarray[TEST_CASES_NUM + 2] =
#define TEST4_HMAC "Test Using Larger Than Block-Size Key - Hash Key First"
#define TEST5_HMAC "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
static uint8_t _hmac_key1[]={
static const uint8_t _hmac_key1[]={
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};
static uint8_t _hmac_key2[]= "Jefe";
static uint8_t _hmac_key3[]={
static const uint8_t _hmac_key2[]= "Jefe";
static const uint8_t _hmac_key3[]={
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c
};
static uint8_t _hmac_key4[]={
static const uint8_t _hmac_key4[]={
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@ -87,7 +87,7 @@ static uint8_t _hmac_key4[]={
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
};
static uint8_t _hmac_key5[]={
static const uint8_t _hmac_key5[]={
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@ -98,7 +98,7 @@ static uint8_t _hmac_key5[]={
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
};
static char *_resultarray_hmac[TEST_CASES_HMAC_NUM] =
static const char *_resultarray_hmac[TEST_CASES_HMAC_NUM] =
{
"B6 17 31 86 55 05 72 64 E2 8B C0 B6 FB 37 8C 8E F1 46 BE 00",
"EF FC DF 6A E5 EB 2F A2 D2 74 16 D5 F1 84 DF 9C 25 9A 7C 79",

View File

@ -122,12 +122,13 @@ static void test_hashes_sha224_hash_sequence_abc_long(void)
static void test_hashes_sha256_hash_long_sequence(void)
{
char *teststring = {"RIOT is an open-source microkernel-based operating system, designed"
" to match the requirements of Internet of Things (IoT) devices and"
" other embedded devices. These requirements include a very low memory"
" footprint (on the order of a few kilobytes), high energy efficiency"
", real-time capabilities, communication stacks for both wireless and"
" wired networks, and support for a wide range of low-power hardware."};
static const char *teststring =
{"RIOT is an open-source microkernel-based operating system, designed"
" to match the requirements of Internet of Things (IoT) devices and"
" other embedded devices. These requirements include a very low memory"
" footprint (on the order of a few kilobytes), high energy efficiency"
", real-time capabilities, communication stacks for both wireless and"
" wired networks, and support for a wide range of low-power hardware."};
TEST_ASSERT(calc_and_compare_hash(teststring, hlong_sequence));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hlong_sequence));
}

View File

@ -31,7 +31,7 @@
static void test_sha256_hash_chain(void)
{
const char strSeed[] = "My cool secret seed, you'll never guess it ;) 12345";
static const char strSeed[] = "My cool secret seed, you'll never guess it ;) 12345";
static unsigned char tail_hash_chain_element[SHA256_DIGEST_LENGTH];
/* we produce a sha256-chain of 257 elements */
@ -69,7 +69,7 @@ static void test_sha256_hash_chain(void)
static void test_sha256_hash_chain_with_waypoints(void)
{
const char strSeed[] = "My cool secret seed, you'll never guess it ;P 123456!";
static const char strSeed[] = "My cool secret seed, you'll never guess it ;P 123456!";
static unsigned char tail_hash_chain_element[SHA256_DIGEST_LENGTH];
/* we produce a sha256-chain of 257 elements */
@ -105,7 +105,7 @@ static void test_sha256_hash_chain_with_waypoints(void)
static void test_sha256_hash_chain_store_whole(void)
{
const char strSeed[] = "My cool secret seed, you'll never guess it ;P 123456!";
static const char strSeed[] = "My cool secret seed, you'll never guess it ;P 123456!";
static unsigned char tail_hash_chain_element[SHA256_DIGEST_LENGTH];
/* now we check storing the whole chain

View File

@ -50,7 +50,7 @@ static void test_hashes_hmac_sha256_hash_sequence(void)
"b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", hmac));
/* use a real message */
const unsigned char str[] = "The quick brown fox jumps over the lazy dog";
static const unsigned char str[] = "The quick brown fox jumps over the lazy dog";
key[0] = 'k';
key[1] = 'e';
key[2] = 'y';
@ -68,7 +68,7 @@ static void test_hashes_hmac_sha256_hash_sequence(void)
static void test_hashes_hmac_sha256_hash_PRF1(void)
{
/* Test Case PRF-1: */
const unsigned char strPRF1[] = "Hi There";
static const unsigned char strPRF1[] = "Hi There";
unsigned char key[20];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(key, 0x0b, sizeof(key));
@ -81,7 +81,7 @@ static void test_hashes_hmac_sha256_hash_PRF1(void)
static void test_hashes_hmac_sha256_hash_PRF2(void)
{
/* Test Case PRF-2: */
const unsigned char strPRF2[] = "what do ya want for nothing?";
static const unsigned char strPRF2[] = "what do ya want for nothing?";
unsigned char key[4] = {'J', 'e', 'f', 'e'};
static unsigned char hmac[SHA256_DIGEST_LENGTH];
@ -128,7 +128,7 @@ static void test_hashes_hmac_sha256_hash_PRF4(void)
static void test_hashes_hmac_sha256_hash_PRF5(void)
{
/* Test Case PRF-5: */
const unsigned char strPRF5[] = "Test Using Larger Than Block-Size Key - Hash Key First";
static const unsigned char strPRF5[] = "Test Using Larger Than Block-Size Key - Hash Key First";
unsigned char longKey[131];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(longKey, 0xaa, sizeof(longKey));
@ -141,9 +141,9 @@ static void test_hashes_hmac_sha256_hash_PRF5(void)
static void test_hashes_hmac_sha256_hash_PRF6(void)
{
/* Test Case PRF-6: */
const unsigned char strPRF6[] = "This is a test using a larger than block-size key and a "
"larger than block-size data. The key needs to be hashed "
"before being used by the HMAC algorithm.";
static const unsigned char strPRF6[] = "This is a test using a larger than block-size key and a "
"larger than block-size data. The key needs to be hashed "
"before being used by the HMAC algorithm.";
unsigned char longKey[131];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(longKey, 0xaa, sizeof(longKey));
@ -172,7 +172,7 @@ static void test_hashes_hmac_sha256_ite_hash_sequence(void)
"b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", hmac));
/* use a real message */
const unsigned char str[] = "The quick brown fox jumps over the lazy dog";
static const unsigned char str[] = "The quick brown fox jumps over the lazy dog";
key[0] = 'k';
key[1] = 'e';
key[2] = 'y';
@ -194,7 +194,7 @@ static void test_hashes_hmac_sha256_ite_hash_PRF1(void)
{
/* Test Case PRF-1: */
hmac_context_t ctx;
const unsigned char strPRF1[] = "Hi There";
static const unsigned char strPRF1[] = "Hi There";
unsigned char key[20];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(key, 0x0b, sizeof(key));
@ -211,7 +211,7 @@ static void test_hashes_hmac_sha256_ite_hash_PRF2(void)
{
/* Test Case PRF-2: */
hmac_context_t ctx;
const unsigned char strPRF2[] = "what do ya want for nothing?";
static const unsigned char strPRF2[] = "what do ya want for nothing?";
unsigned char key[4] = {'J', 'e', 'f', 'e'};
static unsigned char hmac[SHA256_DIGEST_LENGTH];
@ -270,7 +270,7 @@ static void test_hashes_hmac_sha256_ite_hash_PRF5(void)
{
/* Test Case PRF-5: */
hmac_context_t ctx;
const unsigned char strPRF5[] = "Test Using Larger Than Block-Size Key - Hash Key First";
static const unsigned char strPRF5[] = "Test Using Larger Than Block-Size Key - Hash Key First";
unsigned char longKey[131];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(longKey, 0xaa, sizeof(longKey));
@ -287,9 +287,9 @@ static void test_hashes_hmac_sha256_ite_hash_PRF6(void)
{
/* Test Case PRF-6: */
hmac_context_t ctx;
const unsigned char strPRF6[] = "This is a test using a larger than block-size key and a "
"larger than block-size data. The key needs to be hashed "
"before being used by the HMAC algorithm.";
static const unsigned char strPRF6[] = "This is a test using a larger than block-size key and a "
"larger than block-size data. The key needs to be hashed "
"before being used by the HMAC algorithm.";
unsigned char longKey[131];
static unsigned char hmac[SHA256_DIGEST_LENGTH];
memset(longKey, 0xaa, sizeof(longKey));
@ -308,9 +308,9 @@ static void test_hashes_hmac_sha256_ite_hash_PRF6_split(void)
{
/* Test Case PRF-6: */
hmac_context_t ctx;
const unsigned char strPRF6_1[] = "This is a test using a larger than block-size key and a ";
const unsigned char strPRF6_2[] = "larger than block-size data. The key needs to be hashed ";
const unsigned char strPRF6_3[] = "before being used by the HMAC algorithm.";
static const unsigned char strPRF6_1[] = "This is a test using a larger than block-size key and a ";
static const unsigned char strPRF6_2[] = "larger than block-size data. The key needs to be hashed ";
static const unsigned char strPRF6_3[] = "before being used by the HMAC algorithm.";
unsigned char longKey[131];
static unsigned char hmac[SHA256_DIGEST_LENGTH];

View File

@ -176,42 +176,42 @@ static int calc_and_compare_hash_wrapper(const char *str, const unsigned char *e
static void test_hashes_sha256_hash_sequence_01(void)
{
const char *teststring = "1234567890_1";
static const char *teststring = "1234567890_1";
TEST_ASSERT(calc_and_compare_hash(teststring, h01));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h01));
}
static void test_hashes_sha256_hash_sequence_02(void)
{
const char *teststring = "1234567890_2";
static const char *teststring = "1234567890_2";
TEST_ASSERT(calc_and_compare_hash(teststring, h02));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h02));
}
static void test_hashes_sha256_hash_sequence_03(void)
{
const char *teststring = "1234567890_3";
static const char *teststring = "1234567890_3";
TEST_ASSERT(calc_and_compare_hash(teststring, h03));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h03));
}
static void test_hashes_sha256_hash_sequence_04(void)
{
const char *teststring = "1234567890_4";
static const char *teststring = "1234567890_4";
TEST_ASSERT(calc_and_compare_hash(teststring, h04));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h04));
}
static void test_hashes_sha256_hash_sequence_digits_letters(void)
{
const char *teststring = "0123456789abcde-0123456789abcde-0123456789abcde-0123456789abcde-";
static const char *teststring = "0123456789abcde-0123456789abcde-0123456789abcde-0123456789abcde-";
TEST_ASSERT(calc_and_compare_hash(teststring, hdigits_letters));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hdigits_letters));
}
static void test_hashes_sha256_hash_sequence_pangramm(void)
{
const char *teststring = "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern";
static const char *teststring = "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern";
TEST_ASSERT(calc_and_compare_hash(teststring, hpangramm));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hpangramm));
}
@ -219,14 +219,14 @@ static void test_hashes_sha256_hash_sequence_pangramm(void)
static void test_hashes_sha256_hash_sequence_pangramm_no_more(void)
{
/* exchanged `z` with `k` of the first word `Fran[z|k]` */
const char *teststring = "Frank jagt im komplett verwahrlosten Taxi quer durch Bayern";
static const char *teststring = "Frank jagt im komplett verwahrlosten Taxi quer durch Bayern";
TEST_ASSERT(calc_and_compare_hash(teststring, hpangramm_no_more));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hpangramm_no_more));
}
static void test_hashes_sha256_hash_sequence_empty(void)
{
const char *teststring = "";
static const char *teststring = "";
TEST_ASSERT(calc_and_compare_hash(teststring, hempty));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hempty));
}
@ -234,33 +234,34 @@ static void test_hashes_sha256_hash_sequence_empty(void)
static void test_hashes_sha256_hash_sequence_failing_compare(void)
{
/* failing compare (sha256 switched last byte of expected hash from `3b` to `3c`) */
char *teststring = "This test fails!";
static const char *teststring = "This test fails!";
TEST_ASSERT(!calc_and_compare_hash(teststring, hfailing_compare));
TEST_ASSERT(!calc_and_compare_hash_wrapper(teststring, hfailing_compare));
}
static void test_hashes_sha256_hash_long_sequence(void)
{
char *teststring = {"RIOT is an open-source microkernel-based operating system, designed"
" to match the requirements of Internet of Things (IoT) devices and"
" other embedded devices. These requirements include a very low memory"
" footprint (on the order of a few kilobytes), high energy efficiency"
", real-time capabilities, communication stacks for both wireless and"
" wired networks, and support for a wide range of low-power hardware."};
static const char *teststring =
{"RIOT is an open-source microkernel-based operating system, designed"
" to match the requirements of Internet of Things (IoT) devices and"
" other embedded devices. These requirements include a very low memory"
" footprint (on the order of a few kilobytes), high energy efficiency"
", real-time capabilities, communication stacks for both wireless and"
" wired networks, and support for a wide range of low-power hardware."};
TEST_ASSERT(calc_and_compare_hash(teststring, hlong_sequence));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, hlong_sequence));
}
static void test_hashes_sha256_hash_sequence_abc(void)
{
char *teststring = "abc";
static const 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";
static const char *teststring = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
TEST_ASSERT(calc_and_compare_hash(teststring, h_fips_multiblock));
TEST_ASSERT(calc_and_compare_hash_wrapper(teststring, h_fips_multiblock));
}