summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2023-06-21 07:15:39 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2023-06-21 07:15:39 +0000
commit8e13ad6a5f5675e147370f727f69297e781b34d3 (patch)
tree03a41a615fcf8bc7861150a5b56598fa789243e7 /regress
parent0d6acdfcc5c7a6e183d046d16672b249f9daf8f0 (diff)
Add a BN_num_bits() with zero padded input.
Currently BN_hex2bn() removes the leading zeros, however this will not be the case in the future.
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libcrypto/bn/bn_unit.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/regress/lib/libcrypto/bn/bn_unit.c b/regress/lib/libcrypto/bn/bn_unit.c
index bc49192b8c2..3a88bfca6e6 100644
--- a/regress/lib/libcrypto/bn/bn_unit.c
+++ b/regress/lib/libcrypto/bn/bn_unit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_unit.c,v 1.6 2023/06/20 06:46:07 tb Exp $ */
+/* $OpenBSD: bn_unit.c,v 1.7 2023/06/21 07:15:38 jsing Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -80,7 +80,7 @@ test_bn_num_bits(void)
errx(1, "BN_new");
if ((num_bits = BN_num_bits(bn)) != 0) {
- warnx("BN_num_bits(0): want 0, got %d", num_bits);
+ warnx("BN_num_bits(0): got %d, want 0", num_bits);
failed |= 1;
}
@@ -89,14 +89,23 @@ test_bn_num_bits(void)
for (i = 0; i <= 5 * BN_BITS2; i++) {
if ((num_bits = BN_num_bits(bn)) != i + 1) {
- warnx("BN_num_bits(1 << %d): want %d, got %d",
- i, i + 1, num_bits);
+ warnx("BN_num_bits(1 << %d): got %d, want %d",
+ i, num_bits, i + 1);
failed |= 1;
}
if (!BN_lshift1(bn, bn))
errx(1, "BN_lshift1");
}
+ if (BN_hex2bn(&bn, "0000000000000000010000000000000000") != 34)
+ errx(1, "BN_hex2bn");
+
+ if ((num_bits = BN_num_bits(bn)) != 65) {
+ warnx("BN_num_bits(1 << 64) padded: got %d, want %d",
+ num_bits, 65);
+ failed |= 1;
+ }
+
BN_free(bn);
return failed;