Merge branch 'x86/rdrand'
[linux-2.6/x86.git] / include / linux / random.h
blobb44e6e3c580254ee6a53a715552eb006ae887ddb
1 /*
2 * include/linux/random.h
4 * Include file for the random number generator.
5 */
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] )
25 /*
26 * Write bytes into the entropy pool and add to the entropy count.
27 * (Superuser only.)
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 {
38 int entropy_count;
39 int buf_size;
40 __u32 buf[0];
43 struct rnd_state {
44 __u32 s1, s2, s3;
47 /* Exported functions */
49 #ifdef __KERNEL__
51 extern void rand_initialize_irq(int irq);
53 extern void add_input_randomness(unsigned int type, unsigned int code,
54 unsigned int value);
55 extern void add_interrupt_randomness(int irq);
57 extern void get_random_bytes(void *buf, int nbytes);
58 void generate_random_uuid(unsigned char uuid_out[16]);
60 extern __u32 secure_ip_id(__be32 daddr);
61 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
62 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
63 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
64 __be16 dport);
65 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
66 __be16 sport, __be16 dport);
67 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
68 __be16 sport, __be16 dport);
69 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
70 __be16 sport, __be16 dport);
72 #ifndef MODULE
73 extern const struct file_operations random_fops, urandom_fops;
74 #endif
76 unsigned int get_random_int(void);
77 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79 u32 random32(void);
80 void srandom32(u32 seed);
82 u32 prandom32(struct rnd_state *);
85 * Handle minimum values for seeds
87 static inline u32 __seed(u32 x, u32 m)
89 return (x < m) ? x + m : x;
92 /**
93 * prandom32_seed - set seed for prandom32().
94 * @state: pointer to state structure to receive the seed.
95 * @seed: arbitrary 64-bit value to use as a seed.
97 static inline void prandom32_seed(struct rnd_state *state, u64 seed)
99 u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
101 state->s1 = __seed(i, 1);
102 state->s2 = __seed(i, 7);
103 state->s3 = __seed(i, 15);
106 #ifdef CONFIG_ARCH_RANDOM
107 # include <asm/archrandom.h>
108 #else
109 static inline int arch_get_random_long(unsigned long *v)
111 return 0;
113 static inline int arch_get_random_int(unsigned int *v)
115 return 0;
117 #endif
119 #endif /* __KERNEL___ */
121 #endif /* _LINUX_RANDOM_H */