blob: dda1a2e1d85328a8b5a4c5921f181bc1d40decb1 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001
2#ifndef _LINUX_RANDOM_H
3#define _LINUX_RANDOM_H
4
5#include <linux/types.h>
6#include <linux/ioctl.h>
7#include <linux/irqnr.h>
8
9
10#define RNDGETENTCNT _IOR( 'R', 0x00, int )
11
12#define RNDADDTOENTCNT _IOW( 'R', 0x01, int )
13
14#define RNDGETPOOL _IOR( 'R', 0x02, int [2] )
15
16#define RNDADDENTROPY _IOW( 'R', 0x03, int [2] )
17
18#define RNDZAPENTCNT _IO( 'R', 0x04 )
19
20#define RNDCLEARPOOL _IO( 'R', 0x06 )
21
22struct rand_pool_info {
23 int entropy_count;
24 int buf_size;
25 __u32 buf[0];
26};
27
28struct rnd_state {
29 __u32 s1, s2, s3;
30};
31
32
33#ifdef __KERNEL__
34
35extern void add_device_randomness(const void *, unsigned int);
36extern void add_input_randomness(unsigned int type, unsigned int code,
37 unsigned int value);
38extern void add_interrupt_randomness(int irq, int irq_flags);
39
40extern void get_random_bytes(void *buf, int nbytes);
41extern void get_random_bytes_arch(void *buf, int nbytes);
42void generate_random_uuid(unsigned char uuid_out[16]);
43
44#ifndef MODULE
45extern const struct file_operations random_fops, urandom_fops;
46#endif
47
48unsigned int get_random_int(void);
49unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
50
51u32 random32(void);
52void srandom32(u32 seed);
53
54u32 prandom32(struct rnd_state *);
55
56static inline u32 __seed(u32 x, u32 m)
57{
58 return (x < m) ? x + m : x;
59}
60
61static inline void prandom32_seed(struct rnd_state *state, u64 seed)
62{
63 u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
64
65 state->s1 = __seed(i, 1);
66 state->s2 = __seed(i, 7);
67 state->s3 = __seed(i, 15);
68}
69
70#ifdef CONFIG_ARCH_RANDOM
71# include <asm/archrandom.h>
72#else
73static inline int arch_get_random_long(unsigned long *v)
74{
75 return 0;
76}
77static inline int arch_get_random_int(unsigned int *v)
78{
79 return 0;
80}
81#endif
82
83#endif
84
85#endif