2 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: lfsr.h,v 1.17 2007/06/19 23:47:18 tbox Exp $ */
23 /*! \file isc/lfsr.h */
26 #include <isc/types.h>
28 typedef struct isc_lfsr isc_lfsr_t;
31 * This function is called when reseeding is needed. It is allowed to
32 * modify any state in the LFSR in any way it sees fit OTHER THAN "bits".
34 * It MUST set "count" to a new value or the lfsr will never reseed again.
36 * Also, a reseed will never occur in the middle of an extraction. This
37 * is purely an optimization, and is probably what one would want.
39 typedef void (*isc_lfsrreseed_t)(isc_lfsr_t *, void *);
42 * The members of this structure can be used by the application, but care
43 * needs to be taken to not change state once the lfsr is in operation.
46 isc_uint32_t state; /*%< previous state */
47 unsigned int bits; /*%< length */
48 isc_uint32_t tap; /*%< bit taps */
49 unsigned int count; /*%< reseed count (in BITS!) */
50 isc_lfsrreseed_t reseed; /*%< reseed function */
51 void *arg; /*%< reseed function argument */
58 isc_lfsr_init(isc_lfsr_t *lfsr, isc_uint32_t state, unsigned int bits,
59 isc_uint32_t tap, unsigned int count,
60 isc_lfsrreseed_t reseed, void *arg);
66 *\li Putting untrusted values into this function will cause the LFSR to
67 * generate (perhaps) non-maximal length sequences.
79 isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count);
81 * Returns "count" bytes of data from the LFSR.
93 isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip);
103 isc_lfsr_generate32(isc_lfsr_t *lfsr1, isc_lfsr_t *lfsr2);
105 * Given two LFSRs, use the current state from each to skip entries in the
106 * other. The next states are then xor'd together and returned.
110 *\li This function is used only for very, very low security data, such
111 * as DNS message IDs where it is desired to have an unpredictable
112 * stream of bytes that are harder to predict than a simple flooding
117 *\li Since the current state from each of the LFSRs is used to skip
118 * state in the other, it is important that no state be leaked
123 *\li lfsr1 and lfsr2 be valid.
125 *\li 1 <= skipbits <= 31
130 #endif /* ISC_LFSR_H */