| Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | |
| 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 | |
| 22 | struct rand_pool_info { |
| 23 | int entropy_count; |
| 24 | int buf_size; |
| 25 | __u32 buf[0]; |
| 26 | }; |
| 27 | |
| 28 | struct rnd_state { |
| 29 | __u32 s1, s2, s3; |
| 30 | }; |
| 31 | |
| 32 | |
| 33 | #ifdef __KERNEL__ |
| 34 | |
| 35 | extern void add_device_randomness(const void *, unsigned int); |
| 36 | extern void add_input_randomness(unsigned int type, unsigned int code, |
| 37 | unsigned int value); |
| 38 | extern void add_interrupt_randomness(int irq, int irq_flags); |
| 39 | |
| 40 | extern void get_random_bytes(void *buf, int nbytes); |
| 41 | extern void get_random_bytes_arch(void *buf, int nbytes); |
| 42 | void generate_random_uuid(unsigned char uuid_out[16]); |
| 43 | |
| 44 | #ifndef MODULE |
| 45 | extern const struct file_operations random_fops, urandom_fops; |
| 46 | #endif |
| 47 | |
| 48 | unsigned int get_random_int(void); |
| 49 | unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len); |
| 50 | |
| 51 | u32 random32(void); |
| 52 | void srandom32(u32 seed); |
| 53 | |
| 54 | u32 prandom32(struct rnd_state *); |
| 55 | |
| 56 | static inline u32 __seed(u32 x, u32 m) |
| 57 | { |
| 58 | return (x < m) ? x + m : x; |
| 59 | } |
| 60 | |
| 61 | static 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 |
| 73 | static inline int arch_get_random_long(unsigned long *v) |
| 74 | { |
| 75 | return 0; |
| 76 | } |
| 77 | static inline int arch_get_random_int(unsigned int *v) |
| 78 | { |
| 79 | return 0; |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | #endif |
| 84 | |
| 85 | #endif |