* it's cheap to do so and helps slightly in the expected case where
* the entropy is concentrated in the low-order bits.
*/
-static void __add_entropy_words(struct entropy_store *r, const __u32 *in,
- int nwords, __u32 out[16])
+static void add_entropy_words(struct entropy_store *r, const __u32 *in,
+ int nwords)
{
static __u32 const twist_table[8] = {
0, 0x3b6e20c8, 0x76dc4190, 0x4db26158,
r->input_rotate = input_rotate;
r->add_ptr = add_ptr;
- if (out) {
- for (i = 0; i < 16; i++) {
- out[i] = r->pool[add_ptr];
- add_ptr = (add_ptr - 1) & wordmask;
- }
- }
-
spin_unlock_irqrestore(&r->lock, flags);
}
-static inline void add_entropy_words(struct entropy_store *r, const __u32 *in,
- int nwords)
-{
- __add_entropy_words(r, in, nwords, NULL);
-}
-
-
/*
* Credit (or debit) the entropy store with n bits of entropy
*/
* hashing calculations during an interrupt in add_timer_randomness().
* Instead, the entropy is only added to the pool by keventd.
*/
-static void batch_entropy_store(u32 a, u32 b, int num)
+void batch_entropy_store(u32 a, u32 b, int num)
{
int new;
unsigned long flags;
spin_unlock_irqrestore(&batch_lock, flags);
}
+EXPORT_SYMBOL(batch_entropy_store);
+
/*
* Flush out the accumulated entropy operations, adding entropy to the passed
* store (normally random_state). If that store has enough entropy, alternate
* jiffies.
*/
time = get_cycles();
- if (time)
- num ^= (u32)((time >> 31) >> 1);
- else
+ if (time != 0) {
+ if (sizeof(time) > 4)
+ num ^= (u32)(time >> 32);
+ } else {
time = jiffies;
+ }
/*
* Calculate number of bits of randomness we probably added.
}
}
+EXPORT_SYMBOL(add_keyboard_randomness);
+
void add_mouse_randomness(__u32 mouse_data)
{
add_timer_randomness(&mouse_timer_state, mouse_data);
add_timer_randomness(irq_timer_state[irq], 0x100+irq);
}
+EXPORT_SYMBOL(add_interrupt_randomness);
+
void add_disk_randomness(struct gendisk *disk)
{
if (!disk || !disk->random)
size_t nbytes, int flags)
{
ssize_t ret, i;
- __u32 tmp[TMP_BUF_SIZE], data[16];
+ __u32 tmp[TMP_BUF_SIZE];
__u32 x;
unsigned long cpuflags;
HASH_TRANSFORM(tmp, r->pool+i);
add_entropy_words(r, &tmp[x%HASH_BUFFER_SIZE], 1);
}
-
- /*
- * To avoid duplicates, we atomically extract a
- * portion of the pool while mixing, and hash one
- * final time.
- */
- __add_entropy_words(r, &tmp[x%HASH_BUFFER_SIZE], 1, data);
- HASH_TRANSFORM(tmp, data);
-
+
/*
* In case the hash function has some recognizable
* output pattern, we fold it in half.
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen, void **context)
{
- unsigned int len;
+ int len;
sysctl_poolsize = random_state->poolinfo.POOLBYTES;
*
********************************************************************/
-#ifdef CONFIG_INET
/*
* TCP initial sequence number picking. This uses the random number
* generator to pick an initial secret value. This value is hashed
return (cookie - tmp[17]) & COOKIEMASK; /* Leaving the data behind */
}
#endif
-#endif /* CONFIG_INET */
/*
* Get a random word:
return 0;
return PAGE_ALIGN(get_random_int() % range + start);
}
-