aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 10:04:37 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 10:04:37 +0200
commitcbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010 (patch)
tree128aa07e1a8e8bb2738b4b3db40d455d2151952c /common.h
parentStandardise how to interpret a partial byte (diff)
downloadlibhashsum-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.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/common.h b/common.h
index e70d922..3d0972c 100644
--- a/common.h
+++ b/common.h
@@ -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);