Deleted Added
full compact
yarrow.c (103765) yarrow.c (107789)
1/*-
2 * Copyright (c) 2000 Mark R V Murray
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000 Mark R V Murray
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/random/yarrow.c 103765 2002-09-21 21:44:19Z markm $
26 * $FreeBSD: head/sys/dev/random/yarrow.c 107789 2002-12-12 17:38:45Z markm $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/kernel.h>
32#include <sys/lock.h>
33#include <sys/mutex.h>
34#include <sys/random.h>

--- 213 unchanged lines hidden (view full) ---

248
249/* Internal function to return processed entropy from the PRNG */
250int
251read_random_real(void *buf, int count)
252{
253 static int cur = 0;
254 static int gate = 1;
255 static u_char genval[KEYSIZE];
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/kernel.h>
32#include <sys/lock.h>
33#include <sys/mutex.h>
34#include <sys/random.h>

--- 213 unchanged lines hidden (view full) ---

248
249/* Internal function to return processed entropy from the PRNG */
250int
251read_random_real(void *buf, int count)
252{
253 static int cur = 0;
254 static int gate = 1;
255 static u_char genval[KEYSIZE];
256 size_t tomove;
256 int i;
257 int retval;
258
259 /* The reseed task must not be jumped on */
260 mtx_lock(&random_reseed_mtx);
261
262 if (gate) {
263 generator_gate();
264 random_state.outputblocks = 0;
265 gate = 0;
266 }
267 if (count > 0 && (size_t)count >= sizeof(random_state.counter)) {
268 retval = 0;
269 for (i = 0; i < count; i += (int)sizeof(random_state.counter)) {
270 random_state.counter[0]++;
271 yarrow_encrypt(&random_state.key, random_state.counter,
272 genval);
257 int i;
258 int retval;
259
260 /* The reseed task must not be jumped on */
261 mtx_lock(&random_reseed_mtx);
262
263 if (gate) {
264 generator_gate();
265 random_state.outputblocks = 0;
266 gate = 0;
267 }
268 if (count > 0 && (size_t)count >= sizeof(random_state.counter)) {
269 retval = 0;
270 for (i = 0; i < count; i += (int)sizeof(random_state.counter)) {
271 random_state.counter[0]++;
272 yarrow_encrypt(&random_state.key, random_state.counter,
273 genval);
273 memcpy((char *)buf + i, genval,
274 sizeof(random_state.counter));
274 tomove = min(count - i, sizeof(random_state.counter));
275 memcpy((char *)buf + i, genval, tomove);
275 if (++random_state.outputblocks >=
276 random_state.gengateinterval) {
277 generator_gate();
278 random_state.outputblocks = 0;
279 }
276 if (++random_state.outputblocks >=
277 random_state.gengateinterval) {
278 generator_gate();
279 random_state.outputblocks = 0;
280 }
280 retval += (int)sizeof(random_state.counter);
281 retval += (int)tomove;
281 }
282 }
283 else {
284 if (!cur) {
285 random_state.counter[0]++;
286 yarrow_encrypt(&random_state.key, random_state.counter,
287 genval);
288 memcpy(buf, genval, (size_t)count);

--- 50 unchanged lines hidden ---
282 }
283 }
284 else {
285 if (!cur) {
286 random_state.counter[0]++;
287 yarrow_encrypt(&random_state.key, random_state.counter,
288 genval);
289 memcpy(buf, genval, (size_t)count);

--- 50 unchanged lines hidden ---