aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_common_rfc4848s4_encoding_lut_.c
blob: 89b2febea01801c449a9b5b1cb07ede660b3644b (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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


#define ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
NONSTRING const char librecrypt_common_rfc4848s4_encoding_lut_[256u] = MAKE_ENCODING_LUT(ALPHABET);


#else


int
main(void)
{
	size_t i;
	char c;

	SET_UP_ALARM();

	for (i = 0u; i < 64u; i++) {
		c = librecrypt_common_rfc4848s4_encoding_lut_[i];

		/* Check alphabet repeated 4 times (64 characters become 256) */
		EXPECT(librecrypt_common_rfc4848s4_encoding_lut_[i + 64u * 1u] == c);
		EXPECT(librecrypt_common_rfc4848s4_encoding_lut_[i + 64u * 2u] == c);
		EXPECT(librecrypt_common_rfc4848s4_encoding_lut_[i + 64u * 3u] == c);

		/* Check alphabet is valid: */
		/*   printable but not whitespace */
		EXPECT(c > ' ');
		EXPECT(c < '\x7F');
		/*   character does not have special mean */
		EXPECT(c != LIBRECRYPT_HASH_COMPOSITION_DELIMITER);
		EXPECT(c != LIBRECRYPT_ALGORITHM_LINK_DELIMITER);
		EXPECT(c != '*');
		/*   character is not ':' which has special meaning in table files */
		EXPECT(c != ':');
		/*   other characters forbidden by crypt(5) */
		EXPECT(c != ';');
		EXPECT(c != '!');
		EXPECT(c != '\\');

		/* Check encoding LUT matches decoding LUT;
		 * this verifies that characters in the alphabet are unique */
		EXPECT(librecrypt_common_rfc4848s4_decoding_lut_[(unsigned char)c] == i);
	}

	return 0;
}


#endif