Blame doc/man3/BN_num_bytes.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/bn.h>
Packit c4476c
Packit c4476c
 int BN_num_bytes(const BIGNUM *a);
Packit c4476c
Packit c4476c
 int BN_num_bits(const BIGNUM *a);
Packit c4476c
Packit c4476c
 int BN_num_bits_word(BN_ULONG w);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
BN_num_bytes() returns the size of a B<BIGNUM> in bytes.
Packit c4476c
Packit c4476c
BN_num_bits_word() returns the number of significant bits in a word.
Packit c4476c
If we take 0x00000432 as an example, it returns 11, not 16, not 32.
Packit c4476c
Basically, except for a zero, it returns I<floor(log2(w))+1>.
Packit c4476c
Packit c4476c
BN_num_bits() returns the number of significant bits in a B<BIGNUM>,
Packit c4476c
following the same principle as BN_num_bits_word().
Packit c4476c
Packit c4476c
BN_num_bytes() is a macro.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
The size.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
Some have tried using BN_num_bits() on individual numbers in RSA keys,
Packit c4476c
DH keys and DSA keys, and found that they don't always come up with
Packit c4476c
the number of bits they expected (something like 512, 1024, 2048,
Packit c4476c
...).  This is because generating a number with some specific number
Packit c4476c
of bits doesn't always set the highest bits, thereby making the number
Packit c4476c
of I<significant> bits a little lower.  If you want to know the "key
Packit c4476c
size" of such a key, either use functions like RSA_size(), DH_size()
Packit c4476c
and DSA_size(), or use BN_num_bytes() and multiply with 8 (although
Packit c4476c
there's no real guarantee that will match the "key size", just a lot
Packit c4476c
more probability).
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<DH_size(3)>, L<DSA_size(3)>,
Packit c4476c
L<RSA_size(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut