blob: 77dfe300b25d647e5d9e001938471208656513dc (
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
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
#define ENTRY(ALGO)\
{\
.is_algorithm = &librecrypt__##ALGO##__is_algorithm,\
.hash = librecrypt__##ALGO##__hash,\
.test_supported = &librecrypt__##ALGO##__test_supported,\
.make_settings = &librecrypt__##ALGO##__make_settings,\
.encoding_lut = librecrypt__##ALGO##__encoding_lut,\
.decoding_lut = librecrypt__##ALGO##__decoding_lut,\
.hash_size = ALGO##__HASH_SIZE,\
.flexible_hash_size = ALGO##__FLEXIBLE_HASH_SIZE,\
.strict_pad = ALGO##__STRICT_PAD,\
.pad = ALGO##__PAD\
}
#define X(ALGO) IF__##ALGO##__SUPPORTED(ENTRY(ALGO) COMMA)
struct algorithm librecrypt_algorithms_[] = {
LIST_ALGORITHMS(X)
END_OF_ALGORITHMS
};
#undef X
#else
int
main(void)
{
#define X(ALGO) IF__##ALGO##__SUPPORTED(+ 1u)
const size_t count = 0u LIST_ALGORITHMS(X);
#undef X
size_t i;
SET_UP_ALARM();
INIT_RESOURCE_TEST();
/* Validate algorithm entry */
for (i = 0u; i < count; i++) {
/* Stop at end-of-list marker */
EXPECT(!IS_END_OF_ALGORITHMS(&librecrypt_algorithms_[i]));
/* Check all functions are set */
EXPECT(librecrypt_algorithms_[i].is_algorithm != NULL);
EXPECT(librecrypt_algorithms_[i].hash != NULL);
EXPECT(librecrypt_algorithms_[i].test_supported != NULL);
EXPECT(librecrypt_algorithms_[i].make_settings != NULL);
/* Check the salt and hash encoding tables are set */
EXPECT(librecrypt_algorithms_[i].encoding_lut != NULL);
EXPECT(librecrypt_algorithms_[i].decoding_lut != NULL);
/* Check .flexible_hash_size is either 0 and 1 */
EXPECT(librecrypt_algorithms_[i].flexible_hash_size >= 0);
EXPECT(librecrypt_algorithms_[i].flexible_hash_size <= 1);
/* Check hash_size is set if .flexible_hash_size is 0 */
if (!librecrypt_algorithms_[i].flexible_hash_size)
EXPECT(librecrypt_algorithms_[i].hash_size > 0u);
/* Check .strict_pad is either 0 and 1 */
EXPECT(librecrypt_algorithms_[i].strict_pad >= 0);
EXPECT(librecrypt_algorithms_[i].strict_pad <= 1);
/* Check .pad is NUL (none) or valid */
if (librecrypt_algorithms_[i].pad) {
/* printable but not whitespace */
EXPECT(librecrypt_algorithms_[i].pad > ' ');
EXPECT(librecrypt_algorithms_[i].pad < 0x7F);
/* does not have special meaning */
EXPECT(librecrypt_algorithms_[i].pad != LIBRECRYPT_HASH_COMPOSITION_DELIMITER);
EXPECT(librecrypt_algorithms_[i].pad != LIBRECRYPT_ALGORITHM_LINK_DELIMITER);
EXPECT(librecrypt_algorithms_[i].pad != '*');
/* is not ':' which has special meaning in table files */
EXPECT(librecrypt_algorithms_[i].pad != ':');
/* other characters forbidden by crypt(5) */
EXPECT(librecrypt_algorithms_[i].pad != '!');
EXPECT(librecrypt_algorithms_[i].pad != ';');
EXPECT(librecrypt_algorithms_[i].pad != '\\');
}
}
/* Check number of algorithms in the list was the number of supported algorithms */
assert(i == count);
/* Check that the list has an end-of-list marker */
EXPECT(IS_END_OF_ALGORITHMS(&librecrypt_algorithms_[count]));
STOP_RESOURCE_TEST();
return 0;
}
#endif
|