diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-24 10:04:37 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-24 10:04:37 +0200 |
commit | cbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010 (patch) | |
tree | 128aa07e1a8e8bb2738b4b3db40d455d2151952c /common.h | |
parent | Standardise how to interpret a partial byte (diff) | |
download | libhashsum-cbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010.tar.gz libhashsum-cbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010.tar.bz2 libhashsum-cbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010.tar.xz |
Test partial byte support in SHA1 and SHA-224
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -126,9 +126,11 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz return 2; } for (j = 0; j < testcases[i].input_repeat; j++) { - p = memcpy(p, testcases[i].input, input_string_len); + memcpy(p, testcases[i].input, input_string_len); p = &p[input_string_len]; } + if (bits) + *p = testcases[i].input[input_string_len]; if (hasher.finalise(&hasher, input, input_total_len, (unsigned)bits, input_size)) { perror("hasher.finalise"); return 2; @@ -160,6 +162,12 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz if (testcases[i].input_repeat == 1) printf("[\033[1;%s\033[m] %s(\"%s\"%s) = %s\n", caseok ? "32mPASS" : "31mFAIL", name, input, bitstr, hexsum); + else if (!testcases[i].input_repeat && *bitstr) + printf("[\033[1;%s\033[m] %s(%s) = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, &bitstr[3], hexsum); + else if (!testcases[i].input_repeat) + printf("[\033[1;%s\033[m] %s(\"\") = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, hexsum); else printf("[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n", caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum); |