summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/Digest-SHA
diff options
context:
space:
mode:
authorafresh1 <afresh1@openbsd.org>2014-03-24 14:58:42 +0000
committerafresh1 <afresh1@openbsd.org>2014-03-24 14:58:42 +0000
commit91f110e064cd7c194e59e019b83bb7496c1c84d4 (patch)
tree3e8e577405dba7e94b43cbf21c22f21aaa5ab949 /gnu/usr.bin/perl/cpan/Digest-SHA
parentdo not call purge_task every 10 secs, it is only needed once at startup and (diff)
downloadwireguard-openbsd-91f110e064cd7c194e59e019b83bb7496c1c84d4.tar.xz
wireguard-openbsd-91f110e064cd7c194e59e019b83bb7496c1c84d4.zip
Import perl-5.18.2
OK espie@ sthen@ deraadt@
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Digest-SHA')
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/Changes56
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/Makefile.PL34
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/README6
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/SHA.xs25
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/lib/Digest/SHA.pm68
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/shasum10
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.c136
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.h87
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/src/sha64bit.c2
-rw-r--r--gnu/usr.bin/perl/cpan/Digest-SHA/t/unicode.t43
10 files changed, 318 insertions, 149 deletions
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/Changes b/gnu/usr.bin/perl/cpan/Digest-SHA/Changes
index 5f9d1cc777f..98915238731 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/Changes
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/Changes
@@ -1,5 +1,61 @@
Revision history for Perl extension Digest::SHA.
+5.84 Sat Mar 9 17:36:08 MST 2013
+ - untweaked Makefile.PL to remove dependencies of SHA.c
+ -- dependencies were breaking builds on VMS
+ -- retaining dependencies provides too little benefit
+ for cost of portable workaround
+
+5.83 Mon Mar 4 08:12:00 MST 2013
+ - removed code for standalone C operation (no longer used)
+ -- eliminates need for external symbols
+ -- consolidates SHA and HMAC code
+ -- reduces size of object files
+ -- thanks to Marc Lehmann for suggestions
+ - tweaked Makefile.PL to show dependencies of SHA.c
+
+5.82 Thu Jan 24 04:54:12 MST 2013
+ - introduced workaround to SvPVbyte bug in Perl 5.6
+ -- module behavior now consistent under all Perls 5.6+
+ -- ref: new test script t/unicode.t
+ -- SHA routines now always croak on wide chars (5.6+)
+ - removed "static" message schedules from C code
+ -- default "auto" is now just as fast
+ -- thread-safe option (-t) no longer necessary
+ -- still allowed, but ignored
+ -- simplifies source and header files
+ -- eliminates SHA_STO_CLASS and SHA_THREAD_SAFE
+ -- ref. Bug #82784
+ -- thanks to Steve Hay for initial patch
+ - provided documentation to describe Unicode handling
+ -- ref: Bug #82378
+ - updated documentation of NIST statement on SHA-1
+
+5.81 Mon Jan 14 05:17:08 MST 2013
+ - corrected load subroutine (SHA.pm) to prevent double-free
+ -- Bug #82655: Security issue - segfault
+ -- thanks to Victor Efimov and Nicholas Clark
+ for technical expertise and suggestions
+
+5.80 Mon Dec 10 14:15:26 MST 2012
+ - obtained noticeable speedup on Intel/gcc
+ -- by setting -O1 and -fomit-frame-pointer
+ -- SHA-1 about 63% faster, SHA-2 improves 11-20%
+
+5.74 Sat Nov 24 03:10:18 MST 2012
+ - handle wide-string input by converting to bytes first
+ -- viz. use SvPVbyte instead of SvPV in SHA.xs
+ -- thanks to Eric Brine for summary and code
+
+5.73 Wed Oct 31 04:32:44 MST 2012
+ - provided workaround for DEC compiler bug (ref. Makefile.PL)
+
+5.72 Mon Sep 24 15:22:08 MST 2012
+ - adjusted module installation directory for later Perls
+ -- As of 5.11 Perl searches 'site' first, so use that
+ -- ref. INSTALLDIRS in Makefile.PL
+ -- thanks to Robert Sedlacek for patch
+
5.71 Wed Feb 29 04:06:10 MST 2012
- prevented $! from getting clobbered in _bail() routine
-- thanks to Zefram for patch
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/Makefile.PL b/gnu/usr.bin/perl/cpan/Digest-SHA/Makefile.PL
index 400db397728..3d8386563fd 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/Makefile.PL
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/Makefile.PL
@@ -3,28 +3,35 @@ require 5.003000;
use strict;
use ExtUtils::MakeMaker;
use Getopt::Std;
-use Config;
+use Config qw(%Config);
my $PM = 'lib/Digest/SHA.pm';
my %opts;
-getopts('tx', \%opts);
+getopts('tx', \%opts); # -t is no longer used, but allow it anyway
my @defines;
-push(@defines, '-DSHA_PERL_MODULE') if $] >= 5.004;
-push(@defines, '-DSHA_THREAD_SAFE') if $opts{'t'};
+push(@defines, '-DSHA_PerlIO') if $] >= 5.004;
push(@defines, '-DNO_SHA_384_512') if $opts{'x'};
+my $define = join(' ', @defines);
+
+ # Workaround for DEC compiler bug, adapted from Digest::MD5
- # Configure SHA source to use static arrays for
- # message schedules if compiling on Intel platforms.
- # This seems to speed things up a bit. However,
- # DON'T do this if thread-safe option is in force.
-
-if ($Config{archname} =~ /^i[3456]86/) {
- push(@defines, '-DSHA_STO_CLASS=static') unless $opts{'t'};
+my @extra = ();
+if ($^O eq 'VMS') {
+ if (defined($Config{ccname})) {
+ if (grep(/VMS_VAX/, @INC) && ($Config{ccname} eq 'DEC')) {
+ # VAX compiler optimizer even up to v6.4 gets stuck
+ push(@extra, OPTIMIZE => "/Optimize=(NODISJOINT)");
+ }
+ }
}
-my $define = join(' ', @defines);
+ # Enhance performance on Intel when using gcc
+
+if ($Config{archname} =~ /^i[3456]86/ && $Config{ccname} eq 'gcc') {
+ push(@extra, OPTIMIZE => '-O1 -fomit-frame-pointer');
+}
my %att = (
'NAME' => 'Digest::SHA',
@@ -33,7 +40,8 @@ my %att = (
'DEFINE' => $define,
'INC' => '-I.',
'EXE_FILES' => [ 'shasum' ],
- 'INSTALLDIRS' => ($] >= 5.010) ? 'perl' : 'site',
+ 'INSTALLDIRS' => ($] >= 5.010 and $] < 5.011) ? 'perl' : 'site',
+ @extra,
);
my $MMversion = $ExtUtils::MakeMaker::VERSION || 0;
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/README b/gnu/usr.bin/perl/cpan/Digest-SHA/README
index 2478b1ec54e..98317ba4824 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/README
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/README
@@ -1,4 +1,4 @@
-Digest::SHA version 5.71
+Digest::SHA version 5.84
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
@@ -28,13 +28,15 @@ The Makefile.PL options are:
-t : build a thread-safe version of module
-x : exclude support for SHA-384/512
+ NOTE: Option -t is still allowed but no longer necessary.
+
DEPENDENCIES
None
COPYRIGHT AND LICENSE
-Copyright (C) 2003-2012 Mark Shelor
+Copyright (C) 2003-2013 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/gnu/usr.bin/perl/cpan/Digest-SHA/SHA.xs b/gnu/usr.bin/perl/cpan/Digest-SHA/SHA.xs
index 8124a5de70f..47bef28e618 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/SHA.xs
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/SHA.xs
@@ -2,8 +2,17 @@
#include "perl.h"
#include "XSUB.h"
+#ifdef SvPVbyte
+ #if PERL_REVISION == 5 && PERL_VERSION < 8
+ #undef SvPVbyte
+ #define SvPVbyte(sv, lp) \
+ (sv_utf8_downgrade((sv), 0), SvPV((sv), (lp)))
+ #endif
+#else
+ #define SvPVbyte SvPV
+#endif
+
#include "src/sha.c"
-#include "src/hmac.c"
static int ix2alg[] =
{1,1,1,224,224,224,256,256,256,384,384,384,512,512,512,
@@ -13,9 +22,6 @@ MODULE = Digest::SHA PACKAGE = Digest::SHA
PROTOTYPES: ENABLE
-#include "src/sha.h"
-#include "src/hmac.h"
-
#ifndef INT2PTR
#define INT2PTR(p, i) (p) (i)
#endif
@@ -25,6 +31,9 @@ PROTOTYPES: ENABLE
int
shaclose(s)
SHA * s
+CODE:
+ RETVAL = shaclose(s);
+ sv_setiv(SvRV(ST(0)), 0);
int
shadump(file, s)
@@ -87,7 +96,7 @@ PPCODE:
if ((state = shaopen(ix2alg[ix])) == NULL)
XSRETURN_UNDEF;
for (i = 0; i < items; i++) {
- data = (unsigned char *) (SvPV(ST(i), len));
+ data = (unsigned char *) (SvPVbyte(ST(i), len));
while (len > MAX_WRITE_SIZE) {
shawrite(data, MAX_WRITE_SIZE << 3, state);
data += MAX_WRITE_SIZE;
@@ -141,11 +150,11 @@ PREINIT:
HMAC *state;
char *result;
PPCODE:
- key = (unsigned char *) (SvPV(ST(items-1), len));
+ key = (unsigned char *) (SvPVbyte(ST(items-1), len));
if ((state = hmacopen(ix2alg[ix], key, len)) == NULL)
XSRETURN_UNDEF;
for (i = 0; i < items - 1; i++) {
- data = (unsigned char *) (SvPV(ST(i), len));
+ data = (unsigned char *) (SvPVbyte(ST(i), len));
while (len > MAX_WRITE_SIZE) {
hmacwrite(data, MAX_WRITE_SIZE << 3, state);
data += MAX_WRITE_SIZE;
@@ -193,7 +202,7 @@ PREINIT:
PPCODE:
state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self))));
for (i = 1; i < items; i++) {
- data = (unsigned char *) (SvPV(ST(i), len));
+ data = (unsigned char *) (SvPVbyte(ST(i), len));
while (len > MAX_WRITE_SIZE) {
shawrite(data, MAX_WRITE_SIZE << 3, state);
data += MAX_WRITE_SIZE;
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/lib/Digest/SHA.pm b/gnu/usr.bin/perl/cpan/Digest-SHA/lib/Digest/SHA.pm
index d8cc56136be..9a631b1fe9e 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/lib/Digest/SHA.pm
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/lib/Digest/SHA.pm
@@ -7,7 +7,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
use Fcntl;
use integer;
-$VERSION = '5.71';
+$VERSION = '5.84_01';
require Exporter;
require DynaLoader;
@@ -49,8 +49,8 @@ sub new {
sharewind($$class);
return($class);
}
- shaclose($$class) if $$class;
- $$class = shaopen($alg) || return;
+ if ($$class) { shaclose($$class); $$class = undef }
+ return unless $$class = shaopen($alg);
return($class);
}
$alg = 1 unless defined $alg;
@@ -62,7 +62,7 @@ sub new {
sub DESTROY {
my $self = shift;
- shaclose($$self) if $$self;
+ if ($$self) { shaclose($$self); $$self = undef }
}
sub clone {
@@ -163,18 +163,21 @@ sub Addfile {
sub dump {
my $self = shift;
- my $file = shift || "";
+ my $file = shift;
+ $file = "" unless defined $file;
shadump($file, $$self) || return;
return($self);
}
sub load {
my $class = shift;
- my $file = shift || "";
+ my $file = shift;
+
+ $file = "" unless defined $file;
if (ref($class)) { # instance method
- shaclose($$class) if $$class;
- $$class = shaload($file) || return;
+ if ($$class) { shaclose($$class); $$class = undef }
+ return unless $$class = shaload($file);
return($class);
}
my $state = shaload($file) || return;
@@ -321,21 +324,44 @@ I<sha_base64()> functions.
use Digest::SHA qw(hmac_sha256_hex);
print hmac_sha256_hex("Hi There", chr(0x0b) x 32), "\n";
-=head1 NIST STATEMENT ON SHA-1
+=head1 UNICODE AND SIDE EFFECTS
+
+Perl supports Unicode strings as of version 5.6. Such strings may
+contain wide characters, namely, characters whose ordinal values are
+greater than 255. This can cause problems for digest algorithms such
+as SHA that are specified to operate on sequences of bytes.
+
+The rule by which Digest::SHA handles a Unicode string is easy
+to state, but potentially confusing to grasp: the string is interpreted
+as a sequence of byte values, where each byte value is equal to the
+ordinal value (viz. code point) of its corresponding Unicode character.
+That way, the Unicode string 'abc' has exactly the same digest value as
+the ordinary string 'abc'.
+
+Since a wide character does not fit into a byte, the Digest::SHA
+routines croak if they encounter one. Whereas if a Unicode string
+contains no wide characters, the module accepts it quite happily.
+The following code illustrates the two cases:
-I<NIST was recently informed that researchers had discovered a way
-to "break" the current Federal Information Processing Standard SHA-1
-algorithm, which has been in effect since 1994. The researchers
-have not yet published their complete results, so NIST has not
-confirmed these findings. However, the researchers are a reputable
-research team with expertise in this area.>
+ $str1 = pack('U*', (0..255));
+ print sha1_hex($str1); # ok
+
+ $str2 = pack('U*', (0..256));
+ print sha1_hex($str2); # croaks
+
+Be aware that the digest routines silently convert UTF-8 input into its
+equivalent byte sequence in the native encoding (cf. utf8::downgrade).
+This side effect influences only the way Perl stores the data internally,
+but otherwise leaves the actual value of the data intact.
+
+=head1 NIST STATEMENT ON SHA-1
-I<Due to advances in computing power, NIST already planned to phase
-out SHA-1 in favor of the larger and stronger hash functions (SHA-224,
-SHA-256, SHA-384 and SHA-512) by 2010. New developments should use
-the larger and stronger hash functions.>
+NIST acknowledges that the work of Prof. Xiaoyun Wang constitutes a
+practical collision attack on SHA-1. Therefore, NIST encourages the
+rapid adoption of the SHA-2 hash functions (e.g. SHA-256) for applications
+requiring strong collision resistance, such as digital signatures.
-ref. L<http://www.csrc.nist.gov/pki/HashWorkshop/NIST%20Statement/Burr_Mar2005.html>
+ref. L<http://csrc.nist.gov/groups/ST/hash/statement.html>
=head1 PADDING OF BASE64 DIGESTS
@@ -707,7 +733,7 @@ darkness and moored it in so perfect a calm and in so brilliant a light"
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2003-2012 Mark Shelor
+Copyright (C) 2003-2013 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/gnu/usr.bin/perl/cpan/Digest-SHA/shasum b/gnu/usr.bin/perl/cpan/Digest-SHA/shasum
index d75815a3789..11da695c4c2 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/shasum
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/shasum
@@ -2,10 +2,10 @@
## shasum: filter for computing SHA digests (ref. sha1sum/md5sum)
##
- ## Copyright (C) 2003-2012 Mark Shelor, All Rights Reserved
+ ## Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
##
- ## Version: 5.71
- ## Wed Feb 29 04:06:10 MST 2012
+ ## Version: 5.84
+ ## Sat Mar 9 17:36:08 MST 2013
## shasum SYNOPSIS adapted from GNU Coreutils sha1sum.
## Add an "-a" option for algorithm selection, a "-p"
@@ -82,7 +82,7 @@ the 7-bit message I<0001100>:
=head1 AUTHOR
-Copyright (c) 2003-2012 Mark Shelor <mshelor@cpan.org>.
+Copyright (c) 2003-2013 Mark Shelor <mshelor@cpan.org>.
=head1 SEE ALSO
@@ -97,7 +97,7 @@ use strict;
use Fcntl;
use Getopt::Long;
-my $VERSION = "5.71";
+my $VERSION = "5.84";
## Try to use Digest::SHA. If not installed, use the slower
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.c b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.c
index 4aaba5f0a96..6d6fe681091 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.c
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.c
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-2 Secure Hash Standard
*
- * Copyright (C) 2003-2012 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
*
- * Version: 5.71
- * Wed Feb 29 04:06:10 MST 2012
+ * Version: 5.84
+ * Sat Mar 9 17:36:08 MST 2013
*
*/
@@ -86,7 +86,7 @@ static W32 H0256[8] = /* SHA-256 initial hash value */
static void sha1(SHA *s, UCHR *block) /* SHA-1 transform */
{
W32 a, b, c, d, e;
- SHA_STO_CLASS W32 W[16];
+ W32 W[16];
W32 *wp = W;
W32 *H = (W32 *) s->H;
@@ -153,7 +153,7 @@ static void sha1(SHA *s, UCHR *block) /* SHA-1 transform */
static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */
{
W32 a, b, c, d, e, f, g, h, T1;
- SHA_STO_CLASS W32 W[16];
+ W32 W[16];
W32 *kp = K256;
W32 *wp = W;
W32 *H = (W32 *) s->H;
@@ -216,7 +216,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */
#define SETBIT(s, pos) s[(pos) >> 3] |= (0x01 << (7 - (pos) % 8))
#define CLRBIT(s, pos) s[(pos) >> 3] &= ~(0x01 << (7 - (pos) % 8))
-#define NBYTES(nbits) ((nbits) > 0 ? 1 + (((nbits) - 1) >> 3) : 0)
+#define NBYTES(nbits) (((nbits) + 7) >> 3)
#define HEXLEN(nbytes) ((nbytes) << 1)
#define B64LEN(nbytes) (((nbytes) % 3 == 0) ? ((nbytes) / 3) * 4 \
: ((nbytes) / 3) * 4 + ((nbytes) % 3) + 1)
@@ -258,7 +258,7 @@ static void digcpy(SHA *s)
} while (0)
/* sharewind: re-initializes the digest object */
-void sharewind(SHA *s)
+static void sharewind(SHA *s)
{
if (s->alg == SHA1) SHA_INIT(1, 1);
else if (s->alg == SHA224) SHA_INIT(224, 256);
@@ -270,9 +270,9 @@ void sharewind(SHA *s)
}
/* shaopen: creates a new digest object */
-SHA *shaopen(int alg)
+static SHA *shaopen(int alg)
{
- SHA *s;
+ SHA *s = NULL;
if (alg != SHA1 && alg != SHA224 && alg != SHA256 &&
alg != SHA384 && alg != SHA512 &&
@@ -288,6 +288,16 @@ SHA *shaopen(int alg)
return(s);
}
+/* shaclose: de-allocates digest object */
+static int shaclose(SHA *s)
+{
+ if (s != NULL) {
+ memset(s, 0, sizeof(SHA));
+ SHA_free(s);
+ }
+ return(0);
+}
+
/* shadirect: updates state directly (w/o going through s->block) */
static ULNG shadirect(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
@@ -365,7 +375,7 @@ static ULNG shabits(UCHR *bitstr, ULNG bitcnt, SHA *s)
}
/* shawrite: triggers a state update using data in bitstr/bitcnt */
-ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s)
+static ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
if (bitcnt < 1)
return(0);
@@ -382,7 +392,7 @@ ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s)
}
/* shafinish: pads remaining block(s) and computes final digest state */
-void shafinish(SHA *s)
+static void shafinish(SHA *s)
{
UINT lenpos, lhpos, llpos;
@@ -407,14 +417,14 @@ void shafinish(SHA *s)
}
/* shadigest: returns pointer to current digest (binary) */
-UCHR *shadigest(SHA *s)
+static UCHR *shadigest(SHA *s)
{
digcpy(s);
return(s->digest);
}
/* shahex: returns pointer to current digest (hexadecimal) */
-char *shahex(SHA *s)
+static char *shahex(SHA *s)
{
int i;
@@ -448,7 +458,7 @@ static void encbase64(UCHR *in, int n, char *out)
}
/* shabase64: returns pointer to current digest (Base 64) */
-char *shabase64(SHA *s)
+static char *shabase64(SHA *s)
{
int n;
UCHR *q;
@@ -456,7 +466,7 @@ char *shabase64(SHA *s)
digcpy(s);
s->base64[0] = '\0';
- if (B64LEN(s->digestlen) >= sizeof(s->base64))
+ if (B64LEN((size_t) s->digestlen) >= sizeof(s->base64))
return(s->base64);
for (n = s->digestlen, q = s->digest; n > 3; n -= 3, q += 3) {
encbase64(q, 3, out);
@@ -468,19 +478,19 @@ char *shabase64(SHA *s)
}
/* shadsize: returns length of digest in bytes */
-int shadsize(SHA *s)
+static int shadsize(SHA *s)
{
return(s->digestlen);
}
/* shaalg: returns which SHA algorithm is being used */
-int shaalg(SHA *s)
+static int shaalg(SHA *s)
{
return(s->alg);
}
/* shadup: duplicates current digest object */
-SHA *shadup(SHA *s)
+static SHA *shadup(SHA *s)
{
SHA *p;
@@ -492,7 +502,7 @@ SHA *shadup(SHA *s)
}
/* shadump: dumps digest object to a human-readable ASCII file */
-int shadump(char *file, SHA *s)
+static int shadump(char *file, SHA *s)
{
int i, j;
SHA_FILE *f;
@@ -608,7 +618,7 @@ static SHA *closeall(SHA_FILE *f, SHA *s)
}
/* shaload: creates digest object corresponding to contents of dump file */
-SHA *shaload(char *file)
+static SHA *shaload(char *file)
{
int alg;
SHA *s = NULL;
@@ -638,12 +648,88 @@ SHA *shaload(char *file)
return(s);
}
-/* shaclose: de-allocates digest object */
-int shaclose(SHA *s)
+/* hmacopen: creates a new HMAC-SHA digest object */
+static HMAC *hmacopen(int alg, UCHR *key, UINT keylen)
{
- if (s != NULL) {
- memset(s, 0, sizeof(SHA));
- SHA_free(s);
+ UINT i;
+ HMAC *h;
+
+ SHA_newz(0, h, 1, HMAC);
+ if (h == NULL)
+ return(NULL);
+ if ((h->isha = shaopen(alg)) == NULL) {
+ SHA_free(h);
+ return(NULL);
+ }
+ if ((h->osha = shaopen(alg)) == NULL) {
+ shaclose(h->isha);
+ SHA_free(h);
+ return(NULL);
+ }
+ if (keylen <= h->osha->blocksize / 8)
+ memcpy(h->key, key, keylen);
+ else {
+ if ((h->ksha = shaopen(alg)) == NULL) {
+ shaclose(h->isha);
+ shaclose(h->osha);
+ SHA_free(h);
+ return(NULL);
+ }
+ shawrite(key, keylen * 8, h->ksha);
+ shafinish(h->ksha);
+ memcpy(h->key, shadigest(h->ksha), h->ksha->digestlen);
+ shaclose(h->ksha);
+ }
+ for (i = 0; i < h->osha->blocksize / 8; i++)
+ h->key[i] ^= 0x5c;
+ shawrite(h->key, h->osha->blocksize, h->osha);
+ for (i = 0; i < h->isha->blocksize / 8; i++)
+ h->key[i] ^= (0x5c ^ 0x36);
+ shawrite(h->key, h->isha->blocksize, h->isha);
+ memset(h->key, 0, sizeof(h->key));
+ return(h);
+}
+
+/* hmacwrite: triggers a state update using data in bitstr/bitcnt */
+static ULNG hmacwrite(UCHR *bitstr, ULNG bitcnt, HMAC *h)
+{
+ return(shawrite(bitstr, bitcnt, h->isha));
+}
+
+/* hmacfinish: computes final digest state */
+static void hmacfinish(HMAC *h)
+{
+ shafinish(h->isha);
+ shawrite(shadigest(h->isha), h->isha->digestlen * 8, h->osha);
+ shaclose(h->isha);
+ shafinish(h->osha);
+}
+
+/* hmacdigest: returns pointer to digest (binary) */
+static UCHR *hmacdigest(HMAC *h)
+{
+ return(shadigest(h->osha));
+}
+
+/* hmachex: returns pointer to digest (hexadecimal) */
+static char *hmachex(HMAC *h)
+{
+ return(shahex(h->osha));
+}
+
+/* hmacbase64: returns pointer to digest (Base 64) */
+static char *hmacbase64(HMAC *h)
+{
+ return(shabase64(h->osha));
+}
+
+/* hmacclose: de-allocates digest object */
+static int hmacclose(HMAC *h)
+{
+ if (h != NULL) {
+ shaclose(h->osha);
+ memset(h, 0, sizeof(HMAC));
+ SHA_free(h);
}
return(0);
}
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.h b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.h
index 1c80dbc9783..fb7279eee8c 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.h
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha.h
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-2 Secure Hash Standard
*
- * Copyright (C) 2003-2012 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
*
- * Version: 5.71
- * Wed Feb 29 04:06:10 MST 2012
+ * Version: 5.84
+ * Sat Mar 9 17:36:08 MST 2013
*
*/
@@ -102,27 +102,11 @@
(SHA64) b[6] << 8 | (SHA64) b[7]; }
#endif
-/*
- * SHA_STO_CLASS: default to auto storage class for message schedule
- * arrays inside transform routines. Note that redefining this to
- * static might improve performance on some platforms (e.g. Intel).
- */
-
-#if !defined(SHA_STO_CLASS)
- #define SHA_STO_CLASS auto
-#endif
+#define SHA_new New
+#define SHA_newz Newz
+#define SHA_free Safefree
-/* Override use of static arrays if compiling for thread-safety */
-#ifdef SHA_THREAD_SAFE
- #undef SHA_STO_CLASS
- #define SHA_STO_CLASS auto
-#endif
-
-/* Configure memory management and I/O for Perl or standalone C */
-#ifdef SHA_PERL_MODULE
- #define SHA_new New
- #define SHA_newz Newz
- #define SHA_free Safefree
+#ifdef SHA_PerlIO
#define SHA_FILE PerlIO
#define SHA_stdin() PerlIO_stdin()
#define SHA_stdout() PerlIO_stdout()
@@ -132,9 +116,6 @@
#define SHA_feof PerlIO_eof
#define SHA_getc PerlIO_getc
#else
- #define SHA_new(id, p, n, t) p = (t *) malloc(sizeof(t))
- #define SHA_newz(id, p, n, t) p = (t *) calloc(n, sizeof(t))
- #define SHA_free free
#define SHA_FILE FILE
#define SHA_stdin() stdin
#define SHA_stdout() stdout
@@ -194,53 +175,11 @@ typedef struct SHA {
char base64[SHA_MAX_BASE64_LEN+1];
} SHA;
-#define SHA_FMT_RAW 1
-#define SHA_FMT_HEX 2
-#define SHA_FMT_BASE64 3
-
-#define _SHA_STATE SHA *s
-#define _SHA_ALG int alg
-#define _SHA_DATA unsigned char *bitstr, unsigned long bitcnt
-#define _SHA_FNAME char *filename
-
-SHA *shaopen (_SHA_ALG);
-unsigned long shawrite (_SHA_DATA, _SHA_STATE);
-void shafinish (_SHA_STATE);
-void sharewind (_SHA_STATE);
-unsigned char *shadigest (_SHA_STATE);
-char *shahex (_SHA_STATE);
-char *shabase64 (_SHA_STATE);
-int shadsize (_SHA_STATE);
-int shaalg (_SHA_STATE);
-SHA *shadup (_SHA_STATE);
-int shadump (_SHA_FNAME, _SHA_STATE);
-SHA *shaload (_SHA_FNAME);
-int shaclose (_SHA_STATE);
-
-#ifndef SHA_PERL_MODULE
-
-unsigned char *sha1digest (_SHA_DATA);
-char *sha1hex (_SHA_DATA);
-char *sha1base64 (_SHA_DATA);
-unsigned char *sha224digest (_SHA_DATA);
-char *sha224hex (_SHA_DATA);
-char *sha224base64 (_SHA_DATA);
-unsigned char *sha256digest (_SHA_DATA);
-char *sha256hex (_SHA_DATA);
-char *sha256base64 (_SHA_DATA);
-unsigned char *sha384digest (_SHA_DATA);
-char *sha384hex (_SHA_DATA);
-char *sha384base64 (_SHA_DATA);
-unsigned char *sha512digest (_SHA_DATA);
-char *sha512hex (_SHA_DATA);
-char *sha512base64 (_SHA_DATA);
-unsigned char *sha512224digest (_SHA_DATA);
-char *sha512224hex (_SHA_DATA);
-char *sha512224base64 (_SHA_DATA);
-unsigned char *sha512256digest (_SHA_DATA);
-char *sha512256hex (_SHA_DATA);
-char *sha512256base64 (_SHA_DATA);
-
-#endif
+typedef struct {
+ SHA *ksha;
+ SHA *isha;
+ SHA *osha;
+ unsigned char key[SHA_MAX_BLOCK_BITS/8];
+} HMAC;
#endif /* _INCLUDE_SHA_H_ */
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha64bit.c b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha64bit.c
index b37d6f3c09b..6c9096670f3 100644
--- a/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha64bit.c
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/src/sha64bit.c
@@ -95,7 +95,7 @@ static W64 strto64(char *s)
static void sha512(SHA *s, unsigned char *block) /* SHA-384/512 transform */
{
W64 a, b, c, d, e, f, g, h, T1, T2;
- SHA_STO_CLASS W64 W[80];
+ W64 W[80];
W64 *H = (W64 *) s->H;
int t;
diff --git a/gnu/usr.bin/perl/cpan/Digest-SHA/t/unicode.t b/gnu/usr.bin/perl/cpan/Digest-SHA/t/unicode.t
new file mode 100644
index 00000000000..1e7bd13d531
--- /dev/null
+++ b/gnu/usr.bin/perl/cpan/Digest-SHA/t/unicode.t
@@ -0,0 +1,43 @@
+use strict;
+
+my $MODULE;
+
+BEGIN {
+ $MODULE = (-d "src") ? "Digest::SHA" : "Digest::SHA::PurePerl";
+ eval "require $MODULE" || die $@;
+ $MODULE->import(qw(sha1_hex));
+}
+
+BEGIN {
+ if ($ENV{PERL_CORE}) {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ }
+}
+
+my $skip = $] < 5.006 ? 1 : 0;
+
+my $TEMPLATE = $] >= 5.006 ? 'U*' : 'C*';
+my $empty_unicode = pack($TEMPLATE, ());
+my $ok_unicode = pack($TEMPLATE, (0..255));
+my $wide_unicode = pack($TEMPLATE, (0..256));
+
+print "1..3\n";
+
+unless ($skip) {
+ print "not " unless sha1_hex($empty_unicode."abc") eq
+ "a9993e364706816aba3e25717850c26c9cd0d89d";
+}
+print "ok 1", $skip ? " # skip: no Unicode" : "", "\n";
+
+unless ($skip) {
+ print "not " unless sha1_hex($ok_unicode) eq
+ "4916d6bdb7f78e6803698cab32d1586ea457dfc8";
+}
+print "ok 2", $skip ? " # skip: no Unicode" : "", "\n";
+
+unless ($skip) {
+ eval { sha1_hex($wide_unicode) };
+ print "not " unless $@ =~ /Wide character/;
+}
+print "ok 3", $skip ? " # skip: no Unicode" : "", "\n";