summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-02-14 15:08:16 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-02-14 15:08:16 +0000
commit44b474fb468e78f49aec90b8907063c1b2840f8a (patch)
tree6ce4d870aafa522b0ee67a2d0d1d700d7eda857f /regress/lib
parenta9fb324b47c17ca8dc672b0436459d289ffa35c3 (diff)
Add regress coverage for BN_num_bits_word()
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libcrypto/bn/bn_unit.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/regress/lib/libcrypto/bn/bn_unit.c b/regress/lib/libcrypto/bn/bn_unit.c
index 1af3e8868d6..6c5b2107395 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.2 2022/12/06 18:23:29 tb Exp $ */
+/* $OpenBSD: bn_unit.c,v 1.3 2023/02/14 15:08:15 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -69,12 +69,36 @@ test_bn_print_null_derefs(void)
return failed;
}
+static int
+test_bn_num_bits_word(void)
+{
+ BN_ULONG w = 1;
+ int i, num_bits;
+ int failed = 0;
+
+ if ((num_bits = BN_num_bits_word(0)) != 0) {
+ warnx("BN_num_bits_word(0): want 0, got %d", num_bits);
+ failed |= 1;
+ }
+
+ for (i = 0; i < BN_BITS2; i++) {
+ if ((num_bits = BN_num_bits_word(w << i)) != i + 1) {
+ warnx("BN_num_bits_word(0x%llx): want %d, got %d",
+ (unsigned long long)(w << i), i + 1, num_bits);
+ failed |= 1;
+ }
+ }
+
+ return failed;
+}
+
int
main(void)
{
int failed = 0;
failed |= test_bn_print_null_derefs();
+ failed |= test_bn_num_bits_word();
return failed;
}