From aaea8ada220cf53ceff4705ed498d0fe4f0476e4 Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 10 Jul 2023 20:21:37 +0000 Subject: [PATCH] Add test case for negative number with highest bit of top octet set This currently adds an incorrect 00: padding, consistent with OpenSSL's behavior. --- regress/lib/libcrypto/bn/bn_print.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/regress/lib/libcrypto/bn/bn_print.c b/regress/lib/libcrypto/bn/bn_print.c index 24f261d921d..47def85773c 100644 --- a/regress/lib/libcrypto/bn/bn_print.c +++ b/regress/lib/libcrypto/bn/bn_print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_print.c,v 1.3 2023/07/07 07:47:25 tb Exp $ */ +/* $OpenBSD: bn_print.c,v 1.4 2023/07/10 20:21:37 tb Exp $ */ /* * Copyright (c) 2023 Theo Buehler @@ -139,6 +139,11 @@ const struct print_test { .want = " mana mana\n" " 00:80:00:00:00:00:00:00:00:00\n", }, + { + .desc = "high bit of first nibble is set for negative number", + .want = " mana mana (Negative)\n" + " 00:80:00:00:00:00:00:00:00:00\n", + }, }; #define N_TESTCASES (sizeof(bn_print_tests) / sizeof(bn_print_tests[0])) @@ -281,6 +286,13 @@ main(void) test = &bn_print_tests[testcase++]; failed |= bn_print_testcase(bn, test); + /* high bit of first nibble is set for negative number. */ + BN_set_negative(bn, 1); + if (testcase >= N_TESTCASES) + errx(1, "Too many tests"); + test = &bn_print_tests[testcase++]; + failed |= bn_print_testcase(bn, test); + if (testcase != N_TESTCASES) { warnx("Not all tests run"); failed |= 1; -- 2.20.1