random.c (434537ae54ad37e93555de21b6ac8133d6d773a9) random.c (7b5164fb1279bf0251371848e40bae646b59b3a8)
1/*
2 * random.c -- A strong random number generator
3 *
4 * Copyright (C) 2017-2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
5 *
6 * Copyright Matt Mackall <mpm@selenic.com>, 2003, 2004, 2005
7 *
8 * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All

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

1331 if (input_pool.entropy_count < POOL_MIN_BITS)
1332 mask |= EPOLLOUT | EPOLLWRNORM;
1333 return mask;
1334}
1335
1336static int write_pool(const char __user *ubuf, size_t count)
1337{
1338 size_t len;
1/*
2 * random.c -- A strong random number generator
3 *
4 * Copyright (C) 2017-2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
5 *
6 * Copyright Matt Mackall <mpm@selenic.com>, 2003, 2004, 2005
7 *
8 * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All

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

1331 if (input_pool.entropy_count < POOL_MIN_BITS)
1332 mask |= EPOLLOUT | EPOLLWRNORM;
1333 return mask;
1334}
1335
1336static int write_pool(const char __user *ubuf, size_t count)
1337{
1338 size_t len;
1339 int ret = 0;
1339 u8 block[BLAKE2S_BLOCK_SIZE];
1340
1341 while (count) {
1342 len = min(count, sizeof(block));
1340 u8 block[BLAKE2S_BLOCK_SIZE];
1341
1342 while (count) {
1343 len = min(count, sizeof(block));
1343 if (copy_from_user(block, ubuf, len))
1344 return -EFAULT;
1344 if (copy_from_user(block, ubuf, len)) {
1345 ret = -EFAULT;
1346 goto out;
1347 }
1345 count -= len;
1346 ubuf += len;
1347 mix_pool_bytes(block, len);
1348 cond_resched();
1349 }
1350
1348 count -= len;
1349 ubuf += len;
1350 mix_pool_bytes(block, len);
1351 cond_resched();
1352 }
1353
1351 return 0;
1354out:
1355 memzero_explicit(block, sizeof(block));
1356 return ret;
1352}
1353
1354static ssize_t random_write(struct file *file, const char __user *buffer,
1355 size_t count, loff_t *ppos)
1356{
1357 int ret;
1358
1359 ret = write_pool(buffer, count);

--- 419 unchanged lines hidden ---
1357}
1358
1359static ssize_t random_write(struct file *file, const char __user *buffer,
1360 size_t count, loff_t *ppos)
1361{
1362 int ret;
1363
1364 ret = write_pool(buffer, count);

--- 419 unchanged lines hidden ---