2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Remove unused isc_lfsr API

The isc_lfsr API was used to generate message IDs in the past.
Currently, it's just cruft.
This commit is contained in:
Ondřej Surý 2020-04-23 12:16:22 +02:00
parent f6d15d5af8
commit bdca09aa8d
7 changed files with 0 additions and 289 deletions

View File

@ -41,7 +41,6 @@ libisc_la_HEADERS = \
include/isc/iterated_hash.h \ include/isc/iterated_hash.h \
include/isc/lang.h \ include/isc/lang.h \
include/isc/lex.h \ include/isc/lex.h \
include/isc/lfsr.h \
include/isc/lib.h \ include/isc/lib.h \
include/isc/likely.h \ include/isc/likely.h \
include/isc/list.h \ include/isc/list.h \
@ -173,7 +172,6 @@ libisc_la_SOURCES = \
httpd.c \ httpd.c \
iterated_hash.c \ iterated_hash.c \
lex.c \ lex.c \
lfsr.c \
lib.c \ lib.c \
log.c \ log.c \
md.c \ md.c \

View File

@ -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 <inttypes.h>
#include <isc/lang.h>
#include <isc/types.h>
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 */

View File

@ -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 <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <isc/assertions.h>
#include <isc/lfsr.h>
#include <isc/util.h>
#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);
}

View File

@ -328,10 +328,6 @@ isc_lex_setsourceline
isc_lex_setsourcename isc_lex_setsourcename
isc_lex_setspecials isc_lex_setspecials
isc_lex_ungettoken isc_lex_ungettoken
isc_lfsr_generate
isc_lfsr_generate32
isc_lfsr_init
isc_lfsr_skip
isc_lib_register isc_lib_register
isc_log_categorybyname isc_log_categorybyname
isc_log_closefilelogs isc_log_closefilelogs

View File

@ -131,9 +131,6 @@
<ClInclude Include="..\include\isc\lex.h"> <ClInclude Include="..\include\isc\lex.h">
<Filter>Library Header Files</Filter> <Filter>Library Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\include\isc\lfsr.h">
<Filter>Library Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\isc\lib.h"> <ClInclude Include="..\include\isc\lib.h">
<Filter>Library Header Files</Filter> <Filter>Library Header Files</Filter>
</ClInclude> </ClInclude>
@ -515,9 +512,6 @@
<ClCompile Include="..\lex.c"> <ClCompile Include="..\lex.c">
<Filter>Library Source Files</Filter> <Filter>Library Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\lfsr.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\lib.c"> <ClCompile Include="..\lib.c">
<Filter>Library Source Files</Filter> <Filter>Library Source Files</Filter>
</ClCompile> </ClCompile>

View File

@ -326,7 +326,6 @@ copy InstallFiles ..\Build\Release\
<ClInclude Include="..\include\isc\json.h" /> <ClInclude Include="..\include\isc\json.h" />
<ClInclude Include="..\include\isc\lang.h" /> <ClInclude Include="..\include\isc\lang.h" />
<ClInclude Include="..\include\isc\lex.h" /> <ClInclude Include="..\include\isc\lex.h" />
<ClInclude Include="..\include\isc\lfsr.h" />
<ClInclude Include="..\include\isc\lib.h" /> <ClInclude Include="..\include\isc\lib.h" />
<ClInclude Include="..\include\isc\list.h" /> <ClInclude Include="..\include\isc\list.h" />
<ClInclude Include="..\include\isc\log.h" /> <ClInclude Include="..\include\isc\log.h" />
@ -434,7 +433,6 @@ copy InstallFiles ..\Build\Release\
<ClCompile Include="..\httpd.c" /> <ClCompile Include="..\httpd.c" />
<ClCompile Include="..\iterated_hash.c" /> <ClCompile Include="..\iterated_hash.c" />
<ClCompile Include="..\lex.c" /> <ClCompile Include="..\lex.c" />
<ClCompile Include="..\lfsr.c" />
<ClCompile Include="..\lib.c" /> <ClCompile Include="..\lib.c" />
<ClCompile Include="..\log.c" /> <ClCompile Include="..\log.c" />
<ClCompile Include="..\md.c" /> <ClCompile Include="..\md.c" />

View File

@ -1955,7 +1955,6 @@
./lib/isc/include/isc/iterated_hash.h C 2008,2014,2016,2018,2019,2020 ./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/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/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/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/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 ./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/include/pkcs11/pkcs11.h X 2019,2020
./lib/isc/iterated_hash.c C 2006,2008,2009,2016,2018,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/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/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/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 ./lib/isc/md.c C 2018,2019,2020