From: David Miller <davem@davemloft.net>
To: mj@ucw.cz
Cc: netdev@vger.kernel.org
Subject: Re: ipv4: Simplify ARP hash function.
Date: Fri, 08 Jul 2011 10:54:30 -0700 (PDT) [thread overview]
Message-ID: <20110708.105430.2072718553430519147.davem@davemloft.net> (raw)
In-Reply-To: <20110708.104739.169518036069870432.davem@davemloft.net>
From: David Miller <davem@davemloft.net>
Date: Fri, 08 Jul 2011 10:47:39 -0700 (PDT)
> From: Martin Mares <mj@ucw.cz>
> Date: Fri, 8 Jul 2011 19:40:55 +0200
>
>> The hash function is linear, so it can be reduced to:
>>
>> a = key ^ dev->ifindex
>> return (a >> 8) ^ (a >> 16) ^ (a >> 24) // (1)
>> ^ (hash_rnd >> 8) ^ (hash_rnd >> 16) ^ (hash_rnd >> 24) // (2)
>
> Is this really the same? The inclusion of a full 32-bit xor
> with hash_rnd before folding was intentional, so that the
> final folding occurs on a completely "random" value.
For example, try out this test program. Run as "./x ${RANDOM_VALUE}",
it shows that the attacker cannot simply just iterate by the number of
hash table slots to create collisions, assuming a hash table size of
256 slots:
--------------------
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argp)
{
int i, rnd;
rnd = atoi(argp[1]);
for (i = 1; i < (64 * 1024); i += 256) {
int x = (i ^ rnd);
x ^= (x >> 8) ^ (x << 16) ^ (x >> 24);
x &= 0xff;
printf("%d\n", x);
}
return 0;
}
next prev parent reply other threads:[~2011-07-08 17:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-08 17:10 ipv4: Simplify ARP hash function David Miller
2011-07-08 17:40 ` Martin Mares
2011-07-08 17:47 ` David Miller
2011-07-08 17:54 ` David Miller [this message]
2011-07-08 18:03 ` John Heffner
2011-07-08 18:06 ` David Miller
2011-07-08 19:26 ` Roland Dreier
2011-07-08 19:27 ` David Miller
2011-07-08 19:39 ` Michał Mirosław
2011-07-08 19:51 ` David Miller
2011-07-08 19:59 ` David Miller
2011-07-08 20:10 ` Michał Mirosław
2011-07-08 20:34 ` Michał Mirosław
2011-07-08 20:35 ` David Miller
2011-07-08 20:44 ` Roland Dreier
2011-07-08 22:32 ` David Miller
2011-07-08 23:11 ` Roland Dreier
2011-07-10 19:07 ` David Miller
2011-07-08 23:41 ` Stephen Hemminger
2011-07-08 23:47 ` David Miller
2011-07-09 3:08 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110708.105430.2072718553430519147.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=mj@ucw.cz \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).