-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.c
100 lines (94 loc) · 3.57 KB
/
test.c
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
/*
lonesha256.h test by comparison with known hashes of strings, also serves as usage example
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring
rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software.
If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
/*
Compile using "gcc test.c" or equivalent, then run from command line to see the results.
If you find an error in this test or a test pair which lonesha256 fails, please open an issue.
*/
//includes
#define LONESHA256_STATIC
#include "lonesha256.h"
#include <stdio.h>
//structs
struct pair {
unsigned char* in; //input string
unsigned char out[32]; //expected output
};
//known input/output pairs
struct pair pairs[] = {
//0: empty string
{
"",
{0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55}
},
//1: foobar string
{
"foobar",
{0xC3, 0xAB, 0x8F, 0xF1, 0x37, 0x20, 0xE8, 0xAD,
0x90, 0x47, 0xDD, 0x39, 0x46, 0x6B, 0x3C, 0x89,
0x74, 0xE5, 0x92, 0xC2, 0xFA, 0x38, 0x3D, 0x4A,
0x39, 0x60, 0x71, 0x4C, 0xAE, 0xF0, 0xC4, 0xF2}
},
//2: quick brown fox
{
"The quick brown fox jumps over the lazy dog",
{0xD7, 0xA8, 0xFB, 0xB3, 0x07, 0xD7, 0x80, 0x94,
0x69, 0xCA, 0x9A, 0xBC, 0xB0, 0x08, 0x2E, 0x4F,
0x8D, 0x56, 0x51, 0xE4, 0x6D, 0x3C, 0xDB, 0x76,
0x2D, 0x02, 0xD0, 0xBF, 0x37, 0xC9, 0xE5, 0x92}
},
//3: random string
{
"dThNFRWWhyG7pINI",
{0x64, 0x13, 0x46, 0x80, 0xDC, 0x26, 0x6E, 0x5D,
0xFF, 0xE3, 0x83, 0xBD, 0xC4, 0xD1, 0x98, 0xC3,
0xA3, 0x59, 0x2C, 0x36, 0xB4, 0x78, 0xCE, 0xBE,
0xD6, 0x6C, 0x15, 0x8F, 0x78, 0x82, 0x5A, 0x28}
},
//4: longer string
{
"laSQWLJtfvdfSvH9MaJC32tk59jpm3ZOkfQX2E308aUqgyqY"
"Tq2hOyoLJaujn4ULaFDEb65ISERxjSqovIiccU1q8TxsBwm6"
"qodWbY3mUdPL0YuRrN9RggDzkvHQz91XbpoItjPB7mxtzILt"
"lypZtfJY3A3xh0B4ZrsRM2FTtcircLWRfDOpGIGbQcJoXeZq"
"vKdvzrGbs6oG8wKAYKn51j3aQDNmENXGlYR06eRXFyctEU3g"
"HDaXB6shHCa621wAIPn3ZjtaPzkYjFIQv2NwAnmLCSxOlhqs"
"pCoaNVwHfHc6bc3c0Ani6f8Gto3lfrEMwLaPkxOEXuh4SK5w"
"0qWQdahu4LNqoqT7KI7uuwXiMMzw6Y7ySK3u37VJ8msDNI6f"
"0nRHEfROfhK2Yf3FVGItOcNBQDUa4BeuAJgt",
{0xCD, 0x6F, 0x3B, 0x5E, 0x08, 0xC3, 0x41, 0x62,
0xCB, 0xD5, 0x19, 0x0D, 0xA8, 0xCD, 0x45, 0xF7,
0x63, 0x7E, 0x15, 0x13, 0x8A, 0x39, 0x62, 0x90,
0x03, 0x68, 0x97, 0xB3, 0x18, 0x84, 0x26, 0xFE}
},
//5: 56 spaces
{
" ",
{0xB6, 0x0C, 0x4C, 0x2D, 0x56, 0x5C, 0xD1, 0xF1,
0x0E, 0xEB, 0x0D, 0xEF, 0xFD, 0xD7, 0xB6, 0x5F,
0xDF, 0x9D, 0x4F, 0xD3, 0x96, 0x08, 0x68, 0xDA,
0x68, 0xE3, 0x53, 0x31, 0x59, 0xB7, 0x0B, 0xD8}
}
};
//main function
int main () {
//runs through all the hard-coded pairs, then returns
for (int i = 0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
unsigned char out[32];
if (lonesha256(out, pairs[i].in, strlen(pairs[i].in)))
printf("TEST %d: ERROR\n", i);
else if (memcmp(out, pairs[i].out, sizeof(out)))
printf("TEST %d: FAILED\n", i);
else
printf("TEST %d: PASSED\n", i);
}
//return
return 0;
}