diff options
Diffstat (limited to 'librecrypt_common_rfc4848s4_encoding_lut_.c')
| -rw-r--r-- | librecrypt_common_rfc4848s4_encoding_lut_.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/librecrypt_common_rfc4848s4_encoding_lut_.c b/librecrypt_common_rfc4848s4_encoding_lut_.c new file mode 100644 index 0000000..89b2feb --- /dev/null +++ b/librecrypt_common_rfc4848s4_encoding_lut_.c @@ -0,0 +1,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 |
