From f9781f3238cbce0490220a33ae5ab7896fc771d0 Mon Sep 17 00:00:00 2001 From: tb <> Date: Tue, 14 Feb 2023 15:08:15 +0000 Subject: Add regress coverage for BN_num_bits_word() --- src/regress/lib/libcrypto/bn/bn_unit.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/bn/bn_unit.c b/src/regress/lib/libcrypto/bn/bn_unit.c index 1af3e8868d..6c5b210739 100644 --- a/src/regress/lib/libcrypto/bn/bn_unit.c +++ b/src/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 @@ -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; } -- cgit v1.2.3-55-g6feb