From cbe3b01daad36d3ba8f3d2e4c1e0d5645aa44010 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 24 Aug 2024 10:04:37 +0200 Subject: Test partial byte support in SHA1 and SHA-224 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common.h') 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); -- cgit v1.2.3-70-g09d2