aboutsummaryrefslogtreecommitdiffstats
path: root/t/blake224.c
blob: 95e0f45af7dac3e6cb234fac1e580bcdbbfb746f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* See LICENSE file for copyright and license details. */
#ifdef SUPPORT_BLAKE224
# define TEST
# include "../common.h"


static struct testcase testcases[] = {
	{1, 0, "", "7dc5313b1c04512a174bd6503b89607aecbee0903d40a8a569c94eed"},
	{0, 1, "\xff", "6f464fcaa901babeb27cb94dea4aca966756a1759a24e3cae93f3a05"},
	{0, 1, "\x7f", "6f464fcaa901babeb27cb94dea4aca966756a1759a24e3cae93f3a05"},
	{0, 1, "\x01", "6f464fcaa901babeb27cb94dea4aca966756a1759a24e3cae93f3a05"},
	{0, 1, "\xfe", "615b9bd1077a8270d4f647799ffaaf87c03d72efd37e4947fcf01cca"},
	{0, 1, "\x7e", "615b9bd1077a8270d4f647799ffaaf87c03d72efd37e4947fcf01cca"},
	{1, 1, "\x00", "615b9bd1077a8270d4f647799ffaaf87c03d72efd37e4947fcf01cca"},
	{1, 2, "\x03", "6a829dca3a3d0d35762d7b0f9a2c8379c32415c87a8ad773fefec19f"},
	{1, 3, "\x03", "5478a106aca2b539d5bd52db8b19717d436ca27c14ef99ed565bc4a7"},
	{1, 4, "\x01", "2b10ebc335731de6148ce84ed05a2685b9c274105c6aaf1dd59ef000"},
	{1, 5, "\x12", "a49e36fd01041a0a86eb12d7f110bf4ef798b686fff48e5abc6bc8b4"},
	{1, 6, "\x0a", "57036a8ad47cb24e0f329ef991b571211f171bf86f546aa068577cb5"},
	{1, 7, "\x19", "82417e4fdb2b426d125415b10fe7dae7e944291f8daeb049b80e93a0"},
	{1, 8, "\xcc", "5e21c1e375c7bc822046fad96910c95031bd4262ada71b4c91052fea"},
	{1, 9, "\x98\x00", "30df15eb42922a41c1ef59102115d2f656e94f39fd1eeca115a9a07a"},
	{1, 10, "\x9d\x02", "5c6c22d948c98644057c9ad31107164ecda652f4c51abd8cc4652ee6"},
	{1, 11, "\xaa\x01", "276babfb45f0da4ddce7012d009122cdb974702cce1fcc83e0b254af"},
	{1, 12, "\x98\x0c", "5dd804d86cc32084c81caea4ee5b472b2ba6e8c17eb2ff982e9e885b"},
	{1, 13, "\x50\x0c", "e3d122c703be5ebca4ecc1860a8f50cff518c3984d3605f3c98bb52b"},
	{1, 14, "\x4d\x24", "35e05b766f7fcfb136e62cef59400b3e776f74e69a16912a9e7a9d78"},
	{1, 15, "\xcb\x7b", "227804938f7d63d96a54778f71bfb7421dcf056ddd78ab8b739a7a2e"},
	{1, 16, "\x41\xfb", "195707e8ce71fb91c2c82ccf78022609a598bd80c9a505ef035314db"},
	{1, 17, "\x4f\xf4\x00", "86113100dd674ebf5d0c36b609d9ab8bbd8ecb5d54b0a5aaea9d5e1d"},
	{1, 18, "\xfd\x04\x02", "608997b3ae1483e0298a08d816029d112124743cde703dd0350edbe9"},
	{1, 19, "\x42\x4d\x00", "89f898843d7ab0bb50ac8f6d1139e18aca0ef1d4e95b089ec2172685"},
	{1, 20, "\x3f\xde\x07", "280cee22ba45b2ff9dfa70462cd34c106a24842c6a247f74ade67158"},
	{1, 21, "\x33\x57\x16", "780f1fb7fd80898a10e9c6d63d212372bf7f6b3cd6a6c231ee5daa9b"},
	{1, 22, "\x05\x1e\x3e", "0296e4a199194d5b65aa40fb0ec33870e36daa3e2e962d2c5b6f3a99"},
	{1, 23, "\x71\x7f\x31", "1e95aa999a1a68c1c5191d2365664415344ed1673cb6c12a849abf0a"},
	{1, 24, "\x1f\x87\x7c", "4239b4afa926f2269b117059dc0310033c9c85acea1a031f97cd4e2a"},
	{1, 25, "\xeb\x35\xcf\x01", "dfd3f804fbc9ad5805fc5b529c1d0564e96454710d0b21d561357ac5"},
	{1, 26, "\xb4\x06\xc4\x01", "e1fd87c6396d42e19713290547cc324268c27b7fa40398ed3797b148"},
	{1, 27, "\xce\xe8\x80\x02", "dfebe7b56e9247d4023cecda04c28e1fc4eb6049fa27a747f75d832d"},
	{1, 28, "\xc5\x84\xdb\x0e", "79737f20528fac047c7ea52a2a295bd7ce15087773747cb450be6874"},
	{1, 29, "\x53\x58\x7b\x13", "de42f62c6eeddc5bd80fdf52edcf64754d875bb2b214d5e715833270"},
	{1, 30, "\x69\xa3\x05\x0d", "328a913d190fa087c58958a321138400e5a9e9a8983c9853c0b932ea"},
	{1, 31, "\xc9\x37\x5e\x73", "efa18a9d2ada4755c260482989442f21b8c5b2e09155517e201d269e"},
	{1, 32, "\xc1\xec\xfd\xfc", "9cd80af6d0181b831e1879959f287735c9cbf5d1e480e7341266d6f0"},
	{1, 33, "\x8d\x73\xe8\xa2\x01", "2849a31c29e378fa9eef77ad80043e822c70cde973cb99a4a7f21a07"},
	{1, 34, "\x06\xf2\x52\x20\x01", "d9315ee5d1e33178363ddfdd7d595e0ba4a6d82522500e27ed3075ae"},
	{1, 35, "\x3e\xf6\xc3\x6f\x04", "40663b7856cfb2d57987a85dbd76c447dcf582481912c9a373924127"},
	{1, 36, "\x01\x27\xa1\xd3\x02", "61a5fdead981d711d72d3dc5cfe7f8c40916ce16a42a97cb7b8a016e"},
	{1, 37, "\x6a\x6a\xb6\xc2\x08", "a63d8d4a5239c7132031c1ca6527ebe3e7d6d647124fafdf5f123de2"},
	{1, 38, "\xaf\x31\x75\xe1\x06", "3e7c863db3e16c2350a44e161a2aa3810764cf523c62ab71999a9d24"},
	{1, 39, "\xb6\x66\x09\xed\x61", "e3b7ce19f60913cd5aa1d43bd92de285f72163e0f9453f4e5f21bf52"},
	{1, 40, "\x21\xf1\x34\xac\x57", "9e908983741757ff632c01f2b2c4d7f1ec8e642d112c212ba9739fd1"},
	{1, 41, "\x3d\xc2\xaa\xdf\xfc\x01", "4e1a8c57c3713217530a5f667b37f6bc23939d2fb43dea9745f50068"},
	{1, 42, "\x92\x02\x73\x6d\x22\x02", "a3c9ece5a71fed7c2e58bfd0b67fcf286668c2bcc31826c1b4cd6d59"},
	{1, 43, "\xf2\x19\xbd\x62\x98\x04", "f087f490d55044aa4d147f79d0f1e980fdba1d78cacb5999ff9e67ca"},
	{1, 44, "\xf3\x51\x1e\xe2\xc4\x0d", "49da5bdbc1fe187a28cbd493f383108ff1c6bcd71b3fef2c742074a5"},
	{1, 45, "\x3e\xca\xb6\xbf\x77\x04", "2143ed11184621cb64716a451688291bd0799574f2a28537885540be"},
	{1, 46, "\xcd\x62\xf6\x88\xf4\x19", "0874dba67485be94b9f5a500fade53c94622573059a7fd78f50d0309"},
	{1, 47, "\xc2\xcb\xaa\x33\xa9\x1f", "2e14b39f6de58b0fdd67b9c45eae6c3ff71a363defea06975410e25a"},
	{1, 48, "\xc6\xf5\x0b\xb7\x4e\x29", "6d6d952053aead200de9daa856c2993a7a7fa4a15b3924fb77dbb384"},
	{1, 49, "\x79\xf1\xb4\xcc\xc6\x2a\x00", "ad93ea3f245493cf2b660d6f5fe82b8bfb0d3394854e88c2704c98c2"}
};


#else
# define TEST_UNSUPPORTED
# include "../common.h"
#endif


static int
kat_test(void)
{
	TEST_MAIN("BLAKE224", BLAKE224, 1);
}


int
main(void)
{
#ifdef SUPPORT_BLAKE224
	struct libhashsum_hasher hasher1, hasher2;
	char salt1[16], salt2[16];
#endif

	int r = kat_test();
	if (r)
		return r;

#ifdef SUPPORT_BLAKE224
	memset(salt1, 0, sizeof(salt1));
	memset(salt2, 0xAB, sizeof(salt2));

	ASSERT(!libhashsum_init_blake224_hasher(&hasher1, NULL));
	ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt1));
	ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224"));
	ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224"));
	ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0));
	ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0));
	ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size));

	ASSERT(!libhashsum_init_blake224_hasher(&hasher1, NULL));
	ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt1));
	ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0));
	ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0));
	ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size));

	ASSERT(!libhashsum_init_blake224_hasher(&hasher1, salt1));
	ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt2));
	ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224"));
	ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224[salt=abababababababababababababababab]"));
	ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0));
	ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0));
	ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size));

	ASSERT(!libhashsum_init_blake224_hasher(&hasher1, salt1));
	ASSERT(!libhashsum_init_blake224_hasher(&hasher2, salt2));
	ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0));
	ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0));
	ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size));

	ASSERT(!libhashsum_init_hasher_from_string(&hasher1, "BLAKE224[salt=00000000000000000000000000000000]"));
	ASSERT(!libhashsum_init_hasher_from_string(&hasher2, "BLAKE224[salt=abababababababababababababababab]"));
	ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE224"));
	ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE224[salt=abababababababababababababababab]"));
	ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0));
	ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0));
	ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size));
#endif

	return 0;
}