From bdca09aa8da85c6ddd0bc61df42a7b74cef78128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 23 Apr 2020 12:16:22 +0200 Subject: [PATCH] Remove unused isc_lfsr API The isc_lfsr API was used to generate message IDs in the past. Currently, it's just cruft. --- lib/isc/Makefile.am | 2 - lib/isc/include/isc/lfsr.h | 122 ------------------- lib/isc/lfsr.c | 151 ------------------------ lib/isc/win32/libisc.def.in | 4 - lib/isc/win32/libisc.vcxproj.filters.in | 6 - lib/isc/win32/libisc.vcxproj.in | 2 - util/copyrights | 2 - 7 files changed, 289 deletions(-) delete mode 100644 lib/isc/include/isc/lfsr.h delete mode 100644 lib/isc/lfsr.c diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index cb6d6b7d77..83dd5acf2d 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -41,7 +41,6 @@ libisc_la_HEADERS = \ include/isc/iterated_hash.h \ include/isc/lang.h \ include/isc/lex.h \ - include/isc/lfsr.h \ include/isc/lib.h \ include/isc/likely.h \ include/isc/list.h \ @@ -173,7 +172,6 @@ libisc_la_SOURCES = \ httpd.c \ iterated_hash.c \ lex.c \ - lfsr.c \ lib.c \ log.c \ md.c \ diff --git a/lib/isc/include/isc/lfsr.h b/lib/isc/include/isc/lfsr.h deleted file mode 100644 index 5e3947aa81..0000000000 --- a/lib/isc/include/isc/lfsr.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * 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/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#ifndef ISC_LFSR_H -#define ISC_LFSR_H 1 - -/*! \file isc/lfsr.h */ - -#include - -#include -#include - -typedef struct isc_lfsr isc_lfsr_t; - -/*% - * This function is called when reseeding is needed. It is allowed to - * modify any state in the LFSR in any way it sees fit OTHER THAN "bits". - * - * It MUST set "count" to a new value or the lfsr will never reseed again. - * - * Also, a reseed will never occur in the middle of an extraction. This - * is purely an optimization, and is probably what one would want. - */ -typedef void (*isc_lfsrreseed_t)(isc_lfsr_t *, void *); - -/*% - * The members of this structure can be used by the application, but care - * needs to be taken to not change state once the lfsr is in operation. - */ -struct isc_lfsr { - uint32_t state; /*%< previous state */ - unsigned int bits; /*%< length */ - uint32_t tap; /*%< bit taps */ - unsigned int count; /*%< reseed count (in BITS!) */ - isc_lfsrreseed_t reseed; /*%< reseed function */ - void * arg; /*%< reseed function argument */ -}; - -ISC_LANG_BEGINDECLS - -void -isc_lfsr_init(isc_lfsr_t *lfsr, uint32_t state, unsigned int bits, uint32_t tap, - unsigned int count, isc_lfsrreseed_t reseed, void *arg); -/*%< - * Initialize an LFSR. - * - * Note: - * - *\li Putting untrusted values into this function will cause the LFSR to - * generate (perhaps) non-maximal length sequences. - * - * Requires: - * - *\li lfsr != NULL - * - *\li 8 <= bits <= 32 - * - *\li tap != 0 - */ - -void -isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count); -/*%< - * Returns "count" bytes of data from the LFSR. - * - * Requires: - * - *\li lfsr be valid. - * - *\li data != NULL. - * - *\li count > 0. - */ - -void -isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip); -/*%< - * Skip "skip" states. - * - * Requires: - * - *\li lfsr be valid. - */ - -uint32_t -isc_lfsr_generate32(isc_lfsr_t *lfsr1, isc_lfsr_t *lfsr2); -/*%< - * Given two LFSRs, use the current state from each to skip entries in the - * other. The next states are then xor'd together and returned. - * - * WARNING: - * - *\li This function is used only for very, very low security data, such - * as DNS message IDs where it is desired to have an unpredictable - * stream of bytes that are harder to predict than a simple flooding - * attack. - * - * Notes: - * - *\li Since the current state from each of the LFSRs is used to skip - * state in the other, it is important that no state be leaked - * from either LFSR. - * - * Requires: - * - *\li lfsr1 and lfsr2 be valid. - * - *\li 1 <= skipbits <= 31 - */ - -ISC_LANG_ENDDECLS - -#endif /* ISC_LFSR_H */ diff --git a/lib/isc/lfsr.c b/lib/isc/lfsr.c deleted file mode 100644 index 169b215e09..0000000000 --- a/lib/isc/lfsr.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * 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/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -/*! \file */ - -#include -#include -#include - -#include -#include -#include - -#define VALID_LFSR(x) (x != NULL) - -void -isc_lfsr_init(isc_lfsr_t *lfsr, uint32_t state, unsigned int bits, uint32_t tap, - unsigned int count, isc_lfsrreseed_t reseed, void *arg) { - REQUIRE(VALID_LFSR(lfsr)); - REQUIRE(8 <= bits && bits <= 32); - REQUIRE(tap != 0); - - lfsr->state = state; - lfsr->bits = bits; - lfsr->tap = tap; - lfsr->count = count; - lfsr->reseed = reseed; - lfsr->arg = arg; - - if (count == 0 && reseed != NULL) { - reseed(lfsr, arg); - } - if (lfsr->state == 0) { - lfsr->state = 0xffffffffU >> (32 - lfsr->bits); - } -} - -/*! - * Return the next state of the lfsr. - */ -static inline uint32_t -lfsr_generate(isc_lfsr_t *lfsr) { - /* - * If the previous state is zero, we must fill it with something - * here, or we will begin to generate an extremely predictable output. - * - * First, give the reseed function a crack at it. If the state is - * still 0, set it to all ones. - */ - if (lfsr->state == 0) { - if (lfsr->reseed != NULL) { - lfsr->reseed(lfsr, lfsr->arg); - } - if (lfsr->state == 0) { - lfsr->state = 0xffffffffU >> (32 - lfsr->bits); - } - } - - if (lfsr->state & 0x01) { - lfsr->state = (lfsr->state >> 1) ^ lfsr->tap; - return (1); - } else { - lfsr->state >>= 1; - return (0); - } -} - -void -isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count) { - unsigned char *p; - unsigned int bit; - unsigned int byte; - - REQUIRE(VALID_LFSR(lfsr)); - REQUIRE(data != NULL); - REQUIRE(count > 0); - - p = data; - byte = count; - - while (byte--) { - *p = 0; - for (bit = 0; bit < 7; bit++) { - *p |= lfsr_generate(lfsr); - *p <<= 1; - } - *p |= lfsr_generate(lfsr); - p++; - } - - if (lfsr->count != 0 && lfsr->reseed != NULL) { - if (lfsr->count <= count * 8) { - lfsr->reseed(lfsr, lfsr->arg); - } else { - lfsr->count -= (count * 8); - } - } -} - -static inline uint32_t -lfsr_skipgenerate(isc_lfsr_t *lfsr, unsigned int skip) { - while (skip--) { - (void)lfsr_generate(lfsr); - } - - (void)lfsr_generate(lfsr); - - return (lfsr->state); -} - -/* - * Skip "skip" states in "lfsr". - */ -void -isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip) { - REQUIRE(VALID_LFSR(lfsr)); - - while (skip--) { - (void)lfsr_generate(lfsr); - } -} - -/* - * Skip states in lfsr1 and lfsr2 using the other's current state. - * Return the final state of lfsr1 ^ lfsr2. - */ -uint32_t -isc_lfsr_generate32(isc_lfsr_t *lfsr1, isc_lfsr_t *lfsr2) { - uint32_t state1, state2; - uint32_t skip1, skip2; - - REQUIRE(VALID_LFSR(lfsr1)); - REQUIRE(VALID_LFSR(lfsr2)); - - skip1 = lfsr1->state & 0x01; - skip2 = lfsr2->state & 0x01; - - /* cross-skip. */ - state1 = lfsr_skipgenerate(lfsr1, skip2); - state2 = lfsr_skipgenerate(lfsr2, skip1); - - return (state1 ^ state2); -} diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 7cd09bc70f..aecf800244 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -328,10 +328,6 @@ isc_lex_setsourceline isc_lex_setsourcename isc_lex_setspecials isc_lex_ungettoken -isc_lfsr_generate -isc_lfsr_generate32 -isc_lfsr_init -isc_lfsr_skip isc_lib_register isc_log_categorybyname isc_log_closefilelogs diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in index 249e5271e3..f4e1964f06 100644 --- a/lib/isc/win32/libisc.vcxproj.filters.in +++ b/lib/isc/win32/libisc.vcxproj.filters.in @@ -131,9 +131,6 @@ Library Header Files - - Library Header Files - Library Header Files @@ -515,9 +512,6 @@ Library Source Files - - Library Source Files - Library Source Files diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index aafc24a276..b4574460b7 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -326,7 +326,6 @@ copy InstallFiles ..\Build\Release\ - @@ -434,7 +433,6 @@ copy InstallFiles ..\Build\Release\ - diff --git a/util/copyrights b/util/copyrights index 0f8982b09e..4557ac8b40 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1955,7 +1955,6 @@ ./lib/isc/include/isc/iterated_hash.h C 2008,2014,2016,2018,2019,2020 ./lib/isc/include/isc/lang.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020 ./lib/isc/include/isc/lex.h C 1998,1999,2000,2001,2002,2004,2005,2007,2008,2015,2016,2017,2018,2019,2020 -./lib/isc/include/isc/lfsr.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020 ./lib/isc/include/isc/lib.h C 1999,2000,2001,2004,2005,2006,2007,2009,2016,2018,2019,2020 ./lib/isc/include/isc/likely.h C 2017,2018,2019,2020 ./lib/isc/include/isc/list.h C 1997,1998,1999,2000,2001,2002,2004,2006,2007,2011,2012,2013,2016,2018,2019,2020 @@ -2012,7 +2011,6 @@ ./lib/isc/include/pkcs11/pkcs11.h X 2019,2020 ./lib/isc/iterated_hash.c C 2006,2008,2009,2016,2018,2019,2020 ./lib/isc/lex.c C 1998,1999,2000,2001,2002,2003,2004,2005,2007,2013,2014,2015,2016,2017,2018,2019,2020 -./lib/isc/lfsr.c C 1999,2000,2001,2002,2004,2005,2007,2016,2018,2019,2020 ./lib/isc/lib.c C 1999,2000,2001,2004,2005,2007,2009,2013,2014,2015,2016,2018,2019,2020 ./lib/isc/log.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2009,2011,2012,2013,2014,2016,2017,2018,2019,2020 ./lib/isc/md.c C 2018,2019,2020