diff options
author | Karl Berry <karl@freefriends.org> | 2016-04-05 22:27:26 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-04-05 22:27:26 +0000 |
commit | b56b320b5e2515160073fa1b469514002688fe11 (patch) | |
tree | 965a7100c5e45fca8ec803d22b8b6ce14fca4633 /Master/tlpkg/tlperl/lib/Digest | |
parent | d26c206452d2e285c3bbf949f34011e4a55fd8f9 (diff) |
tlperl 5.22.1 from siep
git-svn-id: svn://tug.org/texlive/trunk@40252 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Digest')
-rw-r--r-- | Master/tlpkg/tlperl/lib/Digest/MD5.pm | 12 | ||||
-rw-r--r-- | Master/tlpkg/tlperl/lib/Digest/SHA.pm | 192 | ||||
-rw-r--r-- | Master/tlpkg/tlperl/lib/Digest/SHA1.pm | 246 |
3 files changed, 101 insertions, 349 deletions
diff --git a/Master/tlpkg/tlperl/lib/Digest/MD5.pm b/Master/tlpkg/tlperl/lib/Digest/MD5.pm index 679036f8be7..bb92ddb44a9 100644 --- a/Master/tlpkg/tlperl/lib/Digest/MD5.pm +++ b/Master/tlpkg/tlperl/lib/Digest/MD5.pm @@ -3,7 +3,7 @@ package Digest::MD5; use strict; use vars qw($VERSION @ISA @EXPORT_OK); -$VERSION = '2.53'; +$VERSION = '2.54'; require Exporter; *import = \&Exporter::import; @@ -227,6 +227,16 @@ The base64 encoded string returned is not padded to be a multiple of 4 bytes long. If you want interoperability with other base64 encoded md5 digests you might want to append the string "==" to the result. +=item @ctx = $md5->context + +=item $md5->context(@ctx) + +Saves or restores the internal state. When called with no arguments, +returns a 3-element list: number of blocks processed, a 16-byte +internal state buffer, then up to 63 bytes of unprocessed data. When +passed those same arguments, restores the state. This is only useful +for specialised operations. + =back diff --git a/Master/tlpkg/tlperl/lib/Digest/SHA.pm b/Master/tlpkg/tlperl/lib/Digest/SHA.pm index 57f0bd6ef6f..3abca3d32c1 100644 --- a/Master/tlpkg/tlperl/lib/Digest/SHA.pm +++ b/Master/tlpkg/tlperl/lib/Digest/SHA.pm @@ -3,11 +3,12 @@ package Digest::SHA; require 5.003000; use strict; +use warnings; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Fcntl; use integer; -$VERSION = '5.88'; +$VERSION = '5.95'; require Exporter; require DynaLoader; @@ -28,52 +29,30 @@ require DynaLoader; sha512224 sha512224_base64 sha512224_hex sha512256 sha512256_base64 sha512256_hex); -# If possible, inherit from Digest::base +# Inherit from Digest::base if possible eval { require Digest::base; push(@ISA, 'Digest::base'); }; -*addfile = \&Addfile; -*hexdigest = \&Hexdigest; -*b64digest = \&B64digest; - # The following routines aren't time-critical, so they can be left in Perl sub new { my($class, $alg) = @_; $alg =~ s/\D+//g if defined $alg; if (ref($class)) { # instance method - unless (defined($alg) && ($alg != $class->algorithm)) { - sharewind($$class); + if (!defined($alg) || ($alg == $class->algorithm)) { + sharewind($class); return($class); } - if ($$class) { shaclose($$class); $$class = undef } - return unless $$class = shaopen($alg); - return($class); + return shainit($class, $alg) ? $class : undef; } $alg = 1 unless defined $alg; - my $state = shaopen($alg) || return; - my $self = \$state; - bless($self, $class); - return($self); -} - -sub DESTROY { - my $self = shift; - if ($$self) { shaclose($$self); $$self = undef } -} - -sub clone { - my $self = shift; - my $state = shadup($$self) || return; - my $copy = \$state; - bless($copy, ref($self)); - return($copy); + return $class->newSHA($alg); } -*reset = \&new; +BEGIN { *reset = \&new } sub add_bits { my($self, $data, $nbits) = @_; @@ -82,7 +61,7 @@ sub add_bits { $data = pack("B*", $data); } $nbits = length($data) * 8 if $nbits > length($data) * 8; - shawrite($data, $nbits, $$self); + shawrite($data, $nbits, $self); return($self); } @@ -90,48 +69,53 @@ sub _bail { my $msg = shift; $msg .= ": $!"; - require Carp; - Carp::croak($msg); + require Carp; + Carp::croak($msg); } -sub _addfile { # this is "addfile" from Digest::base 1.00 - my ($self, $handle) = @_; +{ + my $_can_T_filehandle; - my $n; - my $buf = ""; + sub _istext { + local *FH = shift; + my $file = shift; - while (($n = read($handle, $buf, 4096))) { - $self->add($buf); - } - _bail("Read failed") unless defined $n; - - $self; + if (! defined $_can_T_filehandle) { + local $^W = 0; + my $istext = eval { -T FH }; + $_can_T_filehandle = $@ ? 0 : 1; + return $_can_T_filehandle ? $istext : -T $file; + } + return $_can_T_filehandle ? -T FH : -T $file; + } } -my $_can_T_filehandle; +sub _addfile { + my ($self, $handle) = @_; -sub _istext { - local *FH = shift; - my $file = shift; + my $n; + my $buf = ""; - if (! defined $_can_T_filehandle) { - local $^W = 0; - eval { -T FH }; - $_can_T_filehandle = $@ ? 0 : 1; + while (($n = read($handle, $buf, 4096))) { + $self->add($buf); } - return $_can_T_filehandle ? -T FH : -T $file; + _bail("Read failed") unless defined $n; + + $self; } -sub Addfile { +sub addfile { my ($self, $file, $mode) = @_; return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR'; $mode = defined($mode) ? $mode : ""; - my ($binary, $portable, $BITS) = map { $_ eq $mode } ("b", "p", "0"); + my ($binary, $UNIVERSAL, $BITS, $portable) = + map { $_ eq $mode } ("b", "U", "0", "p"); ## Always interpret "-" to mean STDIN; otherwise use ## sysopen to handle full range of POSIX file names + local *FH; $file eq '-' and open(FH, '< -') or sysopen(FH, $file, O_RDONLY) @@ -148,18 +132,18 @@ sub Addfile { return($self); } - binmode(FH) if $binary || $portable; - unless ($portable && _istext(*FH, $file)) { - $self->_addfile(*FH); - close(FH); - return($self); + binmode(FH) if $binary || $portable || $UNIVERSAL; + if ($UNIVERSAL && _istext(*FH, $file)) { + $self->_addfileuniv(*FH); } - - while (<FH>) { - s/\015?\015\012/\012/g; # DOS/Windows - s/\015/\012/g; # early MacOS - $self->add($_); + elsif ($portable && _istext(*FH, $file)) { + while (<FH>) { + s/\015?\015\012/\012/g; + s/\015/\012/g; + $self->add($_); + } } + else { $self->_addfilebin(*FH) } close(FH); $self; @@ -192,8 +176,7 @@ sub getstate { } sub putstate { - my $class = shift; - my $state = shift; + my($class, $state) = @_; my %s = (); for (split(/\n/, $state)) { @@ -218,27 +201,17 @@ sub putstate { $s{'blockcnt'} < ($s{'alg'} <= 256 ? 512 : 1024) or return; } - my $state_packed = ( + my $packed_state = ( pack("H*", $s{'H'}) . pack("H*", $s{'block'}) . - pack("N", $s{'blockcnt'}) . - pack("N", $s{'lenhh'}) . - pack("N", $s{'lenhl'}) . - pack("N", $s{'lenlh'}) . - pack("N", $s{'lenll'}) + pack("N", $s{'blockcnt'}) . + pack("N", $s{'lenhh'}) . + pack("N", $s{'lenhl'}) . + pack("N", $s{'lenlh'}) . + pack("N", $s{'lenll'}) ); - if (ref($class)) { # instance method - if ($$class) { shaclose($$class); $$class = undef } - return unless $$class = shaopen($s{'alg'}); - return $class->_putstate($state_packed); - } - else { - my $sha = shaopen($s{'alg'}) or return; - my $self = \$sha; - bless($self, $class); - return $self->_putstate($state_packed); - } + return $class->new($s{'alg'})->_putstate($packed_state); } sub dump { @@ -555,10 +528,10 @@ common string representations of the algorithm (e.g. "sha256", "SHA-384"). If the argument is missing, SHA-1 will be used by default. -Invoking I<new> as an instance method will not create a new object; -instead, it will simply reset the object to the initial state -associated with I<$alg>. If the argument is missing, the object -will continue using the same algorithm that was selected at creation. +Invoking I<new> as an instance method will reset the object to the +initial state associated with I<$alg>. If the argument is missing, +the object will continue using the same algorithm that was selected +at creation. =item B<reset($alg)> @@ -615,6 +588,15 @@ So, the following two statements do the same thing: $sha->add_bits("111100001010"); $sha->add_bits("\xF0\xA0", 12); +Note that SHA-1 and SHA-2 use I<most-significant-bit ordering> +for their internal state. This means that + + $sha3->add_bits("110"); + +is equivalent to + + $sha3->add_bits("1")->add_bits("1")->add_bits("0"); + =item B<addfile(*FILE)> Reads from I<FILE> until EOF, and appends that data to the current @@ -631,22 +613,31 @@ argument to one of the following values: "b" read file in binary mode - "p" use portable mode + "U" use universal newlines "0" use BITS mode -The "p" mode ensures that the digest value of I<$filename> will be the -same when computed on different operating systems. It accomplishes -this by internally translating all newlines in text files to UNIX format -before calculating the digest. Binary files are read in raw mode with -no translation whatsoever. + "p" use portable mode (to be deprecated) + +The "U" mode is modeled on Python's "Universal Newlines" concept, whereby +DOS and Mac OS line terminators are converted internally to UNIX newlines +before processing. This ensures consistent digest values when working +simultaneously across multiple file systems. B<The "U" mode influences +only text files>, namely those passing Perl's I<-T> test; binary files +are processed with no translation whatsoever. + +The "p" mode differs from "U" only in that it treats "\r\r\n" as a single +newline, a quirky feature designed to accommodate legacy applications that +occasionally added an extra carriage return before DOS line terminators. +The "p" mode will be phased out eventually in favor of the cleaner and +more well-established Universal Newlines concept. The BITS mode ("0") interprets the contents of I<$filename> as a logical stream of bits, where each ASCII '0' or '1' character represents a 0 or 1 bit, respectively. All other characters are ignored. This provides -a convenient way to calculate the digest values of partial-byte data by -using files, rather than having to write programs using the I<add_bits> -method. +a convenient way to calculate the digest values of partial-byte data +by using files, rather than having to write separate programs employing +the I<add_bits> method. =item B<getstate> @@ -691,9 +682,6 @@ Like I<digest>, this method is a read-once operation. Call I<$sha-E<gt>clone-E<gt>hexdigest> if it's necessary to preserve the original digest state. -This method is inherited if L<Digest::base> is installed on your -system. Otherwise, a functionally equivalent substitute is used. - =item B<b64digest> Returns the digest encoded as a Base64 string. @@ -702,9 +690,6 @@ Like I<digest>, this method is a read-once operation. Call I<$sha-E<gt>clone-E<gt>b64digest> if it's necessary to preserve the original digest state. -This method is inherited if L<Digest::base> is installed on your -system. Otherwise, a functionally equivalent substitute is used. - It's important to note that the resulting string does B<not> contain the padding characters typical of Base64 encodings. This omission is deliberate, and is done to maintain compatibility with the family of @@ -801,6 +786,7 @@ L<http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf> The author is particularly grateful to Gisle Aas + H. Merijn Brand Sean Burke Chris Carey Alexandr Ciornii @@ -810,7 +796,9 @@ The author is particularly grateful to Jeffrey Friedl Robert Gilmour Brian Gladman + Jarkko Hietaniemi Adam Kennedy + Mark Lawrence Andy Lester Alex Muntada Steve Peters @@ -825,7 +813,7 @@ darkness and moored it in so perfect a calm and in so brilliant a light" =head1 COPYRIGHT AND LICENSE -Copyright (C) 2003-2014 Mark Shelor +Copyright (C) 2003-2015 Mark Shelor This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/Master/tlpkg/tlperl/lib/Digest/SHA1.pm b/Master/tlpkg/tlperl/lib/Digest/SHA1.pm deleted file mode 100644 index bd2647a1de3..00000000000 --- a/Master/tlpkg/tlperl/lib/Digest/SHA1.pm +++ /dev/null @@ -1,246 +0,0 @@ -package Digest::SHA1; - -use strict; -use vars qw($VERSION @ISA @EXPORT_OK); - -$VERSION = '2.13'; - -require Exporter; -*import = \&Exporter::import; -@EXPORT_OK = qw(sha1 sha1_hex sha1_base64 sha1_transform); - -require DynaLoader; -@ISA=qw(DynaLoader); - -eval { - require Digest::base; - push(@ISA, 'Digest::base'); -}; -if ($@) { - my $err = $@; - *add_bits = sub { die $err }; -} - -Digest::SHA1->bootstrap($VERSION); - -1; -__END__ - -=head1 NAME - -Digest::SHA1 - Perl interface to the SHA-1 algorithm - -=head1 SYNOPSIS - - # Functional style - use Digest::SHA1 qw(sha1 sha1_hex sha1_base64); - - $digest = sha1($data); - $digest = sha1_hex($data); - $digest = sha1_base64($data); - $digest = sha1_transform($data); - - - # OO style - use Digest::SHA1; - - $sha1 = Digest::SHA1->new; - - $sha1->add($data); - $sha1->addfile(*FILE); - - $sha1_copy = $sha1->clone; - - $digest = $sha1->digest; - $digest = $sha1->hexdigest; - $digest = $sha1->b64digest; - $digest = $sha1->transform; - -=head1 DESCRIPTION - -The C<Digest::SHA1> module allows you to use the NIST SHA-1 message -digest algorithm from within Perl programs. The algorithm takes as -input a message of arbitrary length and produces as output a 160-bit -"fingerprint" or "message digest" of the input. - -In 2005, security flaws were identified in SHA-1, namely that a possible -mathematical weakness might exist, indicating that a stronger hash function -would be desirable. The L<Digest::SHA> module implements the stronger -algorithms in the SHA family. - -The C<Digest::SHA1> module provide a procedural interface for simple -use, as well as an object oriented interface that can handle messages -of arbitrary length and which can read files directly. - -=head1 FUNCTIONS - -The following functions can be exported from the C<Digest::SHA1> -module. No functions are exported by default. - -=over 4 - -=item sha1($data,...) - -This function will concatenate all arguments, calculate the SHA-1 -digest of this "message", and return it in binary form. The returned -string will be 20 bytes long. - -The result of sha1("a", "b", "c") will be exactly the same as the -result of sha1("abc"). - -=item sha1_hex($data,...) - -Same as sha1(), but will return the digest in hexadecimal form. The -length of the returned string will be 40 and it will only contain -characters from this set: '0'..'9' and 'a'..'f'. - -=item sha1_base64($data,...) - -Same as sha1(), but will return the digest as a base64 encoded string. -The length of the returned string will be 27 and it will only contain -characters from this set: 'A'..'Z', 'a'..'z', '0'..'9', '+' and -'/'. - -Note that the base64 encoded string returned is not padded to be a -multiple of 4 bytes long. If you want interoperability with other -base64 encoded sha1 digests you might want to append the redundant -string "=" to the result. - -=item sha1_transform($data) - -Implements the basic SHA1 transform on a 64 byte block. The $data -argument and the returned $digest are in binary form. This algorithm -is used in NIST FIPS 186-2 - -=back - -=head1 METHODS - -The object oriented interface to C<Digest::SHA1> is described in this -section. After a C<Digest::SHA1> object has been created, you will add -data to it and finally ask for the digest in a suitable format. A -single object can be used to calculate multiple digests. - -The following methods are provided: - -=over 4 - -=item $sha1 = Digest::SHA1->new - -The constructor returns a new C<Digest::SHA1> object which encapsulate -the state of the SHA-1 message-digest algorithm. - -If called as an instance method (i.e. $sha1->new) it will just reset the -state the object to the state of a newly created object. No new -object is created in this case. - -=item $sha1->reset - -This is just an alias for $sha1->new. - -=item $sha1->clone - -This a copy of the $sha1 object. It is useful when you do not want to -destroy the digests state, but need an intermediate value of the -digest, e.g. when calculating digests iteratively on a continuous data -stream. Example: - - my $sha1 = Digest::SHA1->new; - while (<>) { - $sha1->add($_); - print "Line $.: ", $sha1->clone->hexdigest, "\n"; - } - -=item $sha1->add($data,...) - -The $data provided as argument are appended to the message we -calculate the digest for. The return value is the $sha1 object itself. - -All these lines will have the same effect on the state of the $sha1 -object: - - $sha1->add("a"); $sha1->add("b"); $sha1->add("c"); - $sha1->add("a")->add("b")->add("c"); - $sha1->add("a", "b", "c"); - $sha1->add("abc"); - -=item $sha1->addfile($io_handle) - -The $io_handle will be read until EOF and its content appended to the -message we calculate the digest for. The return value is the $sha1 -object itself. - -The addfile() method will croak() if it fails reading data for some -reason. If it croaks it is unpredictable what the state of the $sha1 -object will be in. The addfile() method might have been able to read -the file partially before it failed. It is probably wise to discard -or reset the $sha1 object if this occurs. - -In most cases you want to make sure that the $io_handle is in -C<binmode> before you pass it as argument to the addfile() method. - -=item $sha1->add_bits($data, $nbits) - -=item $sha1->add_bits($bitstring) - -This implementation of SHA-1 only supports byte oriented input so you -might only add bits as multiples of 8. If you need bit level support -please consider using the C<Digest::SHA> module instead. The -add_bits() method is provided here for compatibility with other digest -implementations. See L<Digest> for description of the arguments that -add_bits() take. - -=item $sha1->digest - -Return the binary digest for the message. The returned string will be -20 bytes long. - -Note that the C<digest> operation is effectively a destructive, -read-once operation. Once it has been performed, the C<Digest::SHA1> -object is automatically C<reset> and can be used to calculate another -digest value. Call $sha1->clone->digest if you want to calculate the -digest without reseting the digest state. - -=item $sha1->hexdigest - -Same as $sha1->digest, but will return the digest in hexadecimal -form. The length of the returned string will be 40 and it will only -contain characters from this set: '0'..'9' and 'a'..'f'. - -=item $sha1->b64digest - -Same as $sha1->digest, but will return the digest as a base64 encoded -string. The length of the returned string will be 27 and it will only -contain characters from this set: 'A'..'Z', 'a'..'z', '0'..'9', '+' -and '/'. - - -The base64 encoded string returned is not padded to be a multiple of 4 -bytes long. If you want interoperability with other base64 encoded -SHA-1 digests you might want to append the string "=" to the result. - -=back - -=head1 SEE ALSO - -L<Digest>, L<Digest::HMAC_SHA1>, L<Digest::SHA>, L<Digest::MD5> - -http://www.itl.nist.gov/fipspubs/fip180-1.htm - -http://en.wikipedia.org/wiki/SHA_hash_functions - -=head1 COPYRIGHT - -This library is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - Copyright 1999-2004 Gisle Aas. - Copyright 1997 Uwe Hollerbach. - -=head1 AUTHORS - -Peter C. Gutmann, -Uwe Hollerbach <uh@alumni.caltech.edu>, -Gisle Aas <gisle@aas.no> - -=cut |