Imported Upstream version 2.13
This commit is contained in:
commit
eef453dcd9
587
Changes
Normal file
587
Changes
Normal file
@ -0,0 +1,587 @@
|
||||
2010-07-03 Release 2.13
|
||||
|
||||
Mike McCauley (1):
|
||||
Fix memory leak in sha1_transform
|
||||
|
||||
|
||||
|
||||
2009-05-23 Release 2.12
|
||||
|
||||
Gisle Aas (6):
|
||||
Get rid of the old CVS ids
|
||||
Avoid "redefined" error for ULONG on Win64
|
||||
Less optimizations on IRIX [RT#8999]
|
||||
Clean up the 'git status' output
|
||||
Mention that SHA-1 might be weak [RT#11880]
|
||||
Ensure more stuff in the META.yml file [RT#40757]
|
||||
|
||||
Steve Peters (1):
|
||||
Quiet warnings when compiled with -Wwrite-strings [RT#31915]
|
||||
|
||||
|
||||
|
||||
2006-01-18 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.11
|
||||
|
||||
Internal cleanup to avoid some compiler warnings.
|
||||
|
||||
|
||||
|
||||
2004-04-05 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.10
|
||||
|
||||
Restore compatibility with perl-5.004 and perl-5.005.
|
||||
|
||||
|
||||
|
||||
2004-04-01 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.09
|
||||
|
||||
The 2.08 release did not compile with a threaded debugging
|
||||
perl, because assert() then needs my_perl. Fixed by commenting
|
||||
out the asserts.
|
||||
|
||||
|
||||
|
||||
2004-04-01 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.08
|
||||
|
||||
Enable PERL_NO_GET_CONTEXT for more more efficient execution
|
||||
on a threaded perl.
|
||||
|
||||
Fix up md5 references. Patch by Ville Skyttä <ville.skytta@iki.fi>.
|
||||
|
||||
|
||||
|
||||
2003-12-05 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.07
|
||||
|
||||
Inherit add_bits() from Digest::base if available.
|
||||
|
||||
|
||||
|
||||
2003-10-13 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.06
|
||||
|
||||
The sha1_transform() function did not check that it was actually
|
||||
passed any arguments.
|
||||
|
||||
Complete self-contained documentation included (copied from
|
||||
Digest::MD5), since the Digest.pm manpage is not always available.
|
||||
|
||||
|
||||
|
||||
2003-10-06 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.05
|
||||
|
||||
Added missing cast to support C++ compilation. Patch by Jan Dubois.
|
||||
|
||||
Document that the sha1_base64 function and the b64digest method
|
||||
does not pad their result.
|
||||
|
||||
|
||||
|
||||
2003-07-22 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.04
|
||||
|
||||
Don't assume PerlIO_read() works like fread() even though
|
||||
it was documented like that for perl 5.6. It returns negative
|
||||
on read failure.
|
||||
|
||||
Kill test #3 in t/badfile.t. I don't know a reliable way
|
||||
to test read failures on a file handle. Seems better not to
|
||||
test than to make many worry.
|
||||
|
||||
|
||||
|
||||
2003-07-05 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.03
|
||||
|
||||
Implemented sha1_transform, required to implement NIST FIPS 186-2.
|
||||
Contributed by Mike McCauley <mikem@open.com.au>.
|
||||
|
||||
Make it build on 64-bit platforms with 32-bit longs. At least
|
||||
I hope it will.
|
||||
|
||||
Sync up with the Digest::MD5 implementation:
|
||||
- added clone method
|
||||
- addfile croaks if it can't read
|
||||
- the sha1*() functions warn if called as method
|
||||
or with reference arguments.
|
||||
|
||||
|
||||
|
||||
2002-12-27 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.02
|
||||
|
||||
Make it work when there is a mismatch between the
|
||||
sizeof(BYTEORDER) and sizeof(long). Based on patch
|
||||
by Allen Smith <easmith@beatrice.rutgers.edu>.
|
||||
|
||||
Support UTF8 strings in newer versions of Perl.
|
||||
|
||||
|
||||
|
||||
2001-12-30 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.01
|
||||
|
||||
Applied trivial win32 fix from Gurusamy Sarathy that
|
||||
avoids stray temp files left after 'make test'.
|
||||
|
||||
|
||||
|
||||
2001-03-13 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.00
|
||||
|
||||
Broken out of the Digest-MD5-2.12 distribution and made into
|
||||
a separate dist.
|
||||
|
||||
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Changes below from the Digest-MD5 dist.
|
||||
|
||||
|
||||
2000-09-18 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.12
|
||||
|
||||
Avoid pointer cast warning for machines with bigger ints
|
||||
than pointers. Patch by Robin Barker <rmb1@cise.npl.co.uk>.
|
||||
|
||||
|
||||
|
||||
2000-08-19 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.11
|
||||
|
||||
The fallback code introduced in 2.10 did only work for
|
||||
perl-5.6.0. It should now for for perl5.004 and 5.005
|
||||
as well. Patch by Ville Skyttä <ville@office.popsystems.com>.
|
||||
|
||||
|
||||
|
||||
2000-08-18 Gisle Aas <gisle@ActiveState.com>
|
||||
|
||||
Release 2.10
|
||||
|
||||
Digest::MD5 will now try to fallback to the pure perl
|
||||
implementation of Digest::Perl::MD5 if bootstrap fails.
|
||||
|
||||
Added a bit internal paranoia about casting the IV
|
||||
in the Digest::MD5 object to the MD5_CTX* pointer.
|
||||
|
||||
|
||||
|
||||
1999-08-06 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.09
|
||||
|
||||
Documentation update.
|
||||
|
||||
|
||||
|
||||
1999-07-28 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.08
|
||||
|
||||
The addfile() methods could trigger a core dump when passed
|
||||
a filehandle that had failed to open.
|
||||
|
||||
|
||||
|
||||
1999-04-26 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.07
|
||||
|
||||
The Digest::SHA1 module failed on some 64-bit systems, because I
|
||||
assumed there was a correspondence between the U32 size and
|
||||
BYTEORDER. This version use 'unsigned long' as Uwe's original
|
||||
SHA module did.
|
||||
|
||||
The module should now work better when liked statically with perl,
|
||||
because we now use a safer module-loaded test in Digest.pm.
|
||||
|
||||
Assume we know the outcome of the alignment test on VMS. Patch by
|
||||
Chuck Lane <lane@duphy4.physics.drexel.edu>
|
||||
|
||||
|
||||
|
||||
1999-03-26 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.06
|
||||
|
||||
Avoid LONG and BYTE types in SHA.xs as they was in conflict
|
||||
with similar definitions in <winnt.h>.
|
||||
|
||||
Patch by Marko Asplund <aspa@hip.fi> to make the the alignment
|
||||
test program link successfully with sfio-perl.
|
||||
|
||||
Fixed a typo in MD5.xs that might have affected 64-bit systems.
|
||||
Spotted by Nick Ing-Simmons
|
||||
|
||||
|
||||
|
||||
1999-03-15 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.05
|
||||
|
||||
Included Digest::SHA1 based on Uwe Hollerbach's SHA module.
|
||||
|
||||
|
||||
|
||||
1999-03-05 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.04
|
||||
|
||||
Avoid the -o option when compiling alignment test program
|
||||
for Win32 as suggested by Gurusamy Sarathy.
|
||||
|
||||
DEC Compiler bug workaround. Contributed by D Roland Walker
|
||||
<walker@ncbi.nlm.nih.gov>
|
||||
|
||||
Having references to a local variable called "na" was not
|
||||
very safe either. Some older versions of Perl can apparently
|
||||
macroize this into something completely different.
|
||||
|
||||
|
||||
|
||||
1999-02-27 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.03
|
||||
|
||||
Patch from Christopher J. Madsen <chris_madsen@geocities.com> that
|
||||
should help getting the u32align test program to compile with
|
||||
Visual C++ 5 on Windows NT.
|
||||
|
||||
Got rid of references to PL_na.
|
||||
|
||||
|
||||
|
||||
1999-01-31 Gisle Aas <gisle@aas.no>
|
||||
|
||||
Release 2.02
|
||||
|
||||
Added a hints file as workaround for an IRIX compiler bug.
|
||||
Contributed by D Roland Walker <walker@ncbi.nlm.nih.gov>.
|
||||
|
||||
Note that the rfc2202 test can still fail on some DEC Alpha,
|
||||
because of a compiler bug that affects the perl 'x' operator.
|
||||
The Digest:: modules should work and be safe to install anyway.
|
||||
|
||||
|
||||
|
||||
1998-12-18 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 2.01
|
||||
|
||||
Some casts and tweaks to make picky compilers more happy.
|
||||
|
||||
|
||||
|
||||
1998-11-04 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 2.00.
|
||||
|
||||
Taken out Digest::SHA1 as this module will be provided from Uwe
|
||||
Hollerbach later.
|
||||
|
||||
Some tweaks to MD2.xs and MD5.xs since "na" disappeared in
|
||||
perl5.005_53
|
||||
|
||||
|
||||
|
||||
1998-10-30 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_60
|
||||
|
||||
The 1.99_59 release introduced compilation problems for big-endian
|
||||
systems with free U32 alignment. Bug reported, and fix suggested
|
||||
by Paul J. Schinder <schinder@pobox.com>.
|
||||
|
||||
|
||||
|
||||
1998-10-28 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_59
|
||||
|
||||
Makefile.PL will run a test program to find out if U32 values can
|
||||
be aligned anywhere. This hopefully cures the core dumps reported
|
||||
on Solaris and other big endian systems. Thanks to Graham Barr for
|
||||
debugging this.
|
||||
|
||||
|
||||
|
||||
1998-10-28 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_58
|
||||
|
||||
Should be very close to a 2.00 release now. Need some success
|
||||
reports from people running on big-endian machines first I think.
|
||||
|
||||
Added a Digest::MD2 implementation.
|
||||
|
||||
Wrote Digest.pm documentation. This define the interface that all
|
||||
Digest:: modules should provide.
|
||||
|
||||
Avoided some code duplication in MD5.xs
|
||||
|
||||
Fixed typo, that prevented Digest::SHA1::sha1_base64() from working.
|
||||
|
||||
|
||||
|
||||
1998-10-27 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_57
|
||||
|
||||
Rewritten most of the MD5 C code to make it real fast (especially
|
||||
on little-endian machines without alignment restrictions for U32).
|
||||
Compared to MD5-1.7 we can process files 4 times as fast and we
|
||||
digest small stuff in memory 7 times faster. I came to these
|
||||
conclusions after these tests (gcc -O2, i586, Linux):
|
||||
|
||||
First tested calculation of the digest of a 31 MB file, using
|
||||
perl -le 'print Digest::MD5->new->addfile(*STDIN)->hexdigest'
|
||||
and similar stuff:
|
||||
|
||||
MD5-1.7: 21.06s
|
||||
Digest::MD5-1.99_57: 5.23s
|
||||
md5sum (GNU textutils): 4.90s
|
||||
|
||||
As you can see, we do nearly as good as the md5sum program. I
|
||||
think the reason we don't beat md5sum is that perl always insist on
|
||||
loading extra modules like Config.pm, Carp.pm, strict.pm, vars.pm,
|
||||
AutoLoader.pm and DynaLoader.pm. When I simply wrapped the MD5.xs
|
||||
hasher code in a C program I managed to process the file in 4.68s.
|
||||
|
||||
Then we calculated the digest of the same 6 byte sting, 20000
|
||||
times:
|
||||
|
||||
MD5-1.7: 11.81s
|
||||
Digest::MD5-1.99_57: 1.68s
|
||||
|
||||
Digest::MD5 benefit from making this into a plain procedure call
|
||||
instead of a static method call.
|
||||
|
||||
|
||||
Other changes in this release are:
|
||||
|
||||
Documentation update
|
||||
|
||||
Internal MD5.xs cleanup.
|
||||
|
||||
$md5->digest will automatically reset now.
|
||||
|
||||
Digest::HMAC methods add() and addfile() did not return the
|
||||
correct object.
|
||||
|
||||
Added Digest.pm loading module. I am not sure this is a good idea.
|
||||
|
||||
Added Digest::SHA1 and Digest::HMAC_SHA1 module. The Digest::SHA1
|
||||
module is just a wrapper around SHA.pm. I hope to get the author
|
||||
of SHA.pm to move his module to the Digest:: category.
|
||||
|
||||
|
||||
|
||||
1998-10-25 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_56
|
||||
|
||||
Fix memcpy_byteswap() function in MD5.xs. Must be careful with
|
||||
htovl() as it might evaluate its arguments more than once.
|
||||
|
||||
|
||||
|
||||
1998-10-25 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_55
|
||||
|
||||
Grahams HMAC_MD5.pm splitted into two modules. Digest::HMAC and
|
||||
Digest::HMAC_MD5. Also provide functional interface. Documentation
|
||||
is still lacking.
|
||||
|
||||
Included RFC 2202 based test for HMAC-MD5.
|
||||
|
||||
|
||||
|
||||
1998-10-24 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_54
|
||||
|
||||
Included HMAC_MD5.pm, contributed by Graham Barr <gbarr@ti.com>.
|
||||
|
||||
I have a hard time to make up my mind :-) md5_bin() renamed back
|
||||
to md5(). Functions are not exported by default any more.
|
||||
|
||||
Try to Encode/Decode with memcpy_byteswap for 32-bit big-endian
|
||||
machines.
|
||||
|
||||
|
||||
|
||||
1998-10-23 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_53
|
||||
|
||||
Renamed core module as Digest::MD5. Leave a MD5.pm stub for
|
||||
legacy code.
|
||||
|
||||
The md5() function renamed as md5_bin().
|
||||
|
||||
The constructor, Digest::MD5->new, no longer takes any extra
|
||||
arguments.
|
||||
|
||||
Added some new tests.
|
||||
|
||||
Updated the documentation.
|
||||
|
||||
$md5->b64digest implemented with same base64 encoder as md5_base64.
|
||||
|
||||
|
||||
|
||||
1998-10-23 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_52
|
||||
|
||||
Patch from Graham Barr which make it work for big-endian machines
|
||||
again.
|
||||
|
||||
|
||||
|
||||
1998-10-22 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_51
|
||||
|
||||
The MD5 class is now subclassable.
|
||||
|
||||
The add() and addfile() methods now return $self.
|
||||
|
||||
The reset() method is just an alias for new().
|
||||
|
||||
The constructor (MD5->new) now takes optional arguments which are
|
||||
automatically added. It means that we can now write:
|
||||
|
||||
MD5->new($data)->hexdigest;
|
||||
|
||||
New $md5->b64digest method.
|
||||
|
||||
New functions that are exported on request: md5, md5_hex, md5_base64
|
||||
|
||||
Included RFC 1321
|
||||
|
||||
Barely started to update the documentation.
|
||||
|
||||
|
||||
|
||||
1998-10-22 Gisle Aas <aas@sn.no>
|
||||
|
||||
Release 1.99_50
|
||||
|
||||
Much better performance (more than twice as fast now). Mostly
|
||||
because we use Copy/Zero instead of the original MD5_memcpy and
|
||||
MD5_memset functions.
|
||||
|
||||
The addfile() and hexdigest() methods are now XS implemented.
|
||||
|
||||
All RSA functions now included in MD5.xs and made static.
|
||||
|
||||
Use perl's Copy/Zero.
|
||||
|
||||
Random cleanup, simplifications and reformatting.
|
||||
Merged things better with the perl configuration.
|
||||
|
||||
|
||||
|
||||
Neil Winton's versions below:
|
||||
|
||||
|
||||
*** 96/06/20 Version 1.7
|
||||
|
||||
MD5 is now completely 64-bit clean (I hope). The basic MD5 code uses
|
||||
32-bit quantities and requires a typedef UINT4 to be defined in
|
||||
global.h. Perl configuration data (the value of BYTEORDER) is used to
|
||||
determine if unsigned longs have 4 or 8 bytes. On 64-bit platforms (eg
|
||||
DEC Alpha) then it assumes that "unsigned int" will be a 32-bit type.
|
||||
If this is incorrect then adding -DUINT4_IS_LONG to the DEFINES line in
|
||||
Makefile.PL will override this.
|
||||
|
||||
On some machines (at least Cray that I know of) there is no 32-bit
|
||||
integer type. In this case defining TRUNCATE_UINT4 (which is done
|
||||
automatically for a Cray) will ensure that 64-bit values are masked
|
||||
down to 32 bits. I have done my best to test this but without easy
|
||||
access to a true 64-bit machine I can not totally guarantee it (unless
|
||||
anyone wants to lend me a spare Cray :-)
|
||||
|
||||
There is one remaining limitation for 64-bit enabled processors. The
|
||||
amount of data passed to any single call to the underlying MD5
|
||||
routines is limited to (2^32 - 1) bytes -- that's 4 gigabytes. I'm
|
||||
sorry if that's a real problem for you ...
|
||||
|
||||
And finally, a minor compilation warning (unsigned char * used with
|
||||
function having char * prototype) has also been eliminated.
|
||||
|
||||
*** 96/04/09 Version 1.6
|
||||
|
||||
Re-generated module framework using h2xs to pick up the latest module
|
||||
conventions for versions etc. You can now say "use MD5 1.6;" and things
|
||||
should work correctly. MD5.pod has been integrated into MD5.pm and
|
||||
CHANGES renamed to Changes. There is a fairly comprehensive test.pl
|
||||
which can be invoked via "make test". There are no functional changes
|
||||
to the MD5 routines themselves.
|
||||
|
||||
*** 96/03/14 Version 1.5.3
|
||||
|
||||
Fixed addfile method to accept type-glob references for the file-handle
|
||||
(eg \*STDOUT). This is more consistent with other routines and is now the
|
||||
recommended way of passing file-handles. The documentation now gives more
|
||||
examples as to how the routines might be used.
|
||||
|
||||
*** 96/03/12 Version 1.5.2
|
||||
|
||||
Minor fixes from Christopher J Madsen <madsen@computek.net> to provide
|
||||
support for building on OS/2 (and to work around a perl -w bug).
|
||||
|
||||
Remove warning about possible difference between add('foo', 'bar') and
|
||||
add('foobar'). This is not true (it may have been true in the earliest
|
||||
version of the module but is no longer the case).
|
||||
|
||||
*** 96/03/08 Version 1.5.1
|
||||
|
||||
Add CHANGES file to make it easier for people to figure out what has
|
||||
been going on. (Meant to do this as part of 1.5)
|
||||
|
||||
*** 96/03/05 Version 1.5
|
||||
|
||||
Add hash() and hexhash() methods at the suggestion/request of Gary
|
||||
Howland <gary@kampai.euronet.nl> before inclusion in a wider library
|
||||
of cryptography modules.
|
||||
|
||||
*** 96/02/27 Version 1.4
|
||||
|
||||
Finally fixed the pesky Solaris dynamic loading bug. All kudos to Ken
|
||||
Pizzini <kenp@spry.com>!
|
||||
|
||||
*** 95/11/29 Version 1.3.1
|
||||
|
||||
Add explanations of current known problems.
|
||||
|
||||
*** 95/06/02 Version 1.3
|
||||
|
||||
Fix problems with scope resolution in addfile() reported by
|
||||
Jean-Claude Giese <Jean-Claude.Giese@loria.fr>. Basically ARGV is
|
||||
always implicitly in package main while other filehandles aren't.
|
||||
|
||||
*** 95/05/23 Version 1.2.1
|
||||
|
||||
[Changes pre 1.2.1 not recorded]
|
14
MANIFEST
Normal file
14
MANIFEST
Normal file
@ -0,0 +1,14 @@
|
||||
Changes
|
||||
MANIFEST
|
||||
Makefile.PL
|
||||
README
|
||||
SHA1.pm
|
||||
SHA1.xs
|
||||
fip180-1.gif
|
||||
fip180-1.html
|
||||
hints/irix_6.pl
|
||||
t/badfile.t
|
||||
t/bits.t
|
||||
t/sha1.t
|
||||
typemap
|
||||
META.yml Module meta-data (added by MakeMaker)
|
24
META.yml
Normal file
24
META.yml
Normal file
@ -0,0 +1,24 @@
|
||||
--- #YAML:1.0
|
||||
name: Digest-SHA1
|
||||
version: 2.13
|
||||
abstract: Perl interface to the SHA-1 algorithm
|
||||
author:
|
||||
- Gisle Aas <gisle@activestate.com>
|
||||
license: perl
|
||||
distribution_type: module
|
||||
configure_requires:
|
||||
ExtUtils::MakeMaker: 0
|
||||
build_requires:
|
||||
ExtUtils::MakeMaker: 0
|
||||
requires:
|
||||
Digest::base: 1.00
|
||||
perl: 5.004
|
||||
no_index:
|
||||
directory:
|
||||
- t
|
||||
- inc
|
||||
generated_by: ExtUtils::MakeMaker version 6.56
|
||||
meta-spec:
|
||||
url: http://module-build.sourceforge.net/META-spec-v1.4.html
|
||||
version: 1.4
|
||||
repository: http://github.com/gisle/digest-sha1
|
41
Makefile.PL
Normal file
41
Makefile.PL
Normal file
@ -0,0 +1,41 @@
|
||||
require 5.004;
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
'NAME' => 'Digest::SHA1',
|
||||
'VERSION_FROM' => 'SHA1.pm',
|
||||
'ABSTRACT' => 'Perl interface to the SHA-1 algorithm',
|
||||
'AUTHOR' => 'Gisle Aas <gisle@activestate.com>',
|
||||
'LICENSE' => "perl",
|
||||
'MIN_PERL_VERSION' => 5.004,
|
||||
'PREREQ_PM' => {
|
||||
'Digest::base' => '1.00',
|
||||
},
|
||||
'META_MERGE' => {
|
||||
repository => 'http://github.com/gisle/digest-sha1',
|
||||
},
|
||||
'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
);
|
||||
|
||||
|
||||
BEGIN {
|
||||
# compatibility with older versions of MakeMaker
|
||||
my $developer = -f "NOTES.txt";
|
||||
my %mm_req = (
|
||||
LICENCE => 6.31,
|
||||
META_MERGE => 6.45,
|
||||
META_ADD => 6.45,
|
||||
MIN_PERL_VERSION => 6.48,
|
||||
);
|
||||
undef(*WriteMakefile);
|
||||
*WriteMakefile = sub {
|
||||
my %arg = @_;
|
||||
for (keys %mm_req) {
|
||||
unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) {
|
||||
warn "$_ $@" if $developer;
|
||||
delete $arg{$_};
|
||||
}
|
||||
}
|
||||
ExtUtils::MakeMaker::WriteMakefile(%arg);
|
||||
};
|
||||
}
|
14
README
Normal file
14
README
Normal file
@ -0,0 +1,14 @@
|
||||
The 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.
|
||||
|
||||
SHA1 is described at <http://www.itl.nist.gov/fipspubs/fip180-1.htm>
|
||||
|
||||
You will need Perl version 5.004 or better to install this module.
|
||||
|
||||
Copyright 1999-2004 Gisle Aas.
|
||||
Copyright 1997 Uwe Hollerbach.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the same terms as Perl itself.
|
246
SHA1.pm
Normal file
246
SHA1.pm
Normal file
@ -0,0 +1,246 @@
|
||||
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
|
622
SHA1.xs
Normal file
622
SHA1.xs
Normal file
@ -0,0 +1,622 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define PERL_NO_GET_CONTEXT /* we want efficiency */
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PERL_VERSION
|
||||
# include <patchlevel.h>
|
||||
# if !(defined(PERL_VERSION) || (SUBVERSION > 0 && defined(PATCHLEVEL)))
|
||||
# include <could_not_find_Perl_patchlevel.h>
|
||||
# endif
|
||||
# define PERL_REVISION 5
|
||||
# define PERL_VERSION PATCHLEVEL
|
||||
# define PERL_SUBVERSION SUBVERSION
|
||||
#endif
|
||||
|
||||
#if PERL_VERSION <= 4 && !defined(PL_dowarn)
|
||||
#define PL_dowarn dowarn
|
||||
#endif
|
||||
|
||||
#ifdef G_WARN_ON
|
||||
#define DOWARN (PL_dowarn & G_WARN_ON)
|
||||
#else
|
||||
#define DOWARN PL_dowarn
|
||||
#endif
|
||||
|
||||
#ifdef SvPVbyte
|
||||
#if PERL_REVISION == 5 && PERL_VERSION < 7
|
||||
/* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
|
||||
#undef SvPVbyte
|
||||
#define SvPVbyte(sv, lp) \
|
||||
((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
|
||||
? ((lp = SvCUR(sv)), SvPVX(sv)) : my_sv_2pvbyte(aTHX_ sv, &lp))
|
||||
|
||||
static char *
|
||||
my_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
|
||||
{
|
||||
sv_utf8_downgrade(sv,0);
|
||||
return SvPV(sv,*lp);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#define SvPVbyte SvPV
|
||||
#endif
|
||||
|
||||
#ifndef dTHX
|
||||
#define pTHX_
|
||||
#define aTHX_
|
||||
#endif
|
||||
|
||||
/* NIST Secure Hash Algorithm */
|
||||
/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */
|
||||
/* from Peter C. Gutmann's implementation as found in */
|
||||
/* Applied Cryptography by Bruce Schneier */
|
||||
/* Further modifications to include the "UNRAVEL" stuff, below */
|
||||
|
||||
/* This code is in the public domain */
|
||||
|
||||
/* Useful defines & typedefs */
|
||||
|
||||
#if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321)))
|
||||
typedef U64TYPE ULONGx;
|
||||
# if BYTEORDER == 0x1234
|
||||
# undef BYTEORDER
|
||||
# define BYTEORDER 0x12345678
|
||||
# elif BYTEORDER == 0x4321
|
||||
# undef BYTEORDER
|
||||
# define BYTEORDER 0x87654321
|
||||
# endif
|
||||
#else
|
||||
typedef unsigned long ULONGx; /* 32-or-more-bit quantity */
|
||||
#endif
|
||||
|
||||
#define SHA_BLOCKSIZE 64
|
||||
#define SHA_DIGESTSIZE 20
|
||||
|
||||
typedef struct {
|
||||
ULONGx digest[5]; /* message digest */
|
||||
ULONGx count_lo, count_hi; /* 64-bit bit count */
|
||||
U8 data[SHA_BLOCKSIZE]; /* SHA data buffer */
|
||||
int local; /* unprocessed amount in data */
|
||||
} SHA_INFO;
|
||||
|
||||
|
||||
/* UNRAVEL should be fastest & biggest */
|
||||
/* UNROLL_LOOPS should be just as big, but slightly slower */
|
||||
/* both undefined should be smallest and slowest */
|
||||
|
||||
#define SHA_VERSION 1
|
||||
#define UNRAVEL
|
||||
/* #define UNROLL_LOOPS */
|
||||
|
||||
/* SHA f()-functions */
|
||||
#define f1(x,y,z) ((x & y) | (~x & z))
|
||||
#define f2(x,y,z) (x ^ y ^ z)
|
||||
#define f3(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define f4(x,y,z) (x ^ y ^ z)
|
||||
|
||||
/* SHA constants */
|
||||
#define CONST1 0x5a827999L
|
||||
#define CONST2 0x6ed9eba1L
|
||||
#define CONST3 0x8f1bbcdcL
|
||||
#define CONST4 0xca62c1d6L
|
||||
|
||||
/* truncate to 32 bits -- should be a null op on 32-bit machines */
|
||||
#define T32(x) ((x) & 0xffffffffL)
|
||||
|
||||
/* 32-bit rotate */
|
||||
#define R32(x,n) T32(((x << n) | (x >> (32 - n))))
|
||||
|
||||
/* the generic case, for when the overall rotation is not unraveled */
|
||||
#define FG(n) \
|
||||
T = T32(R32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n); \
|
||||
E = D; D = C; C = R32(B,30); B = A; A = T
|
||||
|
||||
/* specific cases, for when the overall rotation is unraveled */
|
||||
#define FA(n) \
|
||||
T = T32(R32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n); B = R32(B,30)
|
||||
|
||||
#define FB(n) \
|
||||
E = T32(R32(T,5) + f##n(A,B,C) + D + *WP++ + CONST##n); A = R32(A,30)
|
||||
|
||||
#define FC(n) \
|
||||
D = T32(R32(E,5) + f##n(T,A,B) + C + *WP++ + CONST##n); T = R32(T,30)
|
||||
|
||||
#define FD(n) \
|
||||
C = T32(R32(D,5) + f##n(E,T,A) + B + *WP++ + CONST##n); E = R32(E,30)
|
||||
|
||||
#define FE(n) \
|
||||
B = T32(R32(C,5) + f##n(D,E,T) + A + *WP++ + CONST##n); D = R32(D,30)
|
||||
|
||||
#define FT(n) \
|
||||
A = T32(R32(B,5) + f##n(C,D,E) + T + *WP++ + CONST##n); C = R32(C,30)
|
||||
|
||||
|
||||
static void sha_transform(SHA_INFO *sha_info)
|
||||
{
|
||||
int i;
|
||||
U8 *dp;
|
||||
ULONGx T, A, B, C, D, E, W[80], *WP;
|
||||
|
||||
dp = sha_info->data;
|
||||
|
||||
/*
|
||||
the following makes sure that at least one code block below is
|
||||
traversed or an error is reported, without the necessity for nested
|
||||
preprocessor if/else/endif blocks, which are a great pain in the
|
||||
nether regions of the anatomy...
|
||||
*/
|
||||
#undef SWAP_DONE
|
||||
|
||||
#if BYTEORDER == 0x1234
|
||||
#define SWAP_DONE
|
||||
/* assert(sizeof(ULONGx) == 4); */
|
||||
for (i = 0; i < 16; ++i) {
|
||||
T = *((ULONGx *) dp);
|
||||
dp += 4;
|
||||
W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) |
|
||||
((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BYTEORDER == 0x4321
|
||||
#define SWAP_DONE
|
||||
/* assert(sizeof(ULONGx) == 4); */
|
||||
for (i = 0; i < 16; ++i) {
|
||||
T = *((ULONGx *) dp);
|
||||
dp += 4;
|
||||
W[i] = T32(T);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BYTEORDER == 0x12345678
|
||||
#define SWAP_DONE
|
||||
/* assert(sizeof(ULONGx) == 8); */
|
||||
for (i = 0; i < 16; i += 2) {
|
||||
T = *((ULONGx *) dp);
|
||||
dp += 8;
|
||||
W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) |
|
||||
((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
|
||||
T >>= 32;
|
||||
W[i+1] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) |
|
||||
((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BYTEORDER == 0x87654321
|
||||
#define SWAP_DONE
|
||||
/* assert(sizeof(ULONGx) == 8); */
|
||||
for (i = 0; i < 16; i += 2) {
|
||||
T = *((ULONGx *) dp);
|
||||
dp += 8;
|
||||
W[i] = T32(T >> 32);
|
||||
W[i+1] = T32(T);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef SWAP_DONE
|
||||
#error Unknown byte order -- you need to add code here
|
||||
#endif /* SWAP_DONE */
|
||||
|
||||
for (i = 16; i < 80; ++i) {
|
||||
W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
|
||||
#if (SHA_VERSION == 1)
|
||||
W[i] = R32(W[i], 1);
|
||||
#endif /* SHA_VERSION */
|
||||
}
|
||||
A = sha_info->digest[0];
|
||||
B = sha_info->digest[1];
|
||||
C = sha_info->digest[2];
|
||||
D = sha_info->digest[3];
|
||||
E = sha_info->digest[4];
|
||||
WP = W;
|
||||
#ifdef UNRAVEL
|
||||
FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1);
|
||||
FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1);
|
||||
FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2); FE(2); FT(2);
|
||||
FA(2); FB(2); FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2);
|
||||
FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3); FA(3); FB(3);
|
||||
FC(3); FD(3); FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3);
|
||||
FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4); FC(4); FD(4);
|
||||
FE(4); FT(4); FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4);
|
||||
sha_info->digest[0] = T32(sha_info->digest[0] + E);
|
||||
sha_info->digest[1] = T32(sha_info->digest[1] + T);
|
||||
sha_info->digest[2] = T32(sha_info->digest[2] + A);
|
||||
sha_info->digest[3] = T32(sha_info->digest[3] + B);
|
||||
sha_info->digest[4] = T32(sha_info->digest[4] + C);
|
||||
#else /* !UNRAVEL */
|
||||
#ifdef UNROLL_LOOPS
|
||||
FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
|
||||
FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
|
||||
FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
|
||||
FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
|
||||
FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
|
||||
FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
|
||||
FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
|
||||
FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
|
||||
#else /* !UNROLL_LOOPS */
|
||||
for (i = 0; i < 20; ++i) { FG(1); }
|
||||
for (i = 20; i < 40; ++i) { FG(2); }
|
||||
for (i = 40; i < 60; ++i) { FG(3); }
|
||||
for (i = 60; i < 80; ++i) { FG(4); }
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
sha_info->digest[0] = T32(sha_info->digest[0] + A);
|
||||
sha_info->digest[1] = T32(sha_info->digest[1] + B);
|
||||
sha_info->digest[2] = T32(sha_info->digest[2] + C);
|
||||
sha_info->digest[3] = T32(sha_info->digest[3] + D);
|
||||
sha_info->digest[4] = T32(sha_info->digest[4] + E);
|
||||
#endif /* !UNRAVEL */
|
||||
}
|
||||
|
||||
/* initialize the SHA digest */
|
||||
|
||||
static void sha_init(SHA_INFO *sha_info)
|
||||
{
|
||||
sha_info->digest[0] = 0x67452301L;
|
||||
sha_info->digest[1] = 0xefcdab89L;
|
||||
sha_info->digest[2] = 0x98badcfeL;
|
||||
sha_info->digest[3] = 0x10325476L;
|
||||
sha_info->digest[4] = 0xc3d2e1f0L;
|
||||
sha_info->count_lo = 0L;
|
||||
sha_info->count_hi = 0L;
|
||||
sha_info->local = 0;
|
||||
}
|
||||
|
||||
/* update the SHA digest */
|
||||
|
||||
static void sha_update(SHA_INFO *sha_info, U8 *buffer, int count)
|
||||
{
|
||||
int i;
|
||||
ULONGx clo;
|
||||
|
||||
clo = T32(sha_info->count_lo + ((ULONGx) count << 3));
|
||||
if (clo < sha_info->count_lo) {
|
||||
++sha_info->count_hi;
|
||||
}
|
||||
sha_info->count_lo = clo;
|
||||
sha_info->count_hi += (ULONGx) count >> 29;
|
||||
if (sha_info->local) {
|
||||
i = SHA_BLOCKSIZE - sha_info->local;
|
||||
if (i > count) {
|
||||
i = count;
|
||||
}
|
||||
memcpy(((U8 *) sha_info->data) + sha_info->local, buffer, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
sha_info->local += i;
|
||||
if (sha_info->local == SHA_BLOCKSIZE) {
|
||||
sha_transform(sha_info);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (count >= SHA_BLOCKSIZE) {
|
||||
memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
|
||||
buffer += SHA_BLOCKSIZE;
|
||||
count -= SHA_BLOCKSIZE;
|
||||
sha_transform(sha_info);
|
||||
}
|
||||
memcpy(sha_info->data, buffer, count);
|
||||
sha_info->local = count;
|
||||
}
|
||||
|
||||
|
||||
static void sha_transform_and_copy(unsigned char digest[20], SHA_INFO *sha_info)
|
||||
{
|
||||
sha_transform(sha_info);
|
||||
digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
|
||||
digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
|
||||
digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
|
||||
digest[ 3] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
|
||||
digest[ 4] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
|
||||
digest[ 5] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
|
||||
digest[ 6] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
|
||||
digest[ 7] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
|
||||
digest[ 8] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
|
||||
digest[ 9] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
|
||||
digest[10] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
|
||||
digest[11] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
|
||||
digest[12] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
|
||||
digest[13] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
|
||||
digest[14] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
|
||||
digest[15] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
|
||||
digest[16] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
|
||||
digest[17] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
|
||||
digest[18] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
|
||||
digest[19] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
|
||||
}
|
||||
|
||||
/* finish computing the SHA digest */
|
||||
static void sha_final(unsigned char digest[20], SHA_INFO *sha_info)
|
||||
{
|
||||
int count;
|
||||
ULONGx lo_bit_count, hi_bit_count;
|
||||
|
||||
lo_bit_count = sha_info->count_lo;
|
||||
hi_bit_count = sha_info->count_hi;
|
||||
count = (int) ((lo_bit_count >> 3) & 0x3f);
|
||||
((U8 *) sha_info->data)[count++] = 0x80;
|
||||
if (count > SHA_BLOCKSIZE - 8) {
|
||||
memset(((U8 *) sha_info->data) + count, 0, SHA_BLOCKSIZE - count);
|
||||
sha_transform(sha_info);
|
||||
memset((U8 *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
|
||||
} else {
|
||||
memset(((U8 *) sha_info->data) + count, 0,
|
||||
SHA_BLOCKSIZE - 8 - count);
|
||||
}
|
||||
sha_info->data[56] = (U8)((hi_bit_count >> 24) & 0xff);
|
||||
sha_info->data[57] = (U8)((hi_bit_count >> 16) & 0xff);
|
||||
sha_info->data[58] = (U8)((hi_bit_count >> 8) & 0xff);
|
||||
sha_info->data[59] = (U8)((hi_bit_count >> 0) & 0xff);
|
||||
sha_info->data[60] = (U8)((lo_bit_count >> 24) & 0xff);
|
||||
sha_info->data[61] = (U8)((lo_bit_count >> 16) & 0xff);
|
||||
sha_info->data[62] = (U8)((lo_bit_count >> 8) & 0xff);
|
||||
sha_info->data[63] = (U8)((lo_bit_count >> 0) & 0xff);
|
||||
sha_transform_and_copy(digest, sha_info);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
#ifndef INT2PTR
|
||||
#define INT2PTR(any,d) (any)(d)
|
||||
#endif
|
||||
|
||||
static SHA_INFO* get_sha_info(pTHX_ SV* sv)
|
||||
{
|
||||
if (sv_derived_from(sv, "Digest::SHA1"))
|
||||
return INT2PTR(SHA_INFO*, SvIV(SvRV(sv)));
|
||||
croak("Not a reference to a Digest::SHA1 object");
|
||||
return (SHA_INFO*)0; /* some compilers insist on a return value */
|
||||
}
|
||||
|
||||
|
||||
static char* hex_20(const unsigned char* from, char* to)
|
||||
{
|
||||
static const char *hexdigits = "0123456789abcdef";
|
||||
const unsigned char *end = from + 20;
|
||||
char *d = to;
|
||||
|
||||
while (from < end) {
|
||||
*d++ = hexdigits[(*from >> 4)];
|
||||
*d++ = hexdigits[(*from & 0x0F)];
|
||||
from++;
|
||||
}
|
||||
*d = '\0';
|
||||
return to;
|
||||
}
|
||||
|
||||
static char* base64_20(const unsigned char* from, char* to)
|
||||
{
|
||||
static const char* base64 =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
const unsigned char *end = from + 20;
|
||||
unsigned char c1, c2, c3;
|
||||
char *d = to;
|
||||
|
||||
while (1) {
|
||||
c1 = *from++;
|
||||
c2 = *from++;
|
||||
*d++ = base64[c1>>2];
|
||||
*d++ = base64[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)];
|
||||
if (from == end) {
|
||||
*d++ = base64[(c2 & 0xF) << 2];
|
||||
break;
|
||||
}
|
||||
c3 = *from++;
|
||||
*d++ = base64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
|
||||
*d++ = base64[c3 & 0x3F];
|
||||
}
|
||||
*d = '\0';
|
||||
return to;
|
||||
}
|
||||
|
||||
/* Formats */
|
||||
#define F_BIN 0
|
||||
#define F_HEX 1
|
||||
#define F_B64 2
|
||||
|
||||
static SV* make_mortal_sv(pTHX_ const unsigned char *src, int type)
|
||||
{
|
||||
STRLEN len;
|
||||
char result[41];
|
||||
char *ret;
|
||||
|
||||
switch (type) {
|
||||
case F_BIN:
|
||||
ret = (char*)src;
|
||||
len = 20;
|
||||
break;
|
||||
case F_HEX:
|
||||
ret = hex_20(src, result);
|
||||
len = 40;
|
||||
break;
|
||||
case F_B64:
|
||||
ret = base64_20(src, result);
|
||||
len = 27;
|
||||
break;
|
||||
default:
|
||||
croak("Bad convertion type (%d)", type);
|
||||
break;
|
||||
}
|
||||
return sv_2mortal(newSVpv(ret,len));
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
typedef PerlIO* InputStream;
|
||||
|
||||
MODULE = Digest::SHA1 PACKAGE = Digest::SHA1
|
||||
|
||||
PROTOTYPES: DISABLE
|
||||
|
||||
void
|
||||
new(xclass)
|
||||
SV* xclass
|
||||
PREINIT:
|
||||
SHA_INFO* context;
|
||||
PPCODE:
|
||||
if (!SvROK(xclass)) {
|
||||
STRLEN my_na;
|
||||
char *sclass = SvPV(xclass, my_na);
|
||||
New(55, context, 1, SHA_INFO);
|
||||
ST(0) = sv_newmortal();
|
||||
sv_setref_pv(ST(0), sclass, (void*)context);
|
||||
SvREADONLY_on(SvRV(ST(0)));
|
||||
} else {
|
||||
context = get_sha_info(aTHX_ xclass);
|
||||
}
|
||||
sha_init(context);
|
||||
XSRETURN(1);
|
||||
|
||||
void
|
||||
clone(self)
|
||||
SV* self
|
||||
PREINIT:
|
||||
SHA_INFO* cont = get_sha_info(aTHX_ self);
|
||||
const char *myname = sv_reftype(SvRV(self),TRUE);
|
||||
SHA_INFO* context;
|
||||
PPCODE:
|
||||
New(55, context, 1, SHA_INFO);
|
||||
ST(0) = sv_newmortal();
|
||||
sv_setref_pv(ST(0), myname , (void*)context);
|
||||
SvREADONLY_on(SvRV(ST(0)));
|
||||
memcpy(context,cont,sizeof(SHA_INFO));
|
||||
XSRETURN(1);
|
||||
|
||||
void
|
||||
DESTROY(context)
|
||||
SHA_INFO* context
|
||||
CODE:
|
||||
Safefree(context);
|
||||
|
||||
void
|
||||
add(self, ...)
|
||||
SV* self
|
||||
PREINIT:
|
||||
SHA_INFO* context = get_sha_info(aTHX_ self);
|
||||
int i;
|
||||
unsigned char *data;
|
||||
STRLEN len;
|
||||
PPCODE:
|
||||
for (i = 1; i < items; i++) {
|
||||
data = (unsigned char *)(SvPVbyte(ST(i), len));
|
||||
sha_update(context, data, len);
|
||||
}
|
||||
XSRETURN(1); /* self */
|
||||
|
||||
void
|
||||
addfile(self, fh)
|
||||
SV* self
|
||||
InputStream fh
|
||||
PREINIT:
|
||||
SHA_INFO* context = get_sha_info(aTHX_ self);
|
||||
unsigned char buffer[4096];
|
||||
int n;
|
||||
CODE:
|
||||
if (fh) {
|
||||
/* Process blocks until EOF or error */
|
||||
while ( (n = PerlIO_read(fh, buffer, sizeof(buffer))) > 0) {
|
||||
sha_update(context, buffer, n);
|
||||
}
|
||||
if (PerlIO_error(fh)) {
|
||||
croak("Reading from filehandle failed");
|
||||
}
|
||||
}
|
||||
else {
|
||||
croak("No filehandle passed");
|
||||
}
|
||||
|
||||
XSRETURN(1); /* self */
|
||||
|
||||
void
|
||||
digest(context)
|
||||
SHA_INFO* context
|
||||
ALIAS:
|
||||
Digest::SHA1::digest = F_BIN
|
||||
Digest::SHA1::hexdigest = F_HEX
|
||||
Digest::SHA1::b64digest = F_B64
|
||||
PREINIT:
|
||||
unsigned char digeststr[20];
|
||||
PPCODE:
|
||||
sha_final(digeststr, context);
|
||||
sha_init(context); /* In case it is reused */
|
||||
ST(0) = make_mortal_sv(aTHX_ digeststr, ix);
|
||||
XSRETURN(1);
|
||||
|
||||
void
|
||||
sha1(...)
|
||||
ALIAS:
|
||||
Digest::SHA1::sha1 = F_BIN
|
||||
Digest::SHA1::sha1_hex = F_HEX
|
||||
Digest::SHA1::sha1_base64 = F_B64
|
||||
PREINIT:
|
||||
SHA_INFO ctx;
|
||||
int i;
|
||||
unsigned char *data;
|
||||
STRLEN len;
|
||||
unsigned char digeststr[20];
|
||||
PPCODE:
|
||||
sha_init(&ctx);
|
||||
|
||||
if (DOWARN) {
|
||||
const char *msg = 0;
|
||||
if (items == 1) {
|
||||
if (SvROK(ST(0))) {
|
||||
SV* sv = SvRV(ST(0));
|
||||
if (SvOBJECT(sv) && strEQ(HvNAME(SvSTASH(sv)), "Digest::SHA1"))
|
||||
msg = "probably called as method";
|
||||
else
|
||||
msg = "called with reference argument";
|
||||
}
|
||||
}
|
||||
else if (items > 1) {
|
||||
data = (unsigned char *)SvPVbyte(ST(0), len);
|
||||
if (len == 12 && memEQ("Digest::SHA1", data, 12)) {
|
||||
msg = "probably called as class method";
|
||||
}
|
||||
}
|
||||
if (msg) {
|
||||
const char *f = (ix == F_BIN) ? "sha1" :
|
||||
(ix == F_HEX) ? "sha1_hex" : "sha1_base64";
|
||||
warn("&Digest::SHA1::%s function %s", f, msg);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < items; i++) {
|
||||
data = (unsigned char *)(SvPVbyte(ST(i), len));
|
||||
sha_update(&ctx, data, len);
|
||||
}
|
||||
sha_final(digeststr, &ctx);
|
||||
ST(0) = make_mortal_sv(aTHX_ digeststr, ix);
|
||||
XSRETURN(1);
|
||||
|
||||
void
|
||||
sha1_transform(data)
|
||||
SV* data
|
||||
PREINIT:
|
||||
SHA_INFO ctx;
|
||||
unsigned char *data_pv;
|
||||
unsigned char test[64];
|
||||
STRLEN len;
|
||||
unsigned char digeststr[20];
|
||||
PPCODE:
|
||||
sha_init(&ctx);
|
||||
|
||||
memset (test, 0, 64);
|
||||
data_pv = (unsigned char *)(SvPVbyte(data, len));
|
||||
memcpy (test, data_pv, len);
|
||||
memcpy ((&ctx)->data, test, 64);
|
||||
sha_transform_and_copy(digeststr, &ctx);
|
||||
ST(0) = sv_2mortal(newSVpv((char*)digeststr, 20));
|
||||
XSRETURN(1);
|
||||
|
BIN
fip180-1.gif
Normal file
BIN
fip180-1.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
1035
fip180-1.html
Normal file
1035
fip180-1.html
Normal file
File diff suppressed because it is too large
Load Diff
6
hints/irix_6.pl
Normal file
6
hints/irix_6.pl
Normal file
@ -0,0 +1,6 @@
|
||||
# The Mongoose v7.1 compiler freezes up somewhere in the optimization of
|
||||
# MD5Transform() in MD5.c with optimization -O3. This is a workaround:
|
||||
|
||||
if ($Config{cc} =~ /64|n32/ && `$Config{cc} -version 2>&1` =~ /\s7\.1/) {
|
||||
$self->{OPTIMIZE} = "-O1";
|
||||
}
|
19
t/badfile.t
Normal file
19
t/badfile.t
Normal file
@ -0,0 +1,19 @@
|
||||
print "1..2\n";
|
||||
|
||||
use Digest::SHA1 ();
|
||||
|
||||
$sha1 = Digest::SHA1->new;
|
||||
|
||||
eval {
|
||||
use vars qw(*FOO);
|
||||
$sha1->addfile(*FOO);
|
||||
};
|
||||
print "not " unless $@ =~ /^Bad filehandle: FOO at/;
|
||||
print "ok 1\n";
|
||||
|
||||
open(BAR, "no-existing-file.$$");
|
||||
eval {
|
||||
$sha1->addfile(*BAR);
|
||||
};
|
||||
print "not " unless $@ =~ /^No filehandle passed at/;
|
||||
print "ok 2\n";
|
36
t/bits.t
Normal file
36
t/bits.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!perl -w
|
||||
|
||||
BEGIN {
|
||||
if ($] < 5.005) {
|
||||
# Test module can't be expected to be available
|
||||
# and I ended up with seg faults when trying to
|
||||
# load it with eval { require Test };
|
||||
print "1..0\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
use Test qw(plan ok);
|
||||
plan tests => 2;
|
||||
|
||||
use Digest::SHA1;
|
||||
|
||||
my $sha1 = Digest::SHA1->new;
|
||||
|
||||
if ($Digest::base::VERSION && $Digest::base::VERSION) {
|
||||
$sha1->add_bits("01111111");
|
||||
ok($sha1->hexdigest, "23833462f55515a900e016db2eb943fb474c19f6");
|
||||
eval {
|
||||
$sha1->add_bits("0111");
|
||||
};
|
||||
ok($@ =~ /must be multiple of 8/);
|
||||
}
|
||||
else {
|
||||
print "# No Digest::base\n";
|
||||
eval {
|
||||
$sha1->add_bits("foo");
|
||||
};
|
||||
ok($@ =~ /^Can\'t locate Digest\/base\.pm in \@INC/);
|
||||
ok(1); # dummy
|
||||
}
|
||||
|
62
t/sha1.t
Normal file
62
t/sha1.t
Normal file
@ -0,0 +1,62 @@
|
||||
print "1..13\n";
|
||||
|
||||
use Digest::SHA1 qw(sha1 sha1_hex sha1_base64 sha1_transform);
|
||||
|
||||
print "not " unless Digest::SHA1->new->add("abc")->hexdigest eq "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
print "ok 1\n";
|
||||
|
||||
print "not " unless sha1("abc") eq pack("H*", "a9993e364706816aba3e25717850c26c9cd0d89d");
|
||||
print "ok 2\n";
|
||||
|
||||
print "not " unless sha1_hex("abc") eq "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
print "ok 3\n";
|
||||
|
||||
print "not " unless sha1_base64("abc") eq "qZk+NkcGgWq6PiVxeFDCbJzQ2J0";
|
||||
print "ok 4\n";
|
||||
|
||||
# Test file checking from too...
|
||||
open(FILE, ">stest$$.txt") || die;
|
||||
binmode(FILE);
|
||||
for (1..512) {
|
||||
print FILE "This is line $_\n";
|
||||
}
|
||||
close(FILE);
|
||||
|
||||
open(FILE, "stest$$.txt") || die;
|
||||
$digest = Digest::SHA1->new->addfile(*FILE)->b64digest;
|
||||
print "$digest\nnot " unless $digest eq "1ZuIK/sQeBwqh+dIACqpnoRQUE4";
|
||||
print "ok 5\n";
|
||||
close(FILE);
|
||||
|
||||
unlink("stest$$.txt");
|
||||
|
||||
|
||||
print "not " unless sha1_transform(pack('H*', 'dc71a8092d4b1b7b98101d58698d9d1cc48225bb'))
|
||||
eq pack('H*', '2e4c75ad39160f52614d122e6c7ec80446f68567');
|
||||
print "ok 6\n";
|
||||
|
||||
print "not " unless sha1_transform(pack('H*', '0abe1db666612acdf95d2f86d60c65210b78ab23'))
|
||||
eq pack('H*', '7c1c2aabca822912f3016299b160035787477b48');
|
||||
print "ok 7\n";
|
||||
|
||||
print "not " unless sha1_transform(pack('H*', '86da486230e353e0ec5e9220876c687892c0266c'))
|
||||
eq pack('H*', '1da304aec652c21d4f54642434705c91aeaf9abe');
|
||||
print "ok 8\n";
|
||||
|
||||
$digest = Digest::SHA1->new;
|
||||
print "not " unless $digest->hexdigest eq "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||
print "ok 9\n";
|
||||
|
||||
print "not " unless $digest->clone->hexdigest eq "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||
print "ok 10\n";
|
||||
|
||||
$digest->add("abc");
|
||||
print "not " unless $digest->clone->hexdigest eq "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
print "ok 11\n";
|
||||
|
||||
$digest->add("d");
|
||||
print "not " unless $digest->hexdigest eq "81fe8bfe87576c3ecb22426f8e57847382917acf";
|
||||
print "ok 12\n";
|
||||
|
||||
print "not " unless $digest->hexdigest eq "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||
print "ok 13\n";
|
Loading…
Reference in New Issue
Block a user