/* * random32 - pseudo random number generator * * A 32 bit pseudo-random number is generated using a fast * algorithm suitable for simulation. This algorithm is NOT * considered safe for cryptographic use. */ u32 random32(void) { unsigned long r; struct rnd_state *state = &get_cpu_var(net_rand_state); r = __random32(state); put_cpu_var(state); /* dacashman change */ printk(KERN_DEBUG "RANDOM - random32 called. Value: %x\t%x\t%x\n", state->s1, state->s2, state->s3); return r; }
/* * Generate some initially weak seeding values to allow * to start the random32() engine. */ static int __init random32_init(void) { /* dacashman change */ struct rnd_state *state_cpy; int i; for_each_possible_cpu(i) { struct rnd_state *state = &per_cpu(net_rand_state,i); #define LCG(x) ((x) * 69069) /* super-duper LCG */ state->s1 = __seed(LCG(i + jiffies), 1); state->s2 = __seed(LCG(state->s1), 7); state->s3 = __seed(LCG(state->s2), 15); /* "warm it up" */ __random32(state); __random32(state); __random32(state); __random32(state); __random32(state); __random32(state); /* dacashman change */ state_cpy = state; } /* dacashman change */ printk(KERN_DEBUG "RANDOM - random32 init called. Value: %x\t%x\t%x\n", state_cpy->s1, state_cpy->s2, state_cpy->s3); return 0; }
/* * Generate better values after random number generator * is fully initalized. */ static int __init random32_reseed(void) { int i; for_each_possible_cpu(i) { struct rnd_state *state = &per_cpu(net_rand_state,i); u32 seeds[3]; get_random_bytes(&seeds, sizeof(seeds)); state->s1 = __seed(seeds[0], 1); state->s2 = __seed(seeds[1], 7); state->s3 = __seed(seeds[2], 15); /* mix it in */ __random32(state); /* dacashman change */ printk(KERN_DEBUG "RANDOM - random32_reseed called. Value: %x\t%x\t%x\n", state->s1, state->s2, state->s3); state_change_num = 0; } return 0; }
static void __set_random32(struct rnd_state *state, unsigned long s) { if (s == 0) s = 1; /* default seed is 1 */ #define LCG(n) (69069 * n) state->s1 = LCG(s); state->s2 = LCG(state->s1); state->s3 = LCG(state->s2); /* "warm it up" */ __random32(state); __random32(state); __random32(state); __random32(state); __random32(state); __random32(state); }
/** * random32 - pseudo random number generator * * A 32 bit pseudo-random number is generated using a fast * algorithm suitable for simulation. This algorithm is NOT * considered safe for cryptographic use. */ u32 random32(void) { return __random32(&net_rand_state[smp_processor_id()]); }