Crypt::NaCl::Sodium::shorthash - Short-input hashing (SipHash-2-4)
version 1.0.8.0
use Crypt::NaCl::Sodium qw( :utils ); # for converting to 64-bit integers use Math::BigInt; my $crypto_shorthash = Crypt::NaCl::Sodium->shorthash(); my ($key, $mac, $msg); # generate secret key $key = $crypto_shorthash->keygen(); # list of short file names for which we are computing the checksums my @files = ...; for my $file ( @files ) { my $mac = $crypto_shorthash->mac( $file, $key ); # MAC is 64-bit string print "$file\t", $mac->to_hex, "\n"; # which can be converted to 64-bit integer print "$file\t", Math::BigInt->from_hex($mac->to_hex), "\n"; }
Many applications and programming language implementations were recently found to be vulnerable to denial-of-service attacks when a hash function with weak security guarantees, such as Murmurhash 3, was used to construct a hash table.
In order to address this, crypto_shorthash outputs short but unpredictable (without knowing the secret key) values suitable for picking a list in a hash table for a given key.
crypto_shorthash
This function is optimized for short inputs.
The output of this function is only 64 bits. Therefore, it should not be considered collision-resistant.
Use cases:
Hash tables
Probabilistic data structures such as Bloom filters
Integrity checking in interactive protocols
my $key = $crypto_shorthash->keygen();
Helper method to generate a random key to be used by $crypto_shorthash.
$crypto_shorthash
The length of the $key equals "KEYBYTES".
$key
NOTE: keep the key confidential.
Returns Data::BytesLocker object.
my $mac = $crypto_shorthash->mac( $msg, $key );
Computes the MAC of the $msg using given $key.
$msg
The length of the $mac equals "BYTES".
$mac
my $key_length = $crypto_shorthash->KEYBYTES;
Returns the length of key.
my $mac_length = $crypto_shorthash->BYTES;
Returns the length of MAC.
crypto_shorthash uses SipHash-2-4 pseudorandom hash optimized for speed on short messages.
Data::BytesLocker - guarded data storage
SipHash: a fast short-input PRF
Alex J. G. Burzyński <ajgb@cpan.org>
This software is copyright (c) 2015 by Alex J. G. Burzyński <ajgb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Crypt::NaCl::Sodium, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crypt::NaCl::Sodium
CPAN shell
perl -MCPAN -e shell install Crypt::NaCl::Sodium
For more information on module installation, please visit the detailed CPAN module installation guide.