[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] arc4random_addrandom
- To: libevent-users@xxxxxxxx
- Subject: [Libevent-users] arc4random_addrandom
- From: Jeffrey Walton <noloader@xxxxxxxxx>
- Date: Wed, 19 Feb 2014 00:14:29 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Wed, 19 Feb 2014 00:14:32 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:date:message-id:subject:from:to:content-type; bh=U8+lQXsmNpoz2GRfMBWoq17DWDeRaoq8jcaU3+dpe+g=; b=i3H6c7mHgJnO0uprzr+vrfdYBfhJjlbXN6v4e2i6nw5ZuFpd9bcJXg6KOJ1moYv/Vp WAXZU5oiscrSfxTznpDCep4UF18PmeAxULjFv750RtJ2h9OL6PSvVj2HTcjqzoOfeQsE 94KirBuciVfj/oZx5tB+oFxLsr5BrvP7FEvdF7PBYlk4nCBec6GCbQVsD1QaP9qozVhz TUO5azkiNNXen10dFupLkiZVKWgU4YThQIii66UqpUHx4kNXLMOY7JxieDJ8nznVFmbT lQ1pTxajHW3FmP01YDWpfewvaq/Q2iCPF/t7VeC4KT6xFlEjsvtYoUy+O7kHuiXQLxVS WsVw==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
This does not quite look right:
ARC4RANDOM_EXPORT void
arc4random_addrandom(const unsigned char *dat, int datlen)
{
int j;
_ARC4_LOCK();
if (!rs_initialized)
arc4_stir();
for (j = 0; j < datlen; j += 256) {
/* arc4_addrandom() ignores all but the first 256 bytes of
* its input. We want to make sure to look at ALL the
* data in 'dat', just in case the user is doing something
* crazy like passing us all the files in /var/log. */
arc4_addrandom(dat + j, datlen - j);
}
_ARC4_UNLOCK();
}
It looks like its a O(n^2) algorithm, and it could be painful if all
the data in /var/log is passed in.
Iter 0:
data + 0, datalen - 0
Iter 1:
data + 256, datalen - 256
Iter 2:
data + 512, datalen - 512
...
Pictorially, I think its:
****************
************
********
...
It feels like it should be:
k = min(256, datlen - j);
arc4_addrandom(dat + j, k);
Jeff
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.