Lines Matching refs:lfsr
18 /* $Id: lfsr.c,v 1.20 2007/06/19 23:47:17 tbox Exp $ */
28 #include <isc/lfsr.h>
34 isc_lfsr_init(isc_lfsr_t *lfsr, isc_uint32_t state, unsigned int bits,
38 REQUIRE(VALID_LFSR(lfsr));
42 lfsr->state = state;
43 lfsr->bits = bits;
44 lfsr->tap = tap;
45 lfsr->count = count;
46 lfsr->reseed = reseed;
47 lfsr->arg = arg;
50 reseed(lfsr, arg);
51 if (lfsr->state == 0)
52 lfsr->state = 0xffffffffU >> (32 - lfsr->bits);
56 * Return the next state of the lfsr.
59 lfsr_generate(isc_lfsr_t *lfsr)
69 if (lfsr->state == 0) {
70 if (lfsr->reseed != NULL)
71 lfsr->reseed(lfsr, lfsr->arg);
72 if (lfsr->state == 0)
73 lfsr->state = 0xffffffffU >> (32 - lfsr->bits);
76 if (lfsr->state & 0x01) {
77 lfsr->state = (lfsr->state >> 1) ^ lfsr->tap;
80 lfsr->state >>= 1;
86 isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count)
92 REQUIRE(VALID_LFSR(lfsr));
102 *p |= lfsr_generate(lfsr);
105 *p |= lfsr_generate(lfsr);
109 if (lfsr->count != 0 && lfsr->reseed != NULL) {
110 if (lfsr->count <= count * 8)
111 lfsr->reseed(lfsr, lfsr->arg);
113 lfsr->count -= (count * 8);
118 lfsr_skipgenerate(isc_lfsr_t *lfsr, unsigned int skip)
121 (void)lfsr_generate(lfsr);
123 (void)lfsr_generate(lfsr);
125 return (lfsr->state);
129 * Skip "skip" states in "lfsr".
132 isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip)
134 REQUIRE(VALID_LFSR(lfsr));
137 (void)lfsr_generate(lfsr);