line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: set expandtab ts=4 sw=4 nowrap ft=perl ff=unix : |
2
|
|
|
|
|
|
|
package Digest::BLAKE2; |
3
|
2
|
|
|
2
|
|
14067
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
90
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
787
|
use parent qw/Exporter Digest::base/; |
|
2
|
|
|
|
|
483
|
|
|
2
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Digest::BLAKE2b |
11
|
2
|
|
|
2
|
|
724
|
qw/blake2b blake2b_hex blake2b_base64 blake2b_base64url blake2b_ascii85/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
203
|
|
12
|
|
|
|
|
|
|
use Digest::BLAKE2s |
13
|
2
|
|
|
2
|
|
745
|
qw/blake2s blake2s_hex blake2s_base64 blake2s_base64url blake2s_ascii85/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
612
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#use Digest::BLAKE2bp |
16
|
|
|
|
|
|
|
# qw/blake2bp blake2bp_hex blake2bp_base64 blake2bp_base64url blake2bp_ascii85/; |
17
|
|
|
|
|
|
|
#use Digest::BLAKE2sp |
18
|
|
|
|
|
|
|
# qw/blake2sp blake2sp_hex blake2sp_base64 blake2sp_base64url blake2sp_ascii85/; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
21
|
|
|
|
|
|
|
blake2b blake2b_hex blake2b_base64 blake2b_base64url blake2b_ascii85 |
22
|
|
|
|
|
|
|
blake2s blake2s_hex blake2s_base64 blake2s_base64url blake2s_ascii85 |
23
|
|
|
|
|
|
|
/; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# blake2bp blake2bp_hex blake2bp_base64 blake2bp_base64url blake2bp_ascii85 |
26
|
|
|
|
|
|
|
# blake2sp blake2sp_hex blake2sp_base64 blake2sp_base64url blake2sp_ascii85 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
4
|
|
|
4
|
0
|
20248
|
my ($class, $algorithm) = @_; |
30
|
4
|
|
50
|
|
|
11
|
$algorithm ||= 'b'; |
31
|
4
|
50
|
|
|
|
29
|
unless ($algorithm =~ /^(blake2|BLAKE2)?((b|s)p?)$/) { |
32
|
0
|
|
|
|
|
0
|
die 'Invalid algorithm.'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
bless +{ |
35
|
4
|
|
|
|
|
38
|
instance => "Digest::BLAKE2$2"->new, |
36
|
|
|
|
|
|
|
}, $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub clone { |
40
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
41
|
0
|
|
|
|
|
0
|
$self->{instance}->clone(@_); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add { |
45
|
4
|
|
|
4
|
0
|
17
|
my $self = shift; |
46
|
4
|
|
|
|
|
21
|
$self->{instance}->add(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub digest { |
50
|
4
|
|
|
4
|
0
|
15
|
my $self = shift; |
51
|
4
|
|
|
|
|
36
|
$self->{instance}->digest(@_); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Digest::BLAKE2 - Perl XS interface to the BLAKE2 algorithms |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Digest::BLAKE2 qw(blake2b blake2b_hex blake2b_base64 blake2b_base64url blake2b_ascii85); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# blake2b |
65
|
|
|
|
|
|
|
print blake2b('Japan Break Industries'); |
66
|
|
|
|
|
|
|
print blake2b_hex('Japan Break Industries'); |
67
|
|
|
|
|
|
|
print blake2b_base64('Japan Break Industries'); |
68
|
|
|
|
|
|
|
print blake2b_base64url('Japan Break Industries'); |
69
|
|
|
|
|
|
|
print blake2b_ascii85('Japan Break Industries'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# blake2s |
72
|
|
|
|
|
|
|
print Digest::BLAKE2::blake2s('Japan Break Industries'); |
73
|
|
|
|
|
|
|
print Digest::BLAKE2::blake2s_hex('Japan Break Industries'); |
74
|
|
|
|
|
|
|
print Digest::BLAKE2::blake2s_base64('Japan Break Industries'); |
75
|
|
|
|
|
|
|
print Digest::BLAKE2::blake2s_base64url('Japan Break Industries'); |
76
|
|
|
|
|
|
|
print Digest::BLAKE2::blake2s_ascii85('Japan Break Industries'); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# object interface provided by Digest::base |
79
|
|
|
|
|
|
|
my $b = Digest::BLAKE2->new('blake2s'); |
80
|
|
|
|
|
|
|
$b->add('Japan Break Industries'); |
81
|
|
|
|
|
|
|
print $b->digest; |
82
|
|
|
|
|
|
|
print $b->b64digest; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The C module provides an interface to the BLAKE2 message |
87
|
|
|
|
|
|
|
digest algorithm. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The cryptographic hash function BLAKE2 is an improved version of the SHA-3 finalist BLAKE. |
90
|
|
|
|
|
|
|
Like BLAKE or SHA-3, BLAKE2 offers the highest security, yet is fast as MD5 on 64-bit platforms and requires at least 33% less RAM than SHA-2 or SHA-3 on low-end systems. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
BLAKE2 comes in two flavors. |
93
|
|
|
|
|
|
|
BLAKE2b is optimized for 64-bit platforms—including NEON-enabled ARMs—and produces digests of any size between 1 and 64 bytes. |
94
|
|
|
|
|
|
|
BLAKE2s is optimized for 8- to 32-bit platforms and produces digests of any size between 1 and 32 bytes. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This interface follows the conventions set forth by the C module. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 FUNCTIONS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
None of these functions are exported by default. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 blake2b($data, ...) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 blake2s($data, ...) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Logically joins the arguments into a single string, and returns its BLAKE2 |
107
|
|
|
|
|
|
|
digest encoded as a binary string. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 blake2b_hex($data, ...) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 blake2s_hex($data, ...) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Logically joins the arguments into a single string, and returns its BLAKE2 |
114
|
|
|
|
|
|
|
digest encoded as a hexadecimal string. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 blake2b_base64($data, ...) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 blake2s_base64($data, ...) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Logically joins the arguments into a single string, and returns its BLAKE2 |
121
|
|
|
|
|
|
|
digest encoded as a Base64 string, without any trailing padding. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 blake2b_base64url($data, ...) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 blake2s_base64url($data, ...) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Logically joins the arguments into a single string, and returns its BLAKE2 |
128
|
|
|
|
|
|
|
digest encoded as a urlsafe Base64 string, without any trailing padding. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 blake2b_ascii85($data, ...) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 blake2s_ascii85($data, ...) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Logically joins the arguments into a single string, and returns its BLAKE2 |
135
|
|
|
|
|
|
|
digest encoded as a Ascii85 string, without any trailing padding. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
C |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
C |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
C |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Tasuku SUENAGA a.k.a. gunyarakun Etasuku-s-cpan ATAT titech.acE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 LICENSE |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright (C) Tasuku SUENAGA a.k.a. gunyarakun |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
154
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
155
|
|
|
|
|
|
|
=cut |