OpenBSD manual page server

Manual Page Search Parameters

BN_NUM_BYTES(3) Library Functions Manual BN_NUM_BYTES(3)

BN_num_bits_word, BN_num_bits, BN_num_bytesget BIGNUM size

#include <openssl/bn.h>

int
BN_num_bits_word(BN_ULONG w);

int
BN_num_bits(const BIGNUM *a);

int
BN_num_bytes(const BIGNUM *a);

() returns the number of significant bits in w, that is, the minimum number of digits needed to write w as a binary number. Except for an argument of 0, this is

floor(log2(w)) + 1
.

BN_ULONG is a macro that expands to unsigned long (= uint64_t) on _LP64 platforms and unsigned int (= uint32_t) elsewhere.

() returns the number of significant bits in the value of the BIGNUM *a, following the same principle as BN_num_bits_word().

() is a macro that returns the number of significant bytes in a, i.e. the minimum number of bytes needed to store the value of a, that is, BN_num_bits(a) divided by eight and rounded up to the next integer number.

BN_num_bits_word() returns the number of significant bits in w or 0 if w is 0. The maximum return value that can occur is BN_BITS2, which is 64 on _LP64 platforms and 32 elsewhere.

BN_num_bits() returns the number of significant bits and BN_num_bytes() the number of significant bytes in a, or 0 if the value of a is 0.

BN_new(3), BN_security_bits(3), DH_size(3), DSA_size(3), RSA_size(3)

BN_num_bytes() and BN_num_bits() first appeared in SSLeay 0.5.1. BN_num_bits_word() first appeared in SSLeay 0.5.2. These functions have been available since OpenBSD 2.4.

Some have tried using BN_num_bits() on individual numbers in RSA keys, DH keys and DSA keys, and found that they don't always come up with the number of bits they expected (something like 512, 1024, 2048, ...). This is because generating a number with some specific number of bits doesn't always set the highest bits, thereby making the number of bits a little smaller. If you want to know the "key size" of such a key, use functions like RSA_size(3), DH_size(3), and DSA_size(3).

November 22, 2022 OpenBSD-7.3