golden hour
/usr/share/perl/5.30.0
⬆️ Go Up
Upload
File/Folder
Size
Actions
AnyDBM_File.pm
2.56 KB
Del
OK
App
-
Del
OK
Archive
-
Del
OK
Attribute
-
Del
OK
AutoLoader.pm
15.43 KB
Del
OK
AutoSplit.pm
19.18 KB
Del
OK
B
-
Del
OK
Benchmark.pm
30.3 KB
Del
OK
CORE.pod
3.11 KB
Del
OK
CPAN
-
Del
OK
CPAN.pm
138.75 KB
Del
OK
Carp
-
Del
OK
Carp.pm
35.12 KB
Del
OK
Class
-
Del
OK
Compress
-
Del
OK
Config
-
Del
OK
DB.pm
18.48 KB
Del
OK
DBM_Filter
-
Del
OK
DBM_Filter.pm
14.05 KB
Del
OK
Devel
-
Del
OK
Digest
-
Del
OK
Digest.pm
10.45 KB
Del
OK
DirHandle.pm
2.04 KB
Del
OK
Dumpvalue.pm
17.14 KB
Del
OK
Encode
-
Del
OK
English.pm
4.65 KB
Del
OK
Env.pm
5.39 KB
Del
OK
Exporter
-
Del
OK
Exporter.pm
18.36 KB
Del
OK
ExtUtils
-
Del
OK
Fatal.pm
56.91 KB
Del
OK
File
-
Del
OK
FileCache.pm
5.42 KB
Del
OK
FileHandle.pm
6.63 KB
Del
OK
Filter
-
Del
OK
FindBin.pm
4.45 KB
Del
OK
Getopt
-
Del
OK
HTTP
-
Del
OK
I18N
-
Del
OK
IO
-
Del
OK
IPC
-
Del
OK
Internals.pod
2.51 KB
Del
OK
JSON
-
Del
OK
Locale
-
Del
OK
Math
-
Del
OK
Memoize
-
Del
OK
Memoize.pm
35.34 KB
Del
OK
Module
-
Del
OK
NEXT.pm
18.54 KB
Del
OK
Net
-
Del
OK
Params
-
Del
OK
Parse
-
Del
OK
Perl
-
Del
OK
PerlIO
-
Del
OK
PerlIO.pm
10.21 KB
Del
OK
Pod
-
Del
OK
Safe.pm
24.49 KB
Del
OK
Search
-
Del
OK
SelectSaver.pm
1.05 KB
Del
OK
SelfLoader.pm
17.27 KB
Del
OK
Symbol.pm
4.69 KB
Del
OK
TAP
-
Del
OK
Term
-
Del
OK
Test
-
Del
OK
Test.pm
29.34 KB
Del
OK
Test2
-
Del
OK
Test2.pm
6.24 KB
Del
OK
Text
-
Del
OK
Thread
-
Del
OK
Thread.pm
8.09 KB
Del
OK
Tie
-
Del
OK
Time
-
Del
OK
UNIVERSAL.pm
6.44 KB
Del
OK
Unicode
-
Del
OK
User
-
Del
OK
XSLoader.pm
10.99 KB
Del
OK
_charnames.pm
32.39 KB
Del
OK
autodie
-
Del
OK
autodie.pm
12.58 KB
Del
OK
autouse.pm
4.14 KB
Del
OK
base.pm
10.7 KB
Del
OK
bigint.pm
22.85 KB
Del
OK
bignum.pm
20.64 KB
Del
OK
bigrat.pm
15.78 KB
Del
OK
blib.pm
2.01 KB
Del
OK
bytes.pm
3.65 KB
Del
OK
bytes_heavy.pl
758 B
Del
OK
charnames.pm
20.38 KB
Del
OK
constant.pm
14.38 KB
Del
OK
deprecate.pm
5.07 KB
Del
OK
diagnostics.pm
18.59 KB
Del
OK
dumpvar.pl
15.19 KB
Del
OK
encoding
-
Del
OK
experimental.pm
6.9 KB
Del
OK
feature.pm
17.28 KB
Del
OK
fields.pm
9.25 KB
Del
OK
filetest.pm
3.91 KB
Del
OK
if.pm
3.53 KB
Del
OK
integer.pm
3.18 KB
Del
OK
less.pm
3.13 KB
Del
OK
locale.pm
4.74 KB
Del
OK
meta_notation.pm
2.07 KB
Del
OK
ok.pm
967 B
Del
OK
open.pm
7.83 KB
Del
OK
overload
-
Del
OK
overload.pm
52.04 KB
Del
OK
overloading.pm
1.77 KB
Del
OK
parent.pm
2.51 KB
Del
OK
perl5db.pl
309.69 KB
Del
OK
perlfaq.pm
77 B
Del
OK
pod
-
Del
OK
sigtrap.pm
8.53 KB
Del
OK
sort.pm
3.82 KB
Del
OK
strict.pm
4.63 KB
Del
OK
subs.pm
901 B
Del
OK
unicore
-
Del
OK
utf8.pm
10.18 KB
Del
OK
utf8_heavy.pl
26.66 KB
Del
OK
vars.pm
2.4 KB
Del
OK
version
-
Del
OK
version.pm
1.93 KB
Del
OK
version.pod
9.6 KB
Del
OK
vmsish.pm
4.21 KB
Del
OK
warnings
-
Del
OK
warnings.pm
48.82 KB
Del
OK
Edit: Digest.pm
package Digest; use strict; use vars qw($VERSION %MMAP $AUTOLOAD); $VERSION = "1.17_01"; %MMAP = ( "SHA-1" => [["Digest::SHA", 1], "Digest::SHA1", ["Digest::SHA2", 1]], "SHA-224" => [["Digest::SHA", 224]], "SHA-256" => [["Digest::SHA", 256], ["Digest::SHA2", 256]], "SHA-384" => [["Digest::SHA", 384], ["Digest::SHA2", 384]], "SHA-512" => [["Digest::SHA", 512], ["Digest::SHA2", 512]], "HMAC-MD5" => "Digest::HMAC_MD5", "HMAC-SHA-1" => "Digest::HMAC_SHA1", "CRC-16" => [["Digest::CRC", type => "crc16"]], "CRC-32" => [["Digest::CRC", type => "crc32"]], "CRC-CCITT" => [["Digest::CRC", type => "crcccitt"]], "RIPEMD-160" => "Crypt::RIPEMD160", ); sub new { shift; # class ignored my $algorithm = shift; my $impl = $MMAP{$algorithm} || do { $algorithm =~ s/\W+//g; "Digest::$algorithm"; }; $impl = [$impl] unless ref($impl); local $@; # don't clobber it for our caller my $err; for (@$impl) { my $class = $_; my @args; ($class, @args) = @$class if ref($class); no strict 'refs'; unless (exists ${"$class\::"}{"VERSION"}) { my $pm_file = $class . ".pm"; $pm_file =~ s{::}{/}g; eval { local @INC = @INC; pop @INC if $INC[-1] eq '.'; require $pm_file }; if ($@) { $err ||= $@; next; } } return $class->new(@args, @_); } die $err; } sub AUTOLOAD { my $class = shift; my $algorithm = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); $class->new($algorithm, @_); } 1; __END__ =head1 NAME Digest - Modules that calculate message digests =head1 SYNOPSIS $md5 = Digest->new("MD5"); $sha1 = Digest->new("SHA-1"); $sha256 = Digest->new("SHA-256"); $sha384 = Digest->new("SHA-384"); $sha512 = Digest->new("SHA-512"); $hmac = Digest->HMAC_MD5($key); =head1 DESCRIPTION The C<Digest::> modules calculate digests, also called "fingerprints" or "hashes", of some data, called a message. The digest is (usually) some small/fixed size string. The actual size of the digest depend of the algorithm used. The message is simply a sequence of arbitrary bytes or bits. An important property of the digest algorithms is that the digest is I<likely> to change if the message change in some way. Another property is that digest functions are one-way functions, that is it should be I<hard> to find a message that correspond to some given digest. Algorithms differ in how "likely" and how "hard", as well as how efficient they are to compute. Note that the properties of the algorithms change over time, as the algorithms are analyzed and machines grow faster. If your application for instance depends on it being "impossible" to generate the same digest for a different message it is wise to make it easy to plug in stronger algorithms as the one used grow weaker. Using the interface documented here should make it easy to change algorithms later. All C<Digest::> modules provide the same programming interface. A functional interface for simple use, as well as an object oriented interface that can handle messages of arbitrary length and which can read files directly. The digest can be delivered in three formats: =over 8 =item I<binary> This is the most compact form, but it is not well suited for printing or embedding in places that can't handle arbitrary data. =item I<hex> A twice as long string of lowercase hexadecimal digits. =item I<base64> A string of portable printable characters. This is the base64 encoded representation of the digest with any trailing padding removed. The string will be about 30% longer than the binary version. L<MIME::Base64> tells you more about this encoding. =back The functional interface is simply importable functions with the same name as the algorithm. The functions take the message as argument and return the digest. Example: use Digest::MD5 qw(md5); $digest = md5($message); There are also versions of the functions with "_hex" or "_base64" appended to the name, which returns the digest in the indicated form. =head1 OO INTERFACE The following methods are available for all C<Digest::> modules: =over 4 =item $ctx = Digest->XXX($arg,...) =item $ctx = Digest->new(XXX => $arg,...) =item $ctx = Digest::XXX->new($arg,...) The constructor returns some object that encapsulate the state of the message-digest algorithm. You can add data to the object and finally ask for the digest. The "XXX" should of course be replaced by the proper name of the digest algorithm you want to use. The two first forms are simply syntactic sugar which automatically load the right module on first use. The second form allow you to use algorithm names which contains letters which are not legal perl identifiers, e.g. "SHA-1". If no implementation for the given algorithm can be found, then an exception is raised. If new() is called as an instance method (i.e. $ctx->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, and the return value is the reference to the object (i.e. $ctx). =item $other_ctx = $ctx->clone The clone method creates a copy of the digest state object and returns a reference to the copy. =item $ctx->reset This is just an alias for $ctx->new. =item $ctx->add( $data ) =item $ctx->add( $chunk1, $chunk2, ... ) The string value of the $data provided as argument is appended to the message we calculate the digest for. The return value is the $ctx object itself. If more arguments are provided then they are all appended to the message, thus all these lines will have the same effect on the state of the $ctx object: $ctx->add("a"); $ctx->add("b"); $ctx->add("c"); $ctx->add("a")->add("b")->add("c"); $ctx->add("a", "b", "c"); $ctx->add("abc"); Most algorithms are only defined for strings of bytes and this method might therefore croak if the provided arguments contain chars with ordinal number above 255. =item $ctx->addfile( $io_handle ) The $io_handle is read until EOF and the content is appended to the message we calculate the digest for. The return value is the $ctx 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 $ctx 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 $ctx object if this occurs. In most cases you want to make sure that the $io_handle is in "binmode" before you pass it as argument to the addfile() method. =item $ctx->add_bits( $data, $nbits ) =item $ctx->add_bits( $bitstring ) The add_bits() method is an alternative to add() that allow partial bytes to be appended to the message. Most users should just ignore this method as partial bytes is very unlikely to be of any practical use. The two argument form of add_bits() will add the first $nbits bits from $data. For the last potentially partial byte only the high order C<< $nbits % 8 >> bits are used. If $nbits is greater than C<< length($data) * 8 >>, then this method would do the same as C<< $ctx->add($data) >>. The one argument form of add_bits() takes a $bitstring of "1" and "0" chars as argument. It's a shorthand for C<< $ctx->add_bits(pack("B*", $bitstring), length($bitstring)) >>. The return value is the $ctx object itself. This example shows two calls that should have the same effect: $ctx->add_bits("111100001010"); $ctx->add_bits("\xF0\xA0", 12); Most digest algorithms are byte based and for these it is not possible to add bits that are not a multiple of 8, and the add_bits() method will croak if you try. =item $ctx->digest Return the binary digest for the message. Note that the C<digest> operation is effectively a destructive, read-once operation. Once it has been performed, the $ctx object is automatically C<reset> and can be used to calculate another digest value. Call $ctx->clone->digest if you want to calculate the digest without resetting the digest state. =item $ctx->hexdigest Same as $ctx->digest, but will return the digest in hexadecimal form. =item $ctx->b64digest Same as $ctx->digest, but will return the digest as a base64 encoded string. =back =head1 Digest speed This table should give some indication on the relative speed of different algorithms. It is sorted by throughput based on a benchmark done with of some implementations of this API: Algorithm Size Implementation MB/s MD4 128 Digest::MD4 v1.3 165.0 MD5 128 Digest::MD5 v2.33 98.8 SHA-256 256 Digest::SHA2 v1.1.0 66.7 SHA-1 160 Digest::SHA v4.3.1 58.9 SHA-1 160 Digest::SHA1 v2.10 48.8 SHA-256 256 Digest::SHA v4.3.1 41.3 Haval-256 256 Digest::Haval256 v1.0.4 39.8 SHA-384 384 Digest::SHA2 v1.1.0 19.6 SHA-512 512 Digest::SHA2 v1.1.0 19.3 SHA-384 384 Digest::SHA v4.3.1 19.2 SHA-512 512 Digest::SHA v4.3.1 19.2 Whirlpool 512 Digest::Whirlpool v1.0.2 13.0 MD2 128 Digest::MD2 v2.03 9.5 Adler-32 32 Digest::Adler32 v0.03 1.3 CRC-16 16 Digest::CRC v0.05 1.1 CRC-32 32 Digest::CRC v0.05 1.1 MD5 128 Digest::Perl::MD5 v1.5 1.0 CRC-CCITT 16 Digest::CRC v0.05 0.8 These numbers was achieved Apr 2004 with ActivePerl-5.8.3 running under Linux on a P4 2.8 GHz CPU. The last 5 entries differ by being pure perl implementations of the algorithms, which explains why they are so slow. =head1 SEE ALSO L<Digest::Adler32>, L<Digest::CRC>, L<Digest::Haval256>, L<Digest::HMAC>, L<Digest::MD2>, L<Digest::MD4>, L<Digest::MD5>, L<Digest::SHA>, L<Digest::SHA1>, L<Digest::SHA2>, L<Digest::Whirlpool> New digest implementations should consider subclassing from L<Digest::base>. L<MIME::Base64> http://en.wikipedia.org/wiki/Cryptographic_hash_function =head1 AUTHOR Gisle Aas <gisle@aas.no> The C<Digest::> interface is based on the interface originally developed by Neil Winton for his C<MD5> module. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright 1998-2006 Gisle Aas. Copyright 1995,1996 Neil Winton. =cut
Save