summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2008-03-15 04:57:51 +0000
committerDamien Miller <djm@cvs.openbsd.org>2008-03-15 04:57:51 +0000
commite3e28c1165458f7a58667f74181afcae889fb357 (patch)
tree12f47c3f86b9692ad7ced677edce3241f9fffee6 /usr.sbin
parente5c77630f050400096e5727c1267923f6ca50c4d (diff)
Because the shuffle code initialisation is a specific case of shuffling
a set of incrementing integers (and not an arbitrary set of values) it is possible to populate the array as we shuffle it in a single forward pass. Clever optimisation from didickman AT gmail.com; ok deraadt@ mcbride@ (same change as netinet/ip_id.c)
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bind/lib/isc/shuffle.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/usr.sbin/bind/lib/isc/shuffle.c b/usr.sbin/bind/lib/isc/shuffle.c
index 5e8bb6f9529..0cdcdef6f9b 100644
--- a/usr.sbin/bind/lib/isc/shuffle.c
+++ b/usr.sbin/bind/lib/isc/shuffle.c
@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $OpenBSD: shuffle.c,v 1.2 2008/03/02 22:39:12 djm Exp $ */
+/* $OpenBSD: shuffle.c,v 1.3 2008/03/15 04:57:50 djm Exp $ */
#include <config.h>
@@ -37,15 +37,11 @@ isc_shuffle_init(isc_shuffle_t *shuffle)
REQUIRE(VALID_SHUFFLE(shuffle));
shuffle->isindex = 0;
- for (i = 0; i < 65536; ++i)
- shuffle->id_shuffle[i] = i;
-
- /* Initialize using a Durstenfeld shuffle */
- for (i = 65536; --i; ) {
+ /* Initialize using a Knuth shuffle */
+ for (i = 0; i < 65536; ++i) {
i2 = isc_random_uniform(i + 1);
- r = shuffle->id_shuffle[i];
shuffle->id_shuffle[i] = shuffle->id_shuffle[i2];
- shuffle->id_shuffle[i2] = r;
+ shuffle->id_shuffle[i2] = i;
}
}