1999-12-15 01:50:25 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-12-15 01:50:25 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-05-08 14:38:29 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <stdio.h>
|
1999-12-15 01:50:25 +00:00
|
|
|
|
|
|
|
#include <isc/lfsr.h>
|
2015-05-23 14:21:51 +02:00
|
|
|
#include <isc/print.h>
|
1999-12-16 22:47:38 +00:00
|
|
|
#include <isc/util.h>
|
1999-12-15 01:50:25 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t state[1024 * 64];
|
1999-12-15 01:50:25 +00:00
|
|
|
|
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
1999-12-15 01:50:25 +00:00
|
|
|
isc_lfsr_t lfsr1, lfsr2;
|
2020-02-12 13:59:18 +01:00
|
|
|
int i;
|
|
|
|
uint32_t temp;
|
1999-12-15 01:50:25 +00:00
|
|
|
|
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that returned values are reproducable.
|
|
|
|
*/
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_generate(&lfsr1, &state[i], 4);
|
1999-12-15 01:50:25 +00:00
|
|
|
printf("lfsr1: state[%2d] = %08x\n", i, state[i]);
|
|
|
|
}
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_generate(&lfsr1, &temp, 4);
|
1999-12-15 01:50:25 +00:00
|
|
|
if (state[i] != temp)
|
2000-05-08 14:38:29 +00:00
|
|
|
printf("lfsr1: state[%2d] = %08x, "
|
|
|
|
"but new state is %08x\n",
|
1999-12-15 01:50:25 +00:00
|
|
|
i, state[i], temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now do the same with skipping.
|
|
|
|
*/
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_generate(&lfsr1, &state[i], 4);
|
|
|
|
isc_lfsr_skip(&lfsr1, 32);
|
1999-12-15 01:50:25 +00:00
|
|
|
printf("lfsr1: state[%2d] = %08x\n", i, state[i]);
|
|
|
|
}
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_generate(&lfsr1, &temp, 4);
|
|
|
|
isc_lfsr_skip(&lfsr1, 32);
|
1999-12-15 01:50:25 +00:00
|
|
|
if (state[i] != temp)
|
2000-05-08 14:38:29 +00:00
|
|
|
printf("lfsr1: state[%2d] = %08x, "
|
|
|
|
"but new state is %08x\n",
|
1999-12-15 01:50:25 +00:00
|
|
|
i, state[i], temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find the period of the LFSR.
|
1999-12-16 00:07:21 +00:00
|
|
|
*
|
|
|
|
* x^16 + x^5 + x^3 + x^2 + 1
|
1999-12-15 01:50:25 +00:00
|
|
|
*/
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
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);
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
1999-12-16 00:07:21 +00:00
|
|
|
isc_lfsr_generate(&lfsr2, &temp, 4);
|
|
|
|
if (state[i] != temp)
|
2000-05-08 14:38:29 +00:00
|
|
|
printf("lfsr2: state[%2d] = %08x, "
|
|
|
|
"but new state is %08x\n",
|
1999-12-16 00:07:21 +00:00
|
|
|
i, state[i], temp);
|
1999-12-15 01:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|