aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_algorithms_.c
diff options
context:
space:
mode:
Diffstat (limited to 'librecrypt_algorithms_.c')
-rw-r--r--librecrypt_algorithms_.c67
1 files changed, 47 insertions, 20 deletions
diff --git a/librecrypt_algorithms_.c b/librecrypt_algorithms_.c
index 34c6b3f..0213dff 100644
--- a/librecrypt_algorithms_.c
+++ b/librecrypt_algorithms_.c
@@ -5,14 +5,14 @@
#define ENTRY(ALGO)\
{\
- .get_prefix = &librecrypt__##ALGO##__get_prefix,\
.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,\
+ .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\
}
@@ -39,28 +39,55 @@ main(void)
SET_UP_ALARM();
+ /* Validate algorithm entry */
for (i = 0u; i < count; i++) {
- CHECK(!IS_END_OF_ALGORITHMS(&librecrypt_algorithms_[i]));
- CHECK(librecrypt_algorithms_[i].get_prefix != NULL);
- CHECK(librecrypt_algorithms_[i].is_algorithm != NULL);
- CHECK(librecrypt_algorithms_[i].hash != NULL);
- CHECK(librecrypt_algorithms_[i].test_supported != NULL);
- CHECK(librecrypt_algorithms_[i].make_settings != NULL);
- CHECK(librecrypt_algorithms_[i].encoding_lut != NULL);
- CHECK(librecrypt_algorithms_[i].decoding_lut != NULL);
- CHECK(librecrypt_algorithms_[i].hash_size > 0u);
- CHECK(librecrypt_algorithms_[i].strict_pad >= 0);
- CHECK(librecrypt_algorithms_[i].strict_pad <= 1);
+ /* 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) {
- CHECK(librecrypt_algorithms_[i].pad > ' ');
- CHECK(librecrypt_algorithms_[i].pad < 0x7F);
- CHECK(librecrypt_algorithms_[i].pad != LIBRECRYPT_HASH_COMPOSITION_DELIMITER);
- CHECK(librecrypt_algorithms_[i].pad != LIBRECRYPT_ALGORITHM_LINK_DELIMITER);
- CHECK(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(IS_END_OF_ALGORITHMS(&librecrypt_algorithms_[count]));
+ /* Check that the list has an end-of-list marker */
+ EXPECT(IS_END_OF_ALGORITHMS(&librecrypt_algorithms_[count]));
return 0;
}