NAME
Crypt::NaCl::Sodium::shorthash - Short-input hashing (SipHash-2-4)
VERSION
version 1.0.7.0
SYNOPSIS
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";
}
DESCRIPTION
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.
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
METHODS
keygen
my $key = $crypto_shorthash->keygen();
Helper method to generate a random key to be used by $crypto_shorthash
.
The length of the $key
equals "KEYBYTES".
NOTE: keep the key confidential.
Returns Data::BytesLocker object.
mac
my $mac = $crypto_shorthash->mac( $msg, $key );
Computes the MAC of the $msg
using given $key
.
The length of the $mac
equals "BYTES".
Returns Data::BytesLocker object.
CONSTANTS
KEYBYTES
my $key_length = $crypto_shorthash->KEYBYTES;
Returns the length of key.
BYTES
my $mac_length = $crypto_shorthash->BYTES;
Returns the length of MAC.
SECURITY MODEL
crypto_shorthash
uses SipHash-2-4 pseudorandom hash optimized for speed on short messages.
SEE ALSO
Data::BytesLocker - guarded data storage
AUTHOR
Alex J. G. Burzyński <ajgb@cpan.org>
COPYRIGHT AND LICENSE
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.