random.c (43759d4f429c8d55fd56f863542e20f4e6e8f589) random.c (c84dbf61a7b322188d2a7fddc0cc6317ac6713e2)
1/*
2 * random.c -- A strong random number generator
3 *
4 * Copyright Matt Mackall <mpm@selenic.com>, 2003, 2004, 2005
5 *
6 * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All
7 * rights reserved.
8 *

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

245#include <linux/random.h>
246#include <linux/poll.h>
247#include <linux/init.h>
248#include <linux/fs.h>
249#include <linux/genhd.h>
250#include <linux/interrupt.h>
251#include <linux/mm.h>
252#include <linux/spinlock.h>
1/*
2 * random.c -- A strong random number generator
3 *
4 * Copyright Matt Mackall <mpm@selenic.com>, 2003, 2004, 2005
5 *
6 * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All
7 * rights reserved.
8 *

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

245#include <linux/random.h>
246#include <linux/poll.h>
247#include <linux/init.h>
248#include <linux/fs.h>
249#include <linux/genhd.h>
250#include <linux/interrupt.h>
251#include <linux/mm.h>
252#include <linux/spinlock.h>
253#include <linux/kthread.h>
253#include <linux/percpu.h>
254#include <linux/cryptohash.h>
255#include <linux/fips.h>
256#include <linux/ptrace.h>
257#include <linux/kmemcheck.h>
258#include <linux/workqueue.h>
259#include <linux/irq.h>
260

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

1745randomize_range(unsigned long start, unsigned long end, unsigned long len)
1746{
1747 unsigned long range = end - len - start;
1748
1749 if (end <= start + len)
1750 return 0;
1751 return PAGE_ALIGN(get_random_int() % range + start);
1752}
254#include <linux/percpu.h>
255#include <linux/cryptohash.h>
256#include <linux/fips.h>
257#include <linux/ptrace.h>
258#include <linux/kmemcheck.h>
259#include <linux/workqueue.h>
260#include <linux/irq.h>
261

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

1746randomize_range(unsigned long start, unsigned long end, unsigned long len)
1747{
1748 unsigned long range = end - len - start;
1749
1750 if (end <= start + len)
1751 return 0;
1752 return PAGE_ALIGN(get_random_int() % range + start);
1753}
1754
1755/* Interface for in-kernel drivers of true hardware RNGs.
1756 * Those devices may produce endless random bits and will be throttled
1757 * when our pool is full.
1758 */
1759void add_hwgenerator_randomness(const char *buffer, size_t count,
1760 size_t entropy)
1761{
1762 struct entropy_store *poolp = &input_pool;
1763
1764 /* Suspend writing if we're above the trickle threshold.
1765 * We'll be woken up again once below random_write_wakeup_thresh,
1766 * or when the calling thread is about to terminate.
1767 */
1768 wait_event_interruptible(random_write_wait, kthread_should_stop() ||
1769 ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits);
1770 mix_pool_bytes(poolp, buffer, count);
1771 credit_entropy_bits(poolp, entropy);
1772}
1773EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);