diff options
| author | Mattias Andrée <m@maandree.se> | 2026-09-23 20:16:23 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-09-23 20:16:23 +0200 |
| commit | a89353a992abfcf12606f065a9f6bec798c21bee (patch) | |
| tree | dc244fb1a06a912a8158ecbd7826796b0266141a /librecrypt_hash_binary.c | |
| parent | m header file organisation improvement (diff) | |
| download | librecrypt-a89353a992abfcf12606f065a9f6bec798c21bee.tar.gz librecrypt-a89353a992abfcf12606f065a9f6bec798c21bee.tar.bz2 librecrypt-a89353a992abfcf12606f065a9f6bec798c21bee.tar.xz | |
More testing
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | librecrypt_hash_binary.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/librecrypt_hash_binary.c b/librecrypt_hash_binary.c index 398f7e3..35bd0ed 100644 --- a/librecrypt_hash_binary.c +++ b/librecrypt_hash_binary.c @@ -201,6 +201,9 @@ static const struct librecrypt_algorithm trunc_algo = { #define TEST_HASH_ROT4_TRUNC "8j93l0@@" #define TEST_HASH_ROT4_TRUNC6 "8j93l6lS" #define TEST_HASH_TRUNC_TRUNC6 "4ycQhg00" +#define WRONG_HASH_ROT4 "AAAAAAAAAAA#" +#define WRONG_HASH_TRUNC "000000@@" +#define WRONG_HASH_TRUNC6 "00000000" #define SP4 " " #define SP20 SP4 SP4 SP4 SP4 SP4 @@ -264,8 +267,10 @@ check(const char *phrase, const char *settings, const char *chain, const char *h do {\ size_t scratchsize = GET_SCRATCH_SIZE(HASHLEN);\ if (IS_DEFAULT_HASHLEN >= 0) {\ - check(PHRASE, CONF HASH, CONF "*" #HASHLEN ">" CONF HASH, HASH, (size_t)HASHLEN, scratchsize, ctx);\ - check(PHRASE, CONF "*" #HASHLEN, CONF "*" #HASHLEN ">" CONF "*" #HASHLEN, HASH, (size_t)HASHLEN, scratchsize, ctx);\ + check(PHRASE, CONF HASH, CONF "*" #HASHLEN ">" CONF HASH,\ + HASH, (size_t)HASHLEN, scratchsize, ctx);\ + check(PHRASE, CONF "*" #HASHLEN, CONF "*" #HASHLEN ">" CONF "*" #HASHLEN,\ + HASH, (size_t)HASHLEN, scratchsize, ctx);\ }\ if (IS_DEFAULT_HASHLEN) {\ check(PHRASE, CONF, CONF ">" CONF, HASH, (size_t)HASHLEN, scratchsize, ctx);\ @@ -274,6 +279,18 @@ check(const char *phrase, const char *settings, const char *chain, const char *h } while (0) +#define CHECK_DIFF(PHRASE, CONF, HASHLEN, IS_DEFAULT_HASHLEN /* -1 if fixed */, HASH, DIFFHASH)\ + do {\ + size_t scratchsize = GET_SCRATCH_SIZE(HASHLEN);\ + if (IS_DEFAULT_HASHLEN >= 0) {\ + check(PHRASE, CONF DIFFHASH, CONF "*" #HASHLEN ">" CONF DIFFHASH,\ + HASH, (size_t)HASHLEN, scratchsize, ctx);\ + }\ + if (IS_DEFAULT_HASHLEN)\ + check(PHRASE, CONF DIFFHASH, CONF ">" CONF DIFFHASH, HASH, (size_t)HASHLEN, scratchsize, ctx);\ + } while (0) + + #define CHECK_BAD(ALGO)\ do {\ errno = 0;\ @@ -371,6 +388,18 @@ main(void) CHECK(TEST_PHRASE, "$trunc$*6>$trunc$", 4, 1, TEST_HASH_TRUNC); CHECK(TEST_PHRASE, "$trunc$*6>$trunc$", 6, 0, TEST_HASH_TRUNC6); CHECK(TEST_PHRASE, "$rot4$>$rot4$", 8, -1, TEST_PHRASE64_ROT4); + CHECK_DIFF(TEST_PHRASE, "$trunc$", 4, 1, TEST_HASH_TRUNC, WRONG_HASH_TRUNC); + CHECK_DIFF(TEST_PHRASE, "$trunc$", 6, 0, TEST_HASH_TRUNC6, WRONG_HASH_TRUNC6); + CHECK_DIFF(TEST_PHRASE, "$rot4$", 8, -1, TEST_HASH_ROT4, WRONG_HASH_ROT4); + CHECK_DIFF(TEST_PHRASE, "$rot4$>$trunc$", 4, 1, TEST_HASH_ROT4_TRUNC, WRONG_HASH_TRUNC); + CHECK_DIFF(TEST_PHRASE, "$rot4$>$trunc$", 6, 0, TEST_HASH_ROT4_TRUNC6, WRONG_HASH_TRUNC6); + CHECK_DIFF(TEST_PHRASE, "$trunc$>$rot4$", 8, -1, TEST_HASH_TRUNC_ROT4, WRONG_HASH_ROT4); + CHECK_DIFF(TEST_PHRASE, "$trunc$*6>$rot4$", 8, -1, TEST_HASH_TRUNC6_ROT4, WRONG_HASH_ROT4); + CHECK_DIFF(TEST_PHRASE, "$trunc$>$trunc$", 4, 1, TEST_HASH_TRUNC, WRONG_HASH_TRUNC); + CHECK_DIFF(TEST_PHRASE, "$trunc$>$trunc$", 6, 0, TEST_HASH_TRUNC_TRUNC6, WRONG_HASH_TRUNC6); + CHECK_DIFF(TEST_PHRASE, "$trunc$*6>$trunc$", 4, 1, TEST_HASH_TRUNC, WRONG_HASH_TRUNC); + CHECK_DIFF(TEST_PHRASE, "$trunc$*6>$trunc$", 6, 0, TEST_HASH_TRUNC6, WRONG_HASH_TRUNC6); + CHECK_DIFF(TEST_PHRASE, "$rot4$>$rot4$", 8, -1, TEST_PHRASE64_ROT4, WRONG_HASH_ROT4); #undef GET_SCRATCH_SIZE librecrypt_free_context(ctx); |
