develooper Front page | perl.perl5.porters | Postings from October 2003

Re: 5.8.2-RC1 and mp2

Thread Previous | Thread Next
From:
Mark Jason Dominus
Date:
October 30, 2003 18:12
Subject:
Re: 5.8.2-RC1 and mp2
Message ID:
20031031021237.30113.qmail@plover.com
> 1) replace the hardcoded attack input (from the original attack report by 
> Scott) to something that's autogenerated. I want a sub that I can ask for N 
> number of hash keys that will collapse into the same list.

        sub gen_n_colliding_hash_keys {
          my ($N, $hashf) = @_;
          my @keys;
          my %test;
          my $s = "a";
          while (@keys < $N) {
            my $h = $hashf->($s);
            next unless ($h & 7) == 0;
            push @keys, $s;
        # This only makes sense in 5.8.0 and earlier
        #    $HASH{$s} = 1;
        #    unless (%HASH eq "1/8") {
        #      die "Hash key did not collide; aborting";
        #    }
          } continue {
            $s++;
          }
          @keys;
        }

        sub hash {
          use integer;
          my $s = shift;
          my @c = split //, $s;
          my $u = 0;
          for (@c) {
            $u += ord;
            $u += $u << 10;
            $u ^= $u >> 6;
          }
          $u += $u << 3;
          $u ^= $u >> 11;
          $u += $u << 15;
          $u;
        }


To use, call this with

        my @keys = gen_n_colliding_hash_keys(12345, \&hash);

where 12345 is the number of keys you want to generate.

I'm posting this to the list in the hope that it wil be generally
useful.  The hash() sub matches the hash function in hv.h; if the hash
function changes, you will need to change the second argument to
gen_n_colliding_hash_keys.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About