Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / isc / include / isc / lfsr.h
blobd4d9707000780ec4af73cf4eca43bd4949ca0198
1 /*
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 $ */
20 #ifndef ISC_LFSR_H
21 #define ISC_LFSR_H 1
23 /*! \file isc/lfsr.h */
25 #include <isc/lang.h>
26 #include <isc/types.h>
28 typedef struct isc_lfsr isc_lfsr_t;
30 /*%
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 *);
41 /*%
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.
45 struct isc_lfsr {
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 */
54 ISC_LANG_BEGINDECLS
57 void
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);
61 /*%<
62 * Initialize an LFSR.
64 * Note:
66 *\li Putting untrusted values into this function will cause the LFSR to
67 * generate (perhaps) non-maximal length sequences.
69 * Requires:
71 *\li lfsr != NULL
73 *\li 8 <= bits <= 32
75 *\li tap != 0
78 void
79 isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count);
80 /*%<
81 * Returns "count" bytes of data from the LFSR.
83 * Requires:
85 *\li lfsr be valid.
87 *\li data != NULL.
89 *\li count > 0.
92 void
93 isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip);
94 /*%<
95 * Skip "skip" states.
97 * Requires:
99 *\li lfsr be valid.
102 isc_uint32_t
103 isc_lfsr_generate32(isc_lfsr_t *lfsr1, isc_lfsr_t *lfsr2);
104 /*%<
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.
108 * WARNING:
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
113 * attack.
115 * Notes:
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
119 * from either LFSR.
121 * Requires:
123 *\li lfsr1 and lfsr2 be valid.
125 *\li 1 <= skipbits <= 31
128 ISC_LANG_ENDDECLS
130 #endif /* ISC_LFSR_H */