lfsr_test.c revision 15a44745412679c30a6d022733925af70a38b715
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999, 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence *
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence */
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence/* $Id: lfsr_test.c,v 1.8 2000/07/27 09:38:04 tale Exp $ */
58aaab3687aac838542ee4ef65a9c094a5d34ab0Michael Graff
bd3195dcec5bd8a5603e1050bf27f8d7c19fe926David Lawrence#include <config.h>
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence#include <stdio.h>
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence#include <isc/lfsr.h>
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence#include <isc/util.h>
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrewsisc_uint32_t state[1024 * 64];
bdec0dc85e6d9ff554cf0a4dd977c32692234f9eDavid Lawrence
int
main(int argc, char **argv) {
isc_lfsr_t lfsr1, lfsr2;
int i;
isc_uint32_t temp;
UNUSED(argc);
UNUSED(argv);
/*
* Verify that returned values are reproducable.
*/
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr1, &state[i], 4);
printf("lfsr1: state[%2d] = %08x\n", i, state[i]);
}
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr1, &temp, 4);
if (state[i] != temp)
printf("lfsr1: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
/*
* Now do the same with skipping.
*/
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr1, &state[i], 4);
isc_lfsr_skip(&lfsr1, 32);
printf("lfsr1: state[%2d] = %08x\n", i, state[i]);
}
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr1, &temp, 4);
isc_lfsr_skip(&lfsr1, 32);
if (state[i] != temp)
printf("lfsr1: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
/*
* Try to find the period of the LFSR.
*
* x^16 + x^5 + x^3 + x^2 + 1
*/
isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr2, &state[i], 4);
printf("lfsr2: state[%2d] = %08x\n", i, state[i]);
}
isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL);
for (i = 0 ; i < 32 ; i++) {
isc_lfsr_generate(&lfsr2, &temp, 4);
if (state[i] != temp)
printf("lfsr2: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
return (0);
}