1package Digest::SHA;
2
3require 5.003000;
4
5use strict;
6use warnings;
7use vars qw($VERSION @ISA @EXPORT_OK $errmsg);
8use Fcntl qw(O_RDONLY O_RDWR);
9use Cwd qw(getcwd);
10use integer;
11
12$VERSION = '6.04';
13
14require Exporter;
15@ISA = qw(Exporter);
16@EXPORT_OK = qw(
17	$errmsg
18	hmac_sha1	hmac_sha1_base64	hmac_sha1_hex
19	hmac_sha224	hmac_sha224_base64	hmac_sha224_hex
20	hmac_sha256	hmac_sha256_base64	hmac_sha256_hex
21	hmac_sha384	hmac_sha384_base64	hmac_sha384_hex
22	hmac_sha512	hmac_sha512_base64	hmac_sha512_hex
23	hmac_sha512224	hmac_sha512224_base64	hmac_sha512224_hex
24	hmac_sha512256	hmac_sha512256_base64	hmac_sha512256_hex
25	sha1		sha1_base64		sha1_hex
26	sha224		sha224_base64		sha224_hex
27	sha256		sha256_base64		sha256_hex
28	sha384		sha384_base64		sha384_hex
29	sha512		sha512_base64		sha512_hex
30	sha512224	sha512224_base64	sha512224_hex
31	sha512256	sha512256_base64	sha512256_hex);
32
33# Inherit from Digest::base if possible
34
35eval {
36	require Digest::base;
37	push(@ISA, 'Digest::base');
38};
39
40# The following routines aren't time-critical, so they can be left in Perl
41
42sub new {
43	my($class, $alg) = @_;
44	$alg =~ s/\D+//g if defined $alg;
45	if (ref($class)) {	# instance method
46		if (!defined($alg) || ($alg == $class->algorithm)) {
47			sharewind($class);
48			return($class);
49		}
50		return shainit($class, $alg) ? $class : undef;
51	}
52	$alg = 1 unless defined $alg;
53	return $class->newSHA($alg);
54}
55
56BEGIN { *reset = \&new }
57
58sub add_bits {
59	my($self, $data, $nbits) = @_;
60	unless (defined $nbits) {
61		$nbits = length($data);
62		$data = pack("B*", $data);
63	}
64	$nbits = length($data) * 8 if $nbits > length($data) * 8;
65	shawrite($data, $nbits, $self);
66	return($self);
67}
68
69sub _bail {
70	my $msg = shift;
71
72	$errmsg = $!;
73	$msg .= ": $!";
74	require Carp;
75	Carp::croak($msg);
76}
77
78{
79	my $_can_T_filehandle;
80
81	sub _istext {
82		local *FH = shift;
83		my $file = shift;
84
85		if (! defined $_can_T_filehandle) {
86			local $^W = 0;
87			my $istext = eval { -T FH };
88			$_can_T_filehandle = $@ ? 0 : 1;
89			return $_can_T_filehandle ? $istext : -T $file;
90		}
91		return $_can_T_filehandle ? -T FH : -T $file;
92	}
93}
94
95sub _addfile {
96	my ($self, $handle) = @_;
97
98	my $n;
99	my $buf = "";
100
101	while (($n = read($handle, $buf, 4096))) {
102		$self->add($buf);
103	}
104	_bail("Read failed") unless defined $n;
105
106	$self;
107}
108
109sub addfile {
110	my ($self, $file, $mode) = @_;
111
112	return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR';
113
114	$mode = defined($mode) ? $mode : "";
115	my ($binary, $UNIVERSAL, $BITS) =
116		map { $_ eq $mode } ("b", "U", "0");
117
118		## Always interpret "-" to mean STDIN; otherwise use
119		##	sysopen to handle full range of POSIX file names.
120		## If $file is a directory, force an EISDIR error
121		##	by attempting to open with mode O_RDWR
122
123	local *FH;
124	if ($file eq '-') {
125		if (-d STDIN) {
126			sysopen(FH, getcwd(), O_RDWR)
127				or _bail('Open failed');
128		}
129		open(FH, '< -')
130			or _bail('Open failed');
131	}
132	else {
133		sysopen(FH, $file, -d $file ? O_RDWR : O_RDONLY)
134			or _bail('Open failed');
135	}
136
137	if ($BITS) {
138		my ($n, $buf) = (0, "");
139		while (($n = read(FH, $buf, 4096))) {
140			$buf =~ tr/01//cd;
141			$self->add_bits($buf);
142		}
143		_bail("Read failed") unless defined $n;
144		close(FH);
145		return($self);
146	}
147
148	binmode(FH) if $binary || $UNIVERSAL;
149	if ($UNIVERSAL && _istext(*FH, $file)) {
150		$self->_addfileuniv(*FH);
151	}
152	else { $self->_addfilebin(*FH) }
153	close(FH);
154
155	$self;
156}
157
158sub getstate {
159	my $self = shift;
160
161	my $alg = $self->algorithm or return;
162	my $state = $self->_getstate or return;
163	my $nD = $alg <= 256 ?  8 :  16;
164	my $nH = $alg <= 256 ? 32 :  64;
165	my $nB = $alg <= 256 ? 64 : 128;
166	my($H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) =
167		$state =~ /^(.{$nH})(.{$nB})(.{4})(.{4})(.{4})(.{4})(.{4})$/s;
168	for ($alg, $H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) {
169		return unless defined $_;
170	}
171
172	my @s = ();
173	push(@s, "alg:" . $alg);
174	push(@s, "H:" . join(":", unpack("H*", $H) =~ /.{$nD}/g));
175	push(@s, "block:" . join(":", unpack("H*", $block) =~ /.{2}/g));
176	push(@s, "blockcnt:" . unpack("N", $blockcnt));
177	push(@s, "lenhh:" . unpack("N", $lenhh));
178	push(@s, "lenhl:" . unpack("N", $lenhl));
179	push(@s, "lenlh:" . unpack("N", $lenlh));
180	push(@s, "lenll:" . unpack("N", $lenll));
181	join("\n", @s) . "\n";
182}
183
184sub putstate {
185	my($class, $state) = @_;
186
187	my %s = ();
188	for (split(/\n/, $state)) {
189		s/^\s+//;
190		s/\s+$//;
191		next if (/^(#|$)/);
192		my @f = split(/[:\s]+/);
193		my $tag = shift(@f);
194		$s{$tag} = join('', @f);
195	}
196
197	# H and block may contain arbitrary values, but check everything else
198	grep { $_ == $s{'alg'} } (1,224,256,384,512,512224,512256) or return;
199	length($s{'H'}) == ($s{'alg'} <= 256 ? 64 : 128) or return;
200	length($s{'block'}) == ($s{'alg'} <= 256 ? 128 : 256) or return;
201	{
202		no integer;
203		for (qw(blockcnt lenhh lenhl lenlh lenll)) {
204			0 <= $s{$_} or return;
205			$s{$_} <= 4294967295 or return;
206		}
207		$s{'blockcnt'} < ($s{'alg'} <= 256 ? 512 : 1024) or return;
208	}
209
210	my $packed_state = (
211		pack("H*", $s{'H'}) .
212		pack("H*", $s{'block'}) .
213		pack("N",  $s{'blockcnt'}) .
214		pack("N",  $s{'lenhh'}) .
215		pack("N",  $s{'lenhl'}) .
216		pack("N",  $s{'lenlh'}) .
217		pack("N",  $s{'lenll'})
218	);
219
220	return $class->new($s{'alg'})->_putstate($packed_state);
221}
222
223sub dump {
224	my $self = shift;
225	my $file = shift;
226
227	my $state = $self->getstate or return;
228	$file = "-" if (!defined($file) || $file eq "");
229
230	local *FH;
231	open(FH, "> $file") or return;
232	print FH $state;
233	close(FH);
234
235	return($self);
236}
237
238sub load {
239	my $class = shift;
240	my $file = shift;
241
242	$file = "-" if (!defined($file) || $file eq "");
243
244	local *FH;
245	open(FH, "< $file") or return;
246	my $str = join('', <FH>);
247	close(FH);
248
249	$class->putstate($str);
250}
251
252eval {
253	require XSLoader;
254	XSLoader::load('Digest::SHA', $VERSION);
255	1;
256} or do {
257	require DynaLoader;
258	push @ISA, 'DynaLoader';
259	Digest::SHA->bootstrap($VERSION);
260};
261
2621;
263__END__
264
265=head1 NAME
266
267Digest::SHA - Perl extension for SHA-1/224/256/384/512
268
269=head1 SYNOPSIS
270
271In programs:
272
273		# Functional interface
274
275	use Digest::SHA qw(sha1 sha1_hex sha1_base64 ...);
276
277	$digest = sha1($data);
278	$digest = sha1_hex($data);
279	$digest = sha1_base64($data);
280
281	$digest = sha256($data);
282	$digest = sha384_hex($data);
283	$digest = sha512_base64($data);
284
285		# Object-oriented
286
287	use Digest::SHA;
288
289	$sha = Digest::SHA->new($alg);
290
291	$sha->add($data);		# feed data into stream
292
293	$sha->addfile(*F);
294	$sha->addfile($filename);
295
296	$sha->add_bits($bits);
297	$sha->add_bits($data, $nbits);
298
299	$sha_copy = $sha->clone;	# make copy of digest object
300	$state = $sha->getstate;	# save current state to string
301	$sha->putstate($state);		# restore previous $state
302
303	$digest = $sha->digest;		# compute digest
304	$digest = $sha->hexdigest;
305	$digest = $sha->b64digest;
306
307From the command line:
308
309	$ shasum files
310
311	$ shasum --help
312
313=head1 SYNOPSIS (HMAC-SHA)
314
315		# Functional interface only
316
317	use Digest::SHA qw(hmac_sha1 hmac_sha1_hex ...);
318
319	$digest = hmac_sha1($data, $key);
320	$digest = hmac_sha224_hex($data, $key);
321	$digest = hmac_sha256_base64($data, $key);
322
323=head1 ABSTRACT
324
325Digest::SHA is a complete implementation of the NIST Secure Hash Standard.
326It gives Perl programmers a convenient way to calculate SHA-1, SHA-224,
327SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 message digests.
328The module can handle all types of input, including partial-byte data.
329
330=head1 DESCRIPTION
331
332Digest::SHA is written in C for speed.  If your platform lacks a
333C compiler, you can install the functionally equivalent (but much
334slower) L<Digest::SHA::PurePerl> module.
335
336The programming interface is easy to use: it's the same one found
337in CPAN's L<Digest> module.  So, if your applications currently
338use L<Digest::MD5> and you'd prefer the stronger security of SHA,
339it's a simple matter to convert them.
340
341The interface provides two ways to calculate digests:  all-at-once,
342or in stages.  To illustrate, the following short program computes
343the SHA-256 digest of "hello world" using each approach:
344
345	use Digest::SHA qw(sha256_hex);
346
347	$data = "hello world";
348	@frags = split(//, $data);
349
350	# all-at-once (Functional style)
351	$digest1 = sha256_hex($data);
352
353	# in-stages (OOP style)
354	$state = Digest::SHA->new(256);
355	for (@frags) { $state->add($_) }
356	$digest2 = $state->hexdigest;
357
358	print $digest1 eq $digest2 ?
359		"whew!\n" : "oops!\n";
360
361To calculate the digest of an n-bit message where I<n> is not a
362multiple of 8, use the I<add_bits()> method.  For example, consider
363the 446-bit message consisting of the bit-string "110" repeated
364148 times, followed by "11".  Here's how to display its SHA-1
365digest:
366
367	use Digest::SHA;
368	$bits = "110" x 148 . "11";
369	$sha = Digest::SHA->new(1)->add_bits($bits);
370	print $sha->hexdigest, "\n";
371
372Note that for larger bit-strings, it's more efficient to use the
373two-argument version I<add_bits($data, $nbits)>, where I<$data> is
374in the customary packed binary format used for Perl strings.
375
376The module also lets you save intermediate SHA states to a string.  The
377I<getstate()> method generates portable, human-readable text describing
378the current state of computation.  You can subsequently restore that
379state with I<putstate()> to resume where the calculation left off.
380
381To see what a state description looks like, just run the following:
382
383	use Digest::SHA;
384	print Digest::SHA->new->add("Shaw" x 1962)->getstate;
385
386As an added convenience, the Digest::SHA module offers routines to
387calculate keyed hashes using the HMAC-SHA-1/224/256/384/512
388algorithms.  These services exist in functional form only, and
389mimic the style and behavior of the I<sha()>, I<sha_hex()>, and
390I<sha_base64()> functions.
391
392	# Test vector from draft-ietf-ipsec-ciph-sha-256-01.txt
393
394	use Digest::SHA qw(hmac_sha256_hex);
395	print hmac_sha256_hex("Hi There", chr(0x0b) x 32), "\n";
396
397=head1 UNICODE AND SIDE EFFECTS
398
399Perl supports Unicode strings as of version 5.6.  Such strings may
400contain wide characters, namely, characters whose ordinal values are
401greater than 255.  This can cause problems for digest algorithms such
402as SHA that are specified to operate on sequences of bytes.
403
404The rule by which Digest::SHA handles a Unicode string is easy
405to state, but potentially confusing to grasp: the string is interpreted
406as a sequence of byte values, where each byte value is equal to the
407ordinal value (viz. code point) of its corresponding Unicode character.
408That way, the Unicode string 'abc' has exactly the same digest value as
409the ordinary string 'abc'.
410
411Since a wide character does not fit into a byte, the Digest::SHA
412routines croak if they encounter one.  Whereas if a Unicode string
413contains no wide characters, the module accepts it quite happily.
414The following code illustrates the two cases:
415
416	$str1 = pack('U*', (0..255));
417	print sha1_hex($str1);		# ok
418
419	$str2 = pack('U*', (0..256));
420	print sha1_hex($str2);		# croaks
421
422Be aware that the digest routines silently convert UTF-8 input into its
423equivalent byte sequence in the native encoding (cf. utf8::downgrade).
424This side effect influences only the way Perl stores the data internally,
425but otherwise leaves the actual value of the data intact.
426
427=head1 NIST STATEMENT ON SHA-1
428
429NIST acknowledges that the work of Prof. Xiaoyun Wang constitutes a
430practical collision attack on SHA-1.  Therefore, NIST encourages the
431rapid adoption of the SHA-2 hash functions (e.g. SHA-256) for applications
432requiring strong collision resistance, such as digital signatures.
433
434ref. L<http://csrc.nist.gov/groups/ST/hash/statement.html>
435
436=head1 PADDING OF BASE64 DIGESTS
437
438By convention, CPAN Digest modules do B<not> pad their Base64 output.
439Problems can occur when feeding such digests to other software that
440expects properly padded Base64 encodings.
441
442For the time being, any necessary padding must be done by the user.
443Fortunately, this is a simple operation: if the length of a Base64-encoded
444digest isn't a multiple of 4, simply append "=" characters to the end
445of the digest until it is:
446
447	while (length($b64_digest) % 4) {
448		$b64_digest .= '=';
449	}
450
451To illustrate, I<sha256_base64("abc")> is computed to be
452
453	ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0
454
455which has a length of 43.  So, the properly padded version is
456
457	ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=
458
459=head1 EXPORT
460
461None by default.
462
463=head1 EXPORTABLE FUNCTIONS
464
465Provided your C compiler supports a 64-bit type (e.g. the I<long
466long> of C99, or I<__int64> used by Microsoft C/C++), all of these
467functions will be available for use.  Otherwise, you won't be able
468to perform the SHA-384 and SHA-512 transforms, both of which require
46964-bit operations.
470
471I<Functional style>
472
473=over 4
474
475=item B<sha1($data, ...)>
476
477=item B<sha224($data, ...)>
478
479=item B<sha256($data, ...)>
480
481=item B<sha384($data, ...)>
482
483=item B<sha512($data, ...)>
484
485=item B<sha512224($data, ...)>
486
487=item B<sha512256($data, ...)>
488
489Logically joins the arguments into a single string, and returns
490its SHA-1/224/256/384/512 digest encoded as a binary string.
491
492=item B<sha1_hex($data, ...)>
493
494=item B<sha224_hex($data, ...)>
495
496=item B<sha256_hex($data, ...)>
497
498=item B<sha384_hex($data, ...)>
499
500=item B<sha512_hex($data, ...)>
501
502=item B<sha512224_hex($data, ...)>
503
504=item B<sha512256_hex($data, ...)>
505
506Logically joins the arguments into a single string, and returns
507its SHA-1/224/256/384/512 digest encoded as a hexadecimal string.
508
509=item B<sha1_base64($data, ...)>
510
511=item B<sha224_base64($data, ...)>
512
513=item B<sha256_base64($data, ...)>
514
515=item B<sha384_base64($data, ...)>
516
517=item B<sha512_base64($data, ...)>
518
519=item B<sha512224_base64($data, ...)>
520
521=item B<sha512256_base64($data, ...)>
522
523Logically joins the arguments into a single string, and returns
524its SHA-1/224/256/384/512 digest encoded as a Base64 string.
525
526It's important to note that the resulting string does B<not> contain
527the padding characters typical of Base64 encodings.  This omission is
528deliberate, and is done to maintain compatibility with the family of
529CPAN Digest modules.  See L</"PADDING OF BASE64 DIGESTS"> for details.
530
531=back
532
533I<OOP style>
534
535=over 4
536
537=item B<new($alg)>
538
539Returns a new Digest::SHA object.  Allowed values for I<$alg> are 1,
540224, 256, 384, 512, 512224, or 512256.  It's also possible to use
541common string representations of the algorithm (e.g. "sha256",
542"SHA-384").  If the argument is missing, SHA-1 will be used by
543default.
544
545Invoking I<new> as an instance method will reset the object to the
546initial state associated with I<$alg>.  If the argument is missing,
547the object will continue using the same algorithm that was selected
548at creation.
549
550=item B<reset($alg)>
551
552This method has exactly the same effect as I<new($alg)>.  In fact,
553I<reset> is just an alias for I<new>.
554
555=item B<hashsize>
556
557Returns the number of digest bits for this object.  The values are
558160, 224, 256, 384, 512, 224, and 256 for SHA-1, SHA-224, SHA-256,
559SHA-384, SHA-512, SHA-512/224 and SHA-512/256, respectively.
560
561=item B<algorithm>
562
563Returns the digest algorithm for this object.  The values are 1,
564224, 256, 384, 512, 512224, and 512256 for SHA-1, SHA-224, SHA-256,
565SHA-384, SHA-512, SHA-512/224, and SHA-512/256, respectively.
566
567=item B<clone>
568
569Returns a duplicate copy of the object.
570
571=item B<add($data, ...)>
572
573Logically joins the arguments into a single string, and uses it to
574update the current digest state.  In other words, the following
575statements have the same effect:
576
577	$sha->add("a"); $sha->add("b"); $sha->add("c");
578	$sha->add("a")->add("b")->add("c");
579	$sha->add("a", "b", "c");
580	$sha->add("abc");
581
582The return value is the updated object itself.
583
584=item B<add_bits($data, $nbits)>
585
586=item B<add_bits($bits)>
587
588Updates the current digest state by appending bits to it.  The
589return value is the updated object itself.
590
591The first form causes the most-significant I<$nbits> of I<$data>
592to be appended to the stream.  The I<$data> argument is in the
593customary binary format used for Perl strings.
594
595The second form takes an ASCII string of "0" and "1" characters as
596its argument.  It's equivalent to
597
598	$sha->add_bits(pack("B*", $bits), length($bits));
599
600So, the following two statements do the same thing:
601
602	$sha->add_bits("111100001010");
603	$sha->add_bits("\xF0\xA0", 12);
604
605Note that SHA-1 and SHA-2 use I<most-significant-bit ordering>
606for their internal state.  This means that
607
608	$sha3->add_bits("110");
609
610is equivalent to
611
612	$sha3->add_bits("1")->add_bits("1")->add_bits("0");
613
614=item B<addfile(*FILE)>
615
616Reads from I<FILE> until EOF, and appends that data to the current
617state.  The return value is the updated object itself.
618
619=item B<addfile($filename [, $mode])>
620
621Reads the contents of I<$filename>, and appends that data to the current
622state.  The return value is the updated object itself.
623
624By default, I<$filename> is simply opened and read; no special modes
625or I/O disciplines are used.  To change this, set the optional I<$mode>
626argument to one of the following values:
627
628	"b"	read file in binary mode
629
630	"U"	use universal newlines
631
632	"0"	use BITS mode
633
634The "U" mode is modeled on Python's "Universal Newlines" concept, whereby
635DOS and Mac OS line terminators are converted internally to UNIX newlines
636before processing.  This ensures consistent digest values when working
637simultaneously across multiple file systems.  B<The "U" mode influences
638only text files>, namely those passing Perl's I<-T> test; binary files
639are processed with no translation whatsoever.
640
641The BITS mode ("0") interprets the contents of I<$filename> as a logical
642stream of bits, where each ASCII '0' or '1' character represents a 0 or
6431 bit, respectively.  All other characters are ignored.  This provides
644a convenient way to calculate the digest values of partial-byte data
645by using files, rather than having to write separate programs employing
646the I<add_bits> method.
647
648=item B<getstate>
649
650Returns a string containing a portable, human-readable representation
651of the current SHA state.
652
653=item B<putstate($str)>
654
655Returns a Digest::SHA object representing the SHA state contained
656in I<$str>.  The format of I<$str> matches the format of the output
657produced by method I<getstate>.  If called as a class method, a new
658object is created; if called as an instance method, the object is reset
659to the state contained in I<$str>.
660
661=item B<dump($filename)>
662
663Writes the output of I<getstate> to I<$filename>.  If the argument is
664missing, or equal to the empty string, the state information will be
665written to STDOUT.
666
667=item B<load($filename)>
668
669Returns a Digest::SHA object that results from calling I<putstate> on
670the contents of I<$filename>.  If the argument is missing, or equal to
671the empty string, the state information will be read from STDIN.
672
673=item B<digest>
674
675Returns the digest encoded as a binary string.
676
677Note that the I<digest> method is a read-once operation. Once it
678has been performed, the Digest::SHA object is automatically reset
679in preparation for calculating another digest value.  Call
680I<$sha-E<gt>clone-E<gt>digest> if it's necessary to preserve the
681original digest state.
682
683=item B<hexdigest>
684
685Returns the digest encoded as a hexadecimal string.
686
687Like I<digest>, this method is a read-once operation.  Call
688I<$sha-E<gt>clone-E<gt>hexdigest> if it's necessary to preserve
689the original digest state.
690
691=item B<b64digest>
692
693Returns the digest encoded as a Base64 string.
694
695Like I<digest>, this method is a read-once operation.  Call
696I<$sha-E<gt>clone-E<gt>b64digest> if it's necessary to preserve
697the original digest state.
698
699It's important to note that the resulting string does B<not> contain
700the padding characters typical of Base64 encodings.  This omission is
701deliberate, and is done to maintain compatibility with the family of
702CPAN Digest modules.  See L</"PADDING OF BASE64 DIGESTS"> for details.
703
704=back
705
706I<HMAC-SHA-1/224/256/384/512>
707
708=over 4
709
710=item B<hmac_sha1($data, $key)>
711
712=item B<hmac_sha224($data, $key)>
713
714=item B<hmac_sha256($data, $key)>
715
716=item B<hmac_sha384($data, $key)>
717
718=item B<hmac_sha512($data, $key)>
719
720=item B<hmac_sha512224($data, $key)>
721
722=item B<hmac_sha512256($data, $key)>
723
724Returns the HMAC-SHA-1/224/256/384/512 digest of I<$data>/I<$key>,
725with the result encoded as a binary string.  Multiple I<$data>
726arguments are allowed, provided that I<$key> is the last argument
727in the list.
728
729=item B<hmac_sha1_hex($data, $key)>
730
731=item B<hmac_sha224_hex($data, $key)>
732
733=item B<hmac_sha256_hex($data, $key)>
734
735=item B<hmac_sha384_hex($data, $key)>
736
737=item B<hmac_sha512_hex($data, $key)>
738
739=item B<hmac_sha512224_hex($data, $key)>
740
741=item B<hmac_sha512256_hex($data, $key)>
742
743Returns the HMAC-SHA-1/224/256/384/512 digest of I<$data>/I<$key>,
744with the result encoded as a hexadecimal string.  Multiple I<$data>
745arguments are allowed, provided that I<$key> is the last argument
746in the list.
747
748=item B<hmac_sha1_base64($data, $key)>
749
750=item B<hmac_sha224_base64($data, $key)>
751
752=item B<hmac_sha256_base64($data, $key)>
753
754=item B<hmac_sha384_base64($data, $key)>
755
756=item B<hmac_sha512_base64($data, $key)>
757
758=item B<hmac_sha512224_base64($data, $key)>
759
760=item B<hmac_sha512256_base64($data, $key)>
761
762Returns the HMAC-SHA-1/224/256/384/512 digest of I<$data>/I<$key>,
763with the result encoded as a Base64 string.  Multiple I<$data>
764arguments are allowed, provided that I<$key> is the last argument
765in the list.
766
767It's important to note that the resulting string does B<not> contain
768the padding characters typical of Base64 encodings.  This omission is
769deliberate, and is done to maintain compatibility with the family of
770CPAN Digest modules.  See L</"PADDING OF BASE64 DIGESTS"> for details.
771
772=back
773
774=head1 SEE ALSO
775
776L<Digest>, L<Digest::SHA::PurePerl>
777
778The Secure Hash Standard (Draft FIPS PUB 180-4) can be found at:
779
780L<http://csrc.nist.gov/publications/drafts/fips180-4/Draft-FIPS180-4_Feb2011.pdf>
781
782The Keyed-Hash Message Authentication Code (HMAC):
783
784L<http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf>
785
786=head1 AUTHOR
787
788	Mark Shelor	<mshelor@cpan.org>
789
790=head1 ACKNOWLEDGMENTS
791
792The author is particularly grateful to
793
794	Gisle Aas
795	H. Merijn Brand
796	Sean Burke
797	Chris Carey
798	Alexandr Ciornii
799	Chris David
800	Jim Doble
801	Thomas Drugeon
802	Julius Duque
803	Jeffrey Friedl
804	Robert Gilmour
805	Brian Gladman
806	Jarkko Hietaniemi
807	Adam Kennedy
808	Mark Lawrence
809	Andy Lester
810	Alex Muntada
811	Steve Peters
812	Chris Skiscim
813	Martin Thurn
814	Gunnar Wolf
815	Adam Woodbury
816
817"who by trained skill rescued life from such great billows and such thick
818darkness and moored it in so perfect a calm and in so brilliant a light"
819- Lucretius
820
821=head1 COPYRIGHT AND LICENSE
822
823Copyright (C) 2003-2022 Mark Shelor
824
825This library is free software; you can redistribute it and/or modify
826it under the same terms as Perl itself.
827
828L<perlartistic>
829
830=cut
831