Also write documentation
[digest-highwayhash.git] / lib / Digest / HighwayHash.pm
CommitLineData
096619f2
MG
1package Digest::HighwayHash;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7
8our @EXPORT_OK = qw/highway_hash64 highway_hash128 highway_hash256/;
9our @EXPORT = @EXPORT_OK;
10
5c859103 11our $VERSION = '0.001001';
096619f2
MG
12
13use Math::Int64;
14
15require XSLoader;
16XSLoader::load('Digest::HighwayHash', $VERSION);
17
181;
19__END__
20
21=encoding utf-8
22
23=head1 NAME
24
fc185944 25Digest::HighwayHash - XS fast strong keyed hash function
096619f2
MG
26
27=head1 SYNOPSIS
28
29 use Digest::HighwayHash;
30 say highway_hash64 [1, 2, 3, 4], 'hello';
31 # 11956820856122239241
32 say join ' ', @{highway_hash128([1, 2, 3, 4], 'hello')};
33 # 3048112761216189476 13900443277579286659
34 say join ' ', @{highway_hash256([1, 2, 3, 4], 'hello')};
35 # 8099666330974151427 17027479935588128037 4015249936799013189 10027181291351549853
36
b3ec381e
MG
37 my $state = Digest::HighwayHash->new([1, 2, 3, 4]);
38 $state->append('he');
39 $state->append('llo');
40 say join ' ', @{$state->finish128};
41 # 3048112761216189476 13900443277579286659
42
096619f2
MG
43=head1 DESCRIPTION
44
fc185944 45HighwayHash is a fast and strong keyed hash function, documented at
096619f2
MG
46L<https://github.com/google/highwayhash>.
47
b3ec381e
MG
48This module has a procedural interface (used to hash an entire
49message) and an OO interface (used to hash a message bit by bit). The
50procedural interface is made of three functions, all exported by
51default:
fc185944
MG
52
53=over
54
55=item B<highway_hash64> I<\@key>, I<$input>
56
57Compute the 64-bit HighwayHash of I<$input>, using I<\@key> as a key.
58The key must be a 4-element arrayref, with each element either a
59number or (on Perls without 64-bit numbers) a L<Math::Int64> object. The result is a single number or (on Perls without 64-bit numbers) a L<Math::Int64> object.
60
61=item B<highway_hash128> I<\@key>, I<$input>
62
63Compute the 128-bit HighwayHash of I<$input>, using I<\@key> as a key.
64The key must be a 4-element arrayref, with each element either a
65number or (on Perls without 64-bit numbers) a L<Math::Int64> object. The result is an array of exactly two numbers or (on Perls without 64-bit numbers) L<Math::Int64> objects.
66
67=item B<highway_hash256> I<\@key>, I<$input>
68
69Compute the 256-bit HighwayHash of I<$input>, using I<\@key> as a key.
70The key must be a 4-element arrayref, with each element either a
71number or (on Perls without 64-bit numbers) a L<Math::Int64> object. The result is an array of exactly four numbers or (on Perls without 64-bit numbers) L<Math::Int64> objects.
72
73
b3ec381e
MG
74=back
75
76The OO interface has these methods:
77
78=over
79
80=item Digest::HighwayHash->B<new>(I<\@key>)
81
82Initialize a new C<Digest::HighwayHash> state with a given key. The
83B<append> method will be called with this state and parts of the
84message, and then one of the B<finish*> methods will be called to
85compute the result.
86
87=item $state->B<append>(I<$input>)
88
89Append I<$input> to the message to be hashed by $state.
90
91=item $state->B<finish64>
92
93=item $state->B<finish128>
94
95=item $state->B<finish256>
96
97Compute and return the 64-bit, 128-bit, or respectively 256-bit
98HighwayHash of this state. The return values are the same as in the
99procedural interface.
100
fc185944
MG
101=back
102
096619f2
MG
103=head1 SEE ALSO
104
105L<https://github.com/google/highwayhash>
106
107=head1 AUTHOR
108
109Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
110
111=head1 COPYRIGHT AND LICENSE
112
113Copyright (C) 2018 by Marius Gavrilescu
114
115This library is free software; you can redistribute it and/or modify
116it under the same terms as Perl itself, either Perl version 5.24.1 or,
117at your option, any later version of Perl 5 you may have available.
118
119
120=cut
This page took 0.015626 seconds and 4 git commands to generate.