diff options
author | Mattias Andrée <maandree@kth.se> | 2022-02-26 22:56:28 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-02-26 22:56:28 +0100 |
commit | cb299842e5710ddcc4be7e6d3a28cfd4f64a72af (patch) | |
tree | dce24aacf5a9d54d2194fdcec2e1633fe8dc8c42 | |
parent | Add some known-answer tests (diff) | |
download | libkeccak-cb299842e5710ddcc4be7e6d3a28cfd4f64a72af.tar.gz libkeccak-cb299842e5710ddcc4be7e6d3a28cfd4f64a72af.tar.bz2 libkeccak-cb299842e5710ddcc4be7e6d3a28cfd4f64a72af.tar.xz |
Add tests for byte-incomplete output
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | test.c | 76 |
1 files changed, 75 insertions, 1 deletions
@@ -760,6 +760,74 @@ test_digest_bits(void) /** + * Run test cases for `libkeccak_digest` with + * outputs that are not multiples of 8 + * + * @return Zero on success, -1 on error + */ +static int +test_digest_trunc(void) +{ +#define shake(semicapacity, output, output_lastbyte)\ + (printf(" Testing SHAKE-"#semicapacity"('', %i): ", output),\ + libkeccak_spec_shake(&spec, semicapacity, output),\ + test_digest_case(&spec, LIBKECCAK_SHAKE_SUFFIX, "", 0, INCOMPLETE_ANSWER output_lastbyte)) +#define INCOMPLETE_ANSWER\ + "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef263cb1eea988004b93103cfb0aeefd2a68"\ + "6e01fa4a58e8a3639ca8a1e3f9ae57e235b8cc873c23dc62b8d260169afa2f75ab916a58d974918835d25e6a435085b2"\ + "badfd6dfaac359a5efbb7bcc4b59d538df9a04302e10c8bc1cbf1a0b3a5120ea17cda7cfad765f5623474d368ccca8af"\ + "0007cd9f5e4c849f167a580b14aabdefaee7eef47cb0fca9767be1fda69419dfb927e9df07348b196691abaeb580b32d"\ + "ef58538b8d23f87732ea63b02b4fa0f4873360e2841928cd60dd4cee8cc0d4c922a96188d032675c8ac850933c7aff15"\ + "33b94c834adbb69c6115bad4692d8619f90b0cdf8a7b9c264029ac185b70b83f2801f2f4b3f70c593ea3aeeb613a7f1b"\ + "1de33fd75081f592305f2e4526edc09631b10958f464d889f31ba010250fda7f1368ec2967fc84ef2ae9aff268e0b170"\ + "0affc6820b523a3d917135f2dff2ee06bfe72b3124721d4a26c04e53a75e30e73a7a9c4a95d91c55d495e9f51dd0b5e9"\ + "d83c6d5e8ce803aa62b8d654db53d09b8dcff273cdfeb573fad8bcd45578bec2e770d01efde86e721a3f7c6cce275dab"\ + "e6e2143f1af18da7efddc4c7b70b5e345db93cc936bea323491ccb38a388f546a9ff00dd4e1300b9b2153d2041d205b4"\ + "43e41b45a653f2a5c4492c1add544512dda2529833462b71a41a45be97290b" + + + struct libkeccak_spec spec; + + printf("Testing libkeccak_digest with byte-incomplete output:\n"); + + + if (shake(128, 4096, "6f")) + return -1; + + if (shake(128, 4095, "6f")) + return -1; + + if (shake(128, 4094, "2f")) + return -1; + + if (shake(128, 4093, "0f")) + return -1; + + if (shake(128, 4092, "0f")) + return -1; + + if (shake(128, 4091, "07")) + return -1; + + if (shake(128, 4090, "03")) + return -1; + + if (shake(128, 4089, "01")) + return -1; + + if (shake(128, 4088, "")) + return -1; + + + printf("\n"); + return 0; + +#undef shake +#undef INCOMPLETE_ANSWER +} + + +/** * Run a test case for `libkeccak_update` * * @param spec The specification for the hashing @@ -1107,7 +1175,13 @@ main(void) } printf("\n"); - if (test_hex() || test_state(&spec) || test_digest() || test_digest_bits() || test_update() || test_squeeze()) + if (test_hex() || + test_state(&spec) || + test_digest() || + test_digest_bits() || + test_digest_trunc() || + test_update() || + test_squeeze()) return 1; if (test_file(&spec, LIBKECCAK_SHA3_SUFFIX, ".testfile", |