diff options
| author | schwarze <> | 2022-11-22 18:55:04 +0000 |
|---|---|---|
| committer | schwarze <> | 2022-11-22 18:55:04 +0000 |
| commit | 5a9e2017d44311cc61942a4b59d39f5d6eb1f00c (patch) | |
| tree | a521d678044c52b1efcfd92c026b33f03cc58a84 | |
| parent | 0284f8e696514160e33e4f03f00254ae815b0014 (diff) | |
| download | openbsd-5a9e2017d44311cc61942a4b59d39f5d6eb1f00c.tar.gz openbsd-5a9e2017d44311cc61942a4b59d39f5d6eb1f00c.tar.bz2 openbsd-5a9e2017d44311cc61942a4b59d39f5d6eb1f00c.zip | |
Better document BN_ULONG (in the DESCRIPTION near BN_num_bits_word(3))
and BN_BITS2 (below RETURN VALUES).
While here, perform major reordering and rewriting
for precision and readability, in particular:
- Avoid misleading wordings like "size of a BIGNUM".
- Drop the trivial example.
- Move the pointers to RSA_size(3) and friends to CAVEATS.
- Stop recommending 8*BN_num_bytes() in this context because it is wrong, too.
| -rw-r--r-- | src/lib/libcrypto/man/BN_num_bytes.3 | 124 |
1 files changed, 84 insertions, 40 deletions
diff --git a/src/lib/libcrypto/man/BN_num_bytes.3 b/src/lib/libcrypto/man/BN_num_bytes.3 index f1a995f000..785f43e2f0 100644 --- a/src/lib/libcrypto/man/BN_num_bytes.3 +++ b/src/lib/libcrypto/man/BN_num_bytes.3 | |||
| @@ -1,7 +1,24 @@ | |||
| 1 | .\" $OpenBSD: BN_num_bytes.3,v 1.8 2022/07/13 21:51:35 schwarze Exp $ | 1 | .\" $OpenBSD: BN_num_bytes.3,v 1.9 2022/11/22 18:55:04 schwarze Exp $ |
| 2 | .\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 | 2 | .\" full merge up to: OpenSSL 9e183d22 Mar 11 08:56:44 2017 -0500 |
| 3 | .\" | 3 | .\" |
| 4 | .\" This file was written by Ulf Moeller <ulf@openssl.org> | 4 | .\" This file is a derived work. |
| 5 | .\" The changes are covered by the following Copyright and license: | ||
| 6 | .\" | ||
| 7 | .\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org> | ||
| 8 | .\" | ||
| 9 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 10 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 11 | .\" copyright notice and this permission notice appear in all copies. | ||
| 12 | .\" | ||
| 13 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 14 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 15 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 16 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 17 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 18 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 19 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 20 | .\" | ||
| 21 | .\" The original file was written by Ulf Moeller <ulf@openssl.org> | ||
| 5 | .\" and Richard Levitte <levitte@openssl.org>. | 22 | .\" and Richard Levitte <levitte@openssl.org>. |
| 6 | .\" Copyright (c) 2000, 2004 The OpenSSL Project. All rights reserved. | 23 | .\" Copyright (c) 2000, 2004 The OpenSSL Project. All rights reserved. |
| 7 | .\" | 24 | .\" |
| @@ -49,71 +66,83 @@ | |||
| 49 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 66 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 50 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 67 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
| 51 | .\" | 68 | .\" |
| 52 | .Dd $Mdocdate: July 13 2022 $ | 69 | .Dd $Mdocdate: November 22 2022 $ |
| 53 | .Dt BN_NUM_BYTES 3 | 70 | .Dt BN_NUM_BYTES 3 |
| 54 | .Os | 71 | .Os |
| 55 | .Sh NAME | 72 | .Sh NAME |
| 56 | .Nm BN_num_bytes , | 73 | .Nm BN_num_bits_word , |
| 57 | .Nm BN_num_bits , | 74 | .Nm BN_num_bits , |
| 58 | .Nm BN_num_bits_word | 75 | .Nm BN_num_bytes |
| 59 | .Nd get BIGNUM size | 76 | .Nd get BIGNUM size |
| 60 | .Sh SYNOPSIS | 77 | .Sh SYNOPSIS |
| 61 | .In openssl/bn.h | 78 | .In openssl/bn.h |
| 62 | .Ft int | 79 | .Ft int |
| 63 | .Fo BN_num_bytes | 80 | .Fo BN_num_bits_word |
| 64 | .Fa "const BIGNUM *a" | 81 | .Fa "BN_ULONG w" |
| 65 | .Fc | 82 | .Fc |
| 66 | .Ft int | 83 | .Ft int |
| 67 | .Fo BN_num_bits | 84 | .Fo BN_num_bits |
| 68 | .Fa "const BIGNUM *a" | 85 | .Fa "const BIGNUM *a" |
| 69 | .Fc | 86 | .Fc |
| 70 | .Ft int | 87 | .Ft int |
| 71 | .Fo BN_num_bits_word | 88 | .Fo BN_num_bytes |
| 72 | .Fa "BN_ULONG w" | 89 | .Fa "const BIGNUM *a" |
| 73 | .Fc | 90 | .Fc |
| 74 | .Sh DESCRIPTION | 91 | .Sh DESCRIPTION |
| 75 | .Fn BN_num_bytes | ||
| 76 | returns the size of a | ||
| 77 | .Vt BIGNUM | ||
| 78 | in bytes. | ||
| 79 | .Pp | ||
| 80 | .Fn BN_num_bits_word | 92 | .Fn BN_num_bits_word |
| 81 | returns the number of significant bits in a word. | 93 | returns the number of significant bits in |
| 82 | As an example, 0x00000432 returns 11, not 16 or 32. | 94 | .Fa w , |
| 83 | Basically, except for a zero, it returns | 95 | that is, the minimum number of digits needed to write |
| 96 | .Fa w | ||
| 97 | as a binary number. | ||
| 98 | Except for an argument of 0, this is | ||
| 84 | .Pp | 99 | .Pp |
| 85 | .D1 floor(log2( Ns Fa w ) ) No + 1 . | 100 | .D1 floor(log2( Ns Fa w ) ) No + 1 . |
| 86 | .Pp | 101 | .Pp |
| 102 | .Vt BN_ULONG | ||
| 103 | is a macro that expands to | ||
| 104 | .Vt unsigned long Pq = Vt uint64_t | ||
| 105 | on | ||
| 106 | .Dv _LP64 | ||
| 107 | platforms and | ||
| 108 | .Vt unsigned int Pq = Vt uint32_t | ||
| 109 | elsewhere. | ||
| 110 | .Pp | ||
| 87 | .Fn BN_num_bits | 111 | .Fn BN_num_bits |
| 88 | returns the number of significant bits in a | 112 | returns the number of significant bits in the value of the |
| 89 | .Sy BIGNUM , | 113 | .Fa "BIGNUM *a" , |
| 90 | following the same principle as | 114 | following the same principle as |
| 91 | .Fn BN_num_bits_word . | 115 | .Fn BN_num_bits_word . |
| 92 | .Pp | 116 | .Pp |
| 93 | .Fn BN_num_bytes | 117 | .Fn BN_num_bytes |
| 94 | is a macro. | 118 | is a macro that returns the number of significant bytes in |
| 119 | .Fa a , | ||
| 120 | i.e. the minimum number of bytes needed to store the value of | ||
| 121 | .Fa a , | ||
| 122 | that is, | ||
| 123 | .Fn BN_num_bits a | ||
| 124 | divided by eight and rounded up to the next integer number. | ||
| 125 | .Sh RETURN VALUES | ||
| 126 | .Fn BN_num_bits_word | ||
| 127 | returns the number of significant bits in | ||
| 128 | .Fa w | ||
| 129 | or 0 if | ||
| 130 | .Fa w | ||
| 131 | is 0. | ||
| 132 | The maximum return value that can occur is | ||
| 133 | .Dv BN_BITS2 , | ||
| 134 | which is 64 on | ||
| 135 | .Dv _LP64 | ||
| 136 | platforms and 32 elsewhere. | ||
| 95 | .Pp | 137 | .Pp |
| 96 | Some have tried using | ||
| 97 | .Fn BN_num_bits | 138 | .Fn BN_num_bits |
| 98 | on individual numbers in RSA keys, DH keys and DSA keys, and found that | 139 | returns the number of significant bits and |
| 99 | they don't always come up with the number of bits they expected | ||
| 100 | (something like 512, 1024, 2048, ...). This is because generating a | ||
| 101 | number with some specific number of bits doesn't always set the highest | ||
| 102 | bits, thereby making the number of | ||
| 103 | .Em significant | ||
| 104 | bits a little lower. | ||
| 105 | If you want to know the "key size" of such a key, either use functions | ||
| 106 | like | ||
| 107 | .Xr RSA_size 3 , | ||
| 108 | .Xr DH_size 3 , | ||
| 109 | and | ||
| 110 | .Xr DSA_size 3 , | ||
| 111 | or use | ||
| 112 | .Fn BN_num_bytes | 140 | .Fn BN_num_bytes |
| 113 | and multiply with 8 (although there's no real guarantee that will match | 141 | the number of significant bytes in |
| 114 | the "key size", just a lot more probability). | 142 | .Fa a , |
| 115 | .Sh RETURN VALUES | 143 | or 0 if the value of |
| 116 | The size. | 144 | .Fa a |
| 145 | is 0. | ||
| 117 | .Sh SEE ALSO | 146 | .Sh SEE ALSO |
| 118 | .Xr BN_new 3 , | 147 | .Xr BN_new 3 , |
| 119 | .Xr BN_security_bits 3 , | 148 | .Xr BN_security_bits 3 , |
| @@ -129,3 +158,18 @@ first appeared in SSLeay 0.5.1. | |||
| 129 | first appeared in SSLeay 0.5.2. | 158 | first appeared in SSLeay 0.5.2. |
| 130 | These functions have been available since | 159 | These functions have been available since |
| 131 | .Ox 2.4 . | 160 | .Ox 2.4 . |
| 161 | .Sh CAVEATS | ||
| 162 | Some have tried using | ||
| 163 | .Fn BN_num_bits | ||
| 164 | on individual numbers in RSA keys, DH keys and DSA keys, and found that | ||
| 165 | they don't always come up with the number of bits they expected | ||
| 166 | (something like 512, 1024, 2048, ...). | ||
| 167 | This is because generating a number with some specific number of bits | ||
| 168 | doesn't always set the highest bits, thereby making the number of | ||
| 169 | .Em significant | ||
| 170 | bits a little smaller. | ||
| 171 | If you want to know the "key size" of such a key, use functions like | ||
| 172 | .Xr RSA_size 3 , | ||
| 173 | .Xr DH_size 3 , | ||
| 174 | and | ||
| 175 | .Xr DSA_size 3 . | ||
