require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(lock_keys unlock_keys lock_value unlock_value
- lock_hash unlock_hash
+ lock_hash unlock_hash hash_seed
);
our $VERSION = 0.05;
use Hash::Util qw(lock_keys unlock_keys
lock_value unlock_value
- lock_hash unlock_hash);
+ lock_hash unlock_hash
+ hash_seed);
%hash = (foo => 42, bar => 23);
lock_keys(%hash);
lock_hash (%hash);
unlock_hash(%hash);
+ my $hashes_are_randomised = hash_seed() != 0;
+
=head1 DESCRIPTION
C<Hash::Util> contains special functions for manipulating hashes that
}
+=item B<hash_seed>
+
+ my $hash_seed = hash_seed();
+
+hash_seed() returns the seed number used to randomise hash ordering.
+Zero means the "traditional" random hash ordering, non-zero means the
+new even more random hash ordering introduced in Perl 5.8.1.
+
+=cut
+
+sub hash_seed () {
+ Internals::hash_seed();
+}
+
=back
=head1 CAVEATS
=head1 SEE ALSO
-L<Scalar::Util>, L<List::Util>, L<Hash::Util>
+L<Scalar::Util>, L<List::Util>, L<Hash::Util>,
+and L<perlsec/"Algorithmic Complexity Attacks">.
=cut
chdir 't';
}
}
-use Test::More tests => 155;
+use Test::More tests => 157;
use strict;
my @Exported_Funcs;
@Exported_Funcs = qw(lock_keys unlock_keys
lock_value unlock_value
lock_hash unlock_hash
+ hash_seed
);
use_ok 'Hash::Util', @Exported_Funcs;
}
}
}
}
+
+my $hash_seed = hash_seed();
+ok($hash_seed >= 0, "hash_seed $hash_seed");
This means that each different run of Perl will have a different
ordering of the results of keys(), values(), and each().
-See L<perlsec/"Algorithmic Complexity Attacks"> for more information.
+See L<perlsec/"Algorithmic Complexity Attacks"> for more information,
+and also L</PERL_HASH_SEED>.
=item PERL_HASH_SEED_DEBUG
(Since Perl 5.8.1.) Set to "1" to display (to STDERR) the value of
the hash seed at the beginning of execution.
+See also hash_seed() of L<Hash::Util>.
=item PERL_ROOT (specific to the VMS port)
XS(XS_Internals_hv_clear_placehold);
XS(XS_PerlIO_get_layers);
XS(XS_Regexp_DESTROY);
+XS(XS_Internals_hash_seed);
void
Perl_boot_core_UNIVERSAL(pTHX)
newXSproto("PerlIO::get_layers",
XS_PerlIO_get_layers, file, "*;@");
newXS("Regexp::DESTROY", XS_Regexp_DESTROY, file);
+ newXSproto("Internals::hash_seed",XS_Internals_hash_seed, file, "");
}
XSRETURN(0);
}
+XS(XS_Internals_hash_seed)
+{
+ dXSARGS;
+ XSRETURN_UV(PL_hash_seed);
+}
+