/* * This function adds a byte into the entropy pool. It does not * update the entropy estimate. The caller must do this if appropriate. * * The pool is stirred with a primitive polynomial of degree 128 * over GF(2), namely x^128 + x^99 + x^59 + x^31 + x^9 + x^7 + 1. * For a pool of size 64, try x^64+x^62+x^38+x^10+x^6+x+1. * * We rotate the input word by a changing number of bits, to help * assure that all bits in the entropy get toggled. Otherwise, if we * consistently feed the entropy pool small numbers (like jiffies and * scancodes, for example), the upper bits of the entropy pool don't * get affected. --- TYT, 10/11/95 */ static void add_entropy_words(buf, n) const u_int32_t *buf; u_int n; { static const u_int32_t twist_table[8] = { 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158, 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; for (; n--; buf++) { register u_int32_t w = roll(*buf, random_state.input_rotate); register u_int i = random_state.add_ptr = (random_state.add_ptr - 1) & (POOLWORDS - 1); /* * Normally, we add 7 bits of rotation to the pool. * At the beginning of the pool, add an extra 7 bits * rotation, so that successive passes spread the * input bits across the pool evenly. */ random_state.input_rotate = (random_state.input_rotate + (i? 7 : 14)) & 31; /* XOR in the various taps */ w ^= random_state.pool[(i+TAP1) & (POOLWORDS-1)] ^ random_state.pool[(i+TAP2) & (POOLWORDS-1)] ^ random_state.pool[(i+TAP3) & (POOLWORDS-1)] ^ random_state.pool[(i+TAP4) & (POOLWORDS-1)] ^ random_state.pool[(i+TAP5) & (POOLWORDS-1)] ^ random_state.pool[i]; random_state.pool[i] = (w >> 3) ^ twist_table[w & 7]; } }