lfsr.c revision ad91a3d204891c4b039606f9b5ef557d9036f8c8
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <stdlib.h>
#include <isc/assertions.h>
isc_lfsr_t isc_lfsr_standard[] = {
/* 32-bit, x^31 + x^6 + x^4 + x^2 + x + 1 */
{ 0, 32, (1 << 31) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1) | 1 },
/* 32-bit, x^31 + x^6 + x^2 + x + 1 */
{ 0, 32, (1 << 31) | (1 << 6) | (1 << 2) | (1 << 1) | 1 },
/* 30-bit, x^29 + x^6 + x^3 + 1 */
{ 0, 30, (1 << 29) | (1 << 5) | (1 << 3) | 1 },
/* 19-bit, x^18 + x^4 + x + 1 */
{ 0, 19, (1 << 18) | (1 << 4) | (1 << 1) | 1 },
/* 13-bit, x^12 + x^3 + x^2 + 1 */
{ 0, 13, (1 << 12) | (1 << 3) | (1 << 2) | 1 },
{ 0, 0, 0}
};
#define VALID_LFSR(x) (x != NULL)
/*
* Return the next state of the lfsr.
*/
static inline isc_uint32_t
{
unsigned int nbits;
/*
* If the previous state is zero, we must fill it with something
* here, or we will begin to generate an extremely predictable output.
*/
else
}
{
return (lfsr_generate(lfsr));
}
static inline isc_uint32_t
{
while (skip--)
(void)lfsr_generate(lfsr);
return (lfsr_generate(lfsr));
}
/*
* Skip "skip" states in "lfsr" and return the ending state.
*/
{
}
/*
* Skip states in lfsr1 and lfsr2 using the other's current state.
* Return the final state of lfsr1 ^ lfsr2.
*
* Since this uses the _previous_ state of the lfsrs, the the actual values
* they contain should never be released to anyone other than by return from
* this function.
*
* "skipbits" indicates how many lower bits should be used to advance the
* lfsrs. A good value is 1. If simple combining is desired (without
* skipping any values) one can use 0.
*/
unsigned int skipbits)
{
if (skipbits == 0)
skipmask = 0;
else
/* cross-skip. */
}