From: tb Date: Tue, 14 Feb 2023 15:08:15 +0000 (+0000) Subject: Add regress coverage for BN_num_bits_word() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ed0e30432fb226d31993a20c9aa06df981334abf;p=openbsd Add regress coverage for BN_num_bits_word() --- 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 @@ -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; }