-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.c
109 lines (90 loc) · 4.07 KB
/
tests.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
101
102
103
104
105
106
107
108
109
#include "sha2_common.h"
static int error_occured = 0;
void print_error(int line) {
printf("ERROR on line %d!\n", line);
error_occured = 1;
}
void print_error_arg(int line, size_t arg) {
printf("ERROR on line %d! Output: %lu\n", line, arg);
error_occured = 1;
}
int main () {
#if SHA_BITS==256
size_t size, padded_size;
size = 3;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 64) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 64) print_error_arg(__LINE__, padded_size);
size = 63;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
size = 64;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
size = 65;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
// testing around 5G
size = 5368709119;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
size = 5368709120;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
size = 5368709121;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709184) print_error_arg(__LINE__, padded_size);
#elif SHA_BITS==512
size_t size, padded_size;
size = 3;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 128) print_error_arg(__LINE__, padded_size);
size = 127;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
size = 128;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
size = 129;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 256) print_error_arg(__LINE__, padded_size);
// testing around 5G
size = 5368709119;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
size = 5368709120;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
size = 5368709121;
padded_size = calculate_padded_msg_size(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
padded_size = calculate_padded_msg_size_FIPS_180_4(size);
if (padded_size != 5368709248) print_error_arg(__LINE__, padded_size);
#endif
return error_occured;
}