| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: arc4random.3,v 1.20 2016/07/15 15:23:43 riastradh Exp $ | | 1 | .\" $NetBSD: arc4random.3,v 1.21 2016/07/15 21:19:19 wiz Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2014 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2014 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Taylor R. Campbell. | | 7 | .\" by Taylor R. Campbell. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -155,27 +155,27 @@ uniform distribution on all functions fr | | | @@ -155,27 +155,27 @@ uniform distribution on all functions fr |
155 | strings. | | 155 | strings. |
156 | .Pp | | 156 | .Pp |
157 | The PRNG state is a 32-byte ChaCha20 key | | 157 | The PRNG state is a 32-byte ChaCha20 key |
158 | .Fa s . | | 158 | .Fa s . |
159 | Each request to | | 159 | Each request to |
160 | an | | 160 | an |
161 | .Nm | | 161 | .Nm |
162 | function | | 162 | function |
163 | .Bl -bullet -offset abcd -compact | | 163 | .Bl -bullet -offset abcd -compact |
164 | .It | | 164 | .It |
165 | computes the 64-byte quantity | | 165 | computes the 64-byte quantity |
166 | .Fa x | | 166 | .Fa x |
167 | = | | 167 | = |
168 | .Pf ChaCha20_ Fa s Ns (0), | | 168 | .Pf ChaCha20_ Fa s Ns Pq 0 , |
169 | .It | | 169 | .It |
170 | splits | | 170 | splits |
171 | .Fa x | | 171 | .Fa x |
172 | into two 32-byte quantities | | 172 | into two 32-byte quantities |
173 | .Fa s' | | 173 | .Fa s' |
174 | and | | 174 | and |
175 | .Fa k , | | 175 | .Fa k , |
176 | .It | | 176 | .It |
177 | replaces | | 177 | replaces |
178 | .Fa s | | 178 | .Fa s |
179 | by | | 179 | by |
180 | .Fa s' , | | 180 | .Fa s' , |
181 | and | | 181 | and |
| @@ -186,29 +186,29 @@ as output. | | | @@ -186,29 +186,29 @@ as output. |
186 | .El | | 186 | .El |
187 | .Pp | | 187 | .Pp |
188 | .Fn arc4random | | 188 | .Fn arc4random |
189 | yields the first four bytes of | | 189 | yields the first four bytes of |
190 | .Fa k | | 190 | .Fa k |
191 | as output directly. | | 191 | as output directly. |
192 | .Fn arc4random_buf | | 192 | .Fn arc4random_buf |
193 | either yields up to 32 bytes of | | 193 | either yields up to 32 bytes of |
194 | .Fa k | | 194 | .Fa k |
195 | as output directly, or, for longer | | 195 | as output directly, or, for longer |
196 | requests, uses | | 196 | requests, uses |
197 | .Fa k | | 197 | .Fa k |
198 | as a ChaCha20 key and yields the concatenation | | 198 | as a ChaCha20 key and yields the concatenation |
199 | .Pf ChaCha20_ Fa k Ns (0) | | 199 | .Pf ChaCha20_ Fa k Ns Pq 0 |
200 | || | | 200 | || |
201 | .Pf ChaCha20_ Fa k Ns (1) | | 201 | .Pf ChaCha20_ Fa k Ns Pq 1 |
202 | || ... as output. | | 202 | || ... as output. |
203 | .Fn arc4random_uniform | | 203 | .Fn arc4random_uniform |
204 | repeats | | 204 | repeats |
205 | .Fn arc4random | | 205 | .Fn arc4random |
206 | until it obtains an integer in [2^32 % | | 206 | until it obtains an integer in [2^32 % |
207 | .Fa bound , | | 207 | .Fa bound , |
208 | 2^32), and reduces that modulo | | 208 | 2^32), and reduces that modulo |
209 | .Fa bound . | | 209 | .Fa bound . |
210 | .Pp | | 210 | .Pp |
211 | The PRNG state is per-thread, unless memory allocation fails inside the | | 211 | The PRNG state is per-thread, unless memory allocation fails inside the |
212 | library, in which case some threads may share global PRNG state with a | | 212 | library, in which case some threads may share global PRNG state with a |
213 | mutex. | | 213 | mutex. |
214 | The global PRNG state is zeroed on fork in the parent via | | 214 | The global PRNG state is zeroed on fork in the parent via |