blob: 15cd75454468651db7fecf992d776e9af5d07fa9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/linux/random.h
3 *
4 * Include file for the random number generator.
5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#ifndef _LINUX_RANDOM_H
7#define _LINUX_RANDOM_H
8
Herbert Xu205a5252015-06-09 18:19:39 +08009#include <linux/list.h>
Daniel Borkmann897ece52015-10-08 01:20:38 +020010#include <linux/once.h>
11
David Howells607ca462012-10-13 10:46:48 +010012#include <uapi/linux/random.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Herbert Xu205a5252015-06-09 18:19:39 +080014struct random_ready_callback {
15 struct list_head list;
16 void (*func)(struct random_ready_callback *rdy);
17 struct module *owner;
18};
19
Linus Torvaldsa2080a62012-07-04 11:16:01 -040020extern void add_device_randomness(const void *, unsigned int);
Emese Revfy38addce2016-06-20 20:41:19 +020021
22#if defined(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) && !defined(__CHECKER__)
23static inline void add_latent_entropy(void)
24{
25 add_device_randomness((const void *)&latent_entropy,
26 sizeof(latent_entropy));
27}
28#else
29static inline void add_latent_entropy(void) {}
30#endif
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032extern void add_input_randomness(unsigned int type, unsigned int code,
Emese Revfy0766f782016-06-20 20:42:34 +020033 unsigned int value) __latent_entropy;
34extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36extern void get_random_bytes(void *buf, int nbytes);
Herbert Xu205a5252015-06-09 18:19:39 +080037extern int add_random_ready_callback(struct random_ready_callback *rdy);
38extern void del_random_ready_callback(struct random_ready_callback *rdy);
Theodore Ts'oc2557a32012-07-05 10:35:23 -040039extern void get_random_bytes_arch(void *buf, int nbytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#ifndef MODULE
Arjan van de Ven54047322007-02-12 00:55:28 -080042extern const struct file_operations random_fops, urandom_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#endif
44
45unsigned int get_random_int(void);
Daniel Cashmanec9ee4a2016-02-26 15:19:34 -080046unsigned long get_random_long(void);
Jason Cooper99fdafd2016-10-11 13:53:52 -070047unsigned long randomize_page(unsigned long start, unsigned long range);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Joe Eykholt59601642010-05-26 14:44:13 -070049/*
Linus Torvalds82461642020-07-31 07:51:14 +020050 * This is designed to be standalone for just prandom
51 * users, but for now we include it from <linux/random.h>
52 * for legacy reasons.
Joe Eykholt59601642010-05-26 14:44:13 -070053 */
Linus Torvalds82461642020-07-31 07:51:14 +020054#include <linux/prandom.h>
Joe Eykholt59601642010-05-26 14:44:13 -070055
H. Peter Anvin63d77172011-07-31 13:54:50 -070056#ifdef CONFIG_ARCH_RANDOM
57# include <asm/archrandom.h>
58#else
H. Peter Anvin117780e2016-06-08 12:38:38 -070059static inline bool arch_get_random_long(unsigned long *v)
H. Peter Anvin63d77172011-07-31 13:54:50 -070060{
61 return 0;
62}
H. Peter Anvin117780e2016-06-08 12:38:38 -070063static inline bool arch_get_random_int(unsigned int *v)
H. Peter Anvin63d77172011-07-31 13:54:50 -070064{
65 return 0;
66}
H. Peter Anvin117780e2016-06-08 12:38:38 -070067static inline bool arch_has_random(void)
H. Peter Anvin7b878d42014-03-17 16:36:30 -070068{
69 return 0;
70}
H. Peter Anvin117780e2016-06-08 12:38:38 -070071static inline bool arch_get_random_seed_long(unsigned long *v)
H. Peter Anvind20f78d2014-03-17 16:36:27 -070072{
73 return 0;
74}
H. Peter Anvin117780e2016-06-08 12:38:38 -070075static inline bool arch_get_random_seed_int(unsigned int *v)
H. Peter Anvind20f78d2014-03-17 16:36:27 -070076{
77 return 0;
78}
H. Peter Anvin117780e2016-06-08 12:38:38 -070079static inline bool arch_has_random_seed(void)
H. Peter Anvin7b878d42014-03-17 16:36:30 -070080{
81 return 0;
82}
H. Peter Anvin63d77172011-07-31 13:54:50 -070083#endif
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#endif /* _LINUX_RANDOM_H */