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