
#use wml::openssl-macros area=docs page=BN_num_bytes

<title>Documents, BN_num_bytes(3)</title>

<h1>BN_num_bytes(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BN_num_bits, BN_num_bytes, BN_num_bits_word - get BIGNUM size

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bn.h&gt;
</PRE>
<PRE> int BN_num_bytes(const BIGNUM *a);
</PRE>
<PRE> int BN_num_bits(const BIGNUM *a);
</PRE>
<PRE> int BN_num_bits_word(BN_ULONG w);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BN_num_bytes()</CODE> returns the size of a <STRONG>BIGNUM</STRONG> in bytes.

</P>
<P>
<CODE>BN_num_bits_word()</CODE> returns the number of significant bits in a
word. If we take 0x00000432 as an example, it returns 11, not 16, not 32.
Basically, except for a zero, it returns <EM>floor(log2(w))+1</EM>.

</P>
<P>
<CODE>BN_num_bits()</CODE> returns the number of significant bits in a <STRONG>BIGNUM</STRONG>, following the same principle as <CODE>BN_num_bits_word().</CODE>

</P>
<P>
<CODE>BN_num_bytes()</CODE> is a macro.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
The size.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
Some have tried using <CODE>BN_num_bits()</CODE> 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 <EM>significant</EM> bits a little lower. If you want to know the ``key size'' of such a key,
either use functions like <CODE>RSA_size(),</CODE> <CODE>DH_size()</CODE>
and <CODE>DSA_size(),</CODE> or use <CODE>BN_num_bytes()</CODE> and
multiply with 8 (although there's no real guarantee that will match the
``key size'', just a lot more probability).

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/bn.html#">bn(3)</A>, <A HREF="../crypto/DH_size.html#">DH_size(3)</A>, <A HREF="../crypto/DSA_size.html#">DSA_size(3)</A>,
<A HREF="../crypto/RSA_size.html#">RSA_size(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>BN_num_bytes(),</CODE> <CODE>BN_num_bits()</CODE> and
<CODE>BN_num_bits_word()</CODE> are available in all versions of SSLeay and
OpenSSL.

</P>
:}

