2 * include/linux/random.h
4 * Include file for the random number generator.
7 #ifndef _LINUX_RANDOM_H
8 #define _LINUX_RANDOM_H
10 #include <linux/types.h>
11 #include <linux/ioctl.h>
12 #include <linux/irqnr.h>
14 /* ioctl()'s for the random number generator */
16 /* Get the entropy count. */
17 #define RNDGETENTCNT _IOR( 'R', 0x00, int )
19 /* Add to (or subtract from) the entropy count. (Superuser only.) */
20 #define RNDADDTOENTCNT _IOW( 'R', 0x01, int )
22 /* Get the contents of the entropy pool. (Superuser only.) */
23 #define RNDGETPOOL _IOR( 'R', 0x02, int [2] )
26 * Write bytes into the entropy pool and add to the entropy count.
29 #define RNDADDENTROPY _IOW( 'R', 0x03, int [2] )
31 /* Clear entropy count to 0. (Superuser only.) */
32 #define RNDZAPENTCNT _IO( 'R', 0x04 )
34 /* Clear the entropy pool and associated counters. (Superuser only.) */
35 #define RNDCLEARPOOL _IO( 'R', 0x06 )
37 struct rand_pool_info {
47 /* Exported functions */
51 extern void rand_initialize_irq(int irq);
53 extern void add_device_randomness(const void *, unsigned int);
54 extern void add_input_randomness(unsigned int type, unsigned int code,
56 extern void add_interrupt_randomness(int irq, int irq_flags);
58 extern void get_random_bytes(void *buf, int nbytes);
59 extern void get_random_bytes_arch(void *buf, int nbytes);
60 void generate_random_uuid(unsigned char uuid_out[16]);
61 extern int random_int_secret_init(void);
64 extern const struct file_operations random_fops, urandom_fops;
67 unsigned int get_random_int(void);
68 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
71 void srandom32(u32 seed);
73 u32 prandom32(struct rnd_state *);
76 * Handle minimum values for seeds
78 static inline u32 __seed(u32 x, u32 m)
80 return (x < m) ? x + m : x;
84 * prandom32_seed - set seed for prandom32().
85 * @state: pointer to state structure to receive the seed.
86 * @seed: arbitrary 64-bit value to use as a seed.
88 static inline void prandom32_seed(struct rnd_state *state, u64 seed)
90 u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
92 state->s1 = __seed(i, 2);
93 state->s2 = __seed(i, 8);
94 state->s3 = __seed(i, 16);
97 #ifdef CONFIG_ARCH_RANDOM
98 # include <asm/archrandom.h>
100 static inline int arch_get_random_long(unsigned long *v)
104 static inline int arch_get_random_int(unsigned int *v)
110 #endif /* __KERNEL___ */
112 #endif /* _LINUX_RANDOM_H */