summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2003-01-20 21:28:49 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2003-01-20 21:28:49 +0000
commitf04ce03827c60cbd08a590c280618e260e5dd700 (patch)
treed2f79fe0839924a27de5063d788d90bff9b48c5c
parent9c0ed79401801d92ea3501cc035c89ca6e1a2c29 (diff)
use lcg instad of lfsr for id generation
-rw-r--r--usr.sbin/bind/lib/dns/dispatch.c44
1 files changed, 4 insertions, 40 deletions
diff --git a/usr.sbin/bind/lib/dns/dispatch.c b/usr.sbin/bind/lib/dns/dispatch.c
index 2cc3841fb3d..8a5d886b5f6 100644
--- a/usr.sbin/bind/lib/dns/dispatch.c
+++ b/usr.sbin/bind/lib/dns/dispatch.c
@@ -45,8 +45,7 @@ typedef struct dns_qid {
unsigned int qid_nbuckets; /* hash table size */
unsigned int qid_increment; /* id increment on collision */
isc_mutex_t lock;
- isc_lfsr_t qid_lfsr1; /* state generator info */
- isc_lfsr_t qid_lfsr2; /* state generator info */
+ isc_lcg_t qid_lcg; /* state generator info */
dns_displist_t *qid_table; /* the table itself */
} dns_qid_t;
@@ -256,36 +255,14 @@ request_log(dns_dispatch_t *disp, dns_dispentry_t *resp,
}
}
-static void
-reseed_lfsr(isc_lfsr_t *lfsr, void *arg)
-{
- dns_dispatchmgr_t *mgr = arg;
- isc_result_t result;
- isc_uint32_t val;
-
- REQUIRE(VALID_DISPATCHMGR(mgr));
-
- if (mgr->entropy != NULL) {
- result = isc_entropy_getdata(mgr->entropy, &val, sizeof val,
- NULL, 0);
- INSIST(result == ISC_R_SUCCESS);
- lfsr->count = (val & 0x1f) + 32;
- lfsr->state = val;
- return;
- }
-
- lfsr->count = (random() & 0x1f) + 32; /* From 32 to 63 states */
- lfsr->state = random();
-}
-
/*
* Return an unpredictable message ID.
*/
static dns_messageid_t
dns_randomid(dns_qid_t *qid) {
- isc_uint32_t id;
+ isc_uint16_t id;
- id = isc_lfsr_generate32(&qid->qid_lfsr1, &qid->qid_lfsr2);
+ id = isc_lcg_generate16(&qid->qid_lcg);
return (dns_messageid_t)(id & 0xFFFF);
}
@@ -1304,20 +1281,7 @@ qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
qid->qid_increment = increment;
qid->magic = QID_MAGIC;
- /*
- * Initialize to a 32-bit LFSR. Both of these are from Applied
- * Cryptography.
- *
- * lfsr1:
- * x^32 + x^7 + x^5 + x^3 + x^2 + x + 1
- *
- * lfsr2:
- * x^32 + x^7 + x^6 + x^2 + 1
- */
- isc_lfsr_init(&qid->qid_lfsr1, 0, 32, 0x80000057U,
- 0, reseed_lfsr, mgr);
- isc_lfsr_init(&qid->qid_lfsr2, 0, 32, 0x800000c2U,
- 0, reseed_lfsr, mgr);
+ isc_lcg_init(&qid->qid_lcg);
*qidp = qid;
return (ISC_R_SUCCESS);
}