The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Digest::HighwayHash - XS fast strong keyed hash function

SYNOPSIS

  use Digest::HighwayHash;
  say highway_hash64 [1, 2, 3, 4], 'hello';
  # 11956820856122239241
  say join ' ', @{highway_hash128([1, 2, 3, 4], 'hello')};
  # 3048112761216189476 13900443277579286659
  say join ' ', @{highway_hash256([1, 2, 3, 4], 'hello')};
  # 8099666330974151427 17027479935588128037 4015249936799013189 10027181291351549853

  my $state = Digest::HighwayHash->new([1, 2, 3, 4]);
  $state->append('he');
  $state->append('llo');
  say join ' ', @{$state->finish128};
  # 3048112761216189476 13900443277579286659

DESCRIPTION

HighwayHash is a fast and strong keyed hash function, documented at https://github.com/google/highwayhash.

This module has a procedural interface (used to hash an entire message) and an OO interface (used to hash a message bit by bit). The procedural interface is made of three functions, all exported by default:

highway_hash64 \@key, $input

Compute the 64-bit HighwayHash of $input, using \@key as a key. The key must be a 4-element arrayref, with each element either a number or (on Perls without 64-bit numbers) a Math::Int64 object. The result is a single number or (on Perls without 64-bit numbers) a Math::Int64 object.

highway_hash128 \@key, $input

Compute the 128-bit HighwayHash of $input, using \@key as a key. The key must be a 4-element arrayref, with each element either a number or (on Perls without 64-bit numbers) a Math::Int64 object. The result is an array of exactly two numbers or (on Perls without 64-bit numbers) Math::Int64 objects.

highway_hash256 \@key, $input

Compute the 256-bit HighwayHash of $input, using \@key as a key. The key must be a 4-element arrayref, with each element either a number or (on Perls without 64-bit numbers) a Math::Int64 object. The result is an array of exactly four numbers or (on Perls without 64-bit numbers) Math::Int64 objects.

The OO interface has these methods:

Digest::HighwayHash->new(\@key)

Initialize a new Digest::HighwayHash state with a given key. The append method will be called with this state and parts of the message, and then one of the finish* methods will be called to compute the result.

$state->append($input)

Append $input to the message to be hashed by $state.

$state->finish64
$state->finish128
$state->finish256

Compute and return the 64-bit, 128-bit, or respectively 256-bit HighwayHash of this state. The return values are the same as in the procedural interface.

SEE ALSO

https://github.com/google/highwayhash

AUTHOR

Marius Gavrilescu, <marius@ieval.ro>

COPYRIGHT AND LICENSE

Copyright (C) 2018 by Marius Gavrilescu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.1 or, at your option, any later version of Perl 5 you may have available.