diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2015-01-10 11:59:43 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2015-01-10 11:59:43 +0000 |
commit | 24278fc491f4ba7178a5908dcc9e84b962520a65 (patch) | |
tree | 7fbc715026138b54e4c26d07166e7dbf1d7be9f4 /cpan | |
parent | 0fcb6a367491789c4ba3a99744c5373751a9aa56 (diff) | |
download | perl-24278fc491f4ba7178a5908dcc9e84b962520a65.tar.gz |
Update Digest-SHA to CPAN version 5.94
[DELTA]
5.94 Sat Jan 10 00:45:28 MST 2015
- added support for threaded builds
-- PERL_GET_NO_CONTEXT, pTHX_, aTHX_, etc.
-- employed 'const' storage class where possible
-- ref. rt.cpan.org #101260
- simplified shabits() routine (bitwise input buffering)
-- slightly less efficient but easier to understand
-- ref. rt.cpan.org #101344
- minor documentation tweaks and additions
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/Digest-SHA/SHA.xs | 26 | ||||
-rw-r--r-- | cpan/Digest-SHA/lib/Digest/SHA.pm | 13 | ||||
-rw-r--r-- | cpan/Digest-SHA/shasum | 10 | ||||
-rw-r--r-- | cpan/Digest-SHA/src/sha.c | 63 | ||||
-rw-r--r-- | cpan/Digest-SHA/src/sha.h | 6 | ||||
-rw-r--r-- | cpan/Digest-SHA/src/sha64bit.c | 16 | ||||
-rw-r--r-- | cpan/Digest-SHA/src/sha64bit.h | 8 | ||||
-rw-r--r-- | cpan/Digest-SHA/t/bit-order.t | 15 | ||||
-rw-r--r-- | cpan/Digest-SHA/typemap | 2 |
9 files changed, 84 insertions, 75 deletions
diff --git a/cpan/Digest-SHA/SHA.xs b/cpan/Digest-SHA/SHA.xs index 30fdb858ae..0a0c89d4e3 100644 --- a/cpan/Digest-SHA/SHA.xs +++ b/cpan/Digest-SHA/SHA.xs @@ -1,3 +1,4 @@ +#define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -12,6 +13,11 @@ #define SvPVbyte SvPV #endif +#ifndef dTHX + #define pTHX_ + #define aTHX_ +#endif + #ifndef PerlIO #define PerlIO FILE #define PerlIO_read(f, buf, count) fread(buf, 1, count, f) @@ -28,7 +34,7 @@ #include "src/sha.c" -static int ix2alg[] = +static const int ix2alg[] = {1,1,1,224,224,224,256,256,256,384,384,384,512,512,512, 512224,512224,512224,512256,512256,512256}; @@ -39,7 +45,7 @@ static int ix2alg[] = #define MAX_WRITE_SIZE 16384 #define IO_BUFFER_SIZE 4096 -static SHA *getSHA(SV *self) +static SHA *getSHA(pTHX_ SV *self) { if (!sv_isobject(self) || !sv_derived_from(self, "Digest::SHA")) return(NULL); @@ -90,7 +96,7 @@ PREINIT: SHA *state; SHA *clone; CODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; Newx(clone, 1, SHA); RETVAL = newSV(0); @@ -231,7 +237,7 @@ ALIAS: PREINIT: SHA *state; CODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; RETVAL = ix ? state->alg : (int) (state->digestlen << 3); OUTPUT: @@ -246,7 +252,7 @@ PREINIT: STRLEN len; SHA *state; PPCODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; for (i = 1; i < items; i++) { data = (UCHR *) (SvPVbyte(ST(i), len)); @@ -271,7 +277,7 @@ PREINIT: SHA *state; char *result; CODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; shafinish(state); len = 0; @@ -296,7 +302,7 @@ PREINIT: UCHR buf[256]; UCHR *ptr = buf; CODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; Copy(digcpy(state), ptr, state->alg <= SHA256 ? 32 : 64, UCHR); ptr += state->alg <= SHA256 ? 32 : 64; @@ -321,7 +327,7 @@ PREINIT: SHA *state; UCHR *data; PPCODE: - if ((state = getSHA(self)) == NULL) + if ((state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; data = (UCHR *) SvPV(packed_state, len); if (len != (state->alg <= SHA256 ? 116U : 212U)) @@ -348,7 +354,7 @@ PREINIT: int n; UCHR in[IO_BUFFER_SIZE]; PPCODE: - if (!f || (state = getSHA(self)) == NULL) + if (!f || (state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; while ((n = PerlIO_read(f, in, sizeof(in))) > 0) shawrite(in, (ULNG) n << 3, state); @@ -366,7 +372,7 @@ PREINIT: UCHR in[IO_BUFFER_SIZE+1]; SHA *state; PPCODE: - if (!f || (state = getSHA(self)) == NULL) + if (!f || (state = getSHA(aTHX_ self)) == NULL) XSRETURN_UNDEF; while ((n = PerlIO_read(f, in+1, IO_BUFFER_SIZE)) > 0) { for (dst = in, src = in + 1; n; n--) { diff --git a/cpan/Digest-SHA/lib/Digest/SHA.pm b/cpan/Digest-SHA/lib/Digest/SHA.pm index 83906df06d..bbc1e229d7 100644 --- a/cpan/Digest-SHA/lib/Digest/SHA.pm +++ b/cpan/Digest-SHA/lib/Digest/SHA.pm @@ -8,7 +8,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Fcntl; use integer; -$VERSION = '5.93'; +$VERSION = '5.94'; require Exporter; require DynaLoader; @@ -588,6 +588,15 @@ So, the following two statements do the same thing: $sha->add_bits("111100001010"); $sha->add_bits("\xF0\xA0", 12); +Note that SHA-1 and SHA-2 use I<most-significant-bit ordering> +for their internal state. This means that + + $sha3->add_bits("110"); + +is equivalent to + + $sha3->add_bits("1")->add_bits("1")->add_bits("0"); + =item B<addfile(*FILE)> Reads from I<FILE> until EOF, and appends that data to the current @@ -804,7 +813,7 @@ darkness and moored it in so perfect a calm and in so brilliant a light" =head1 COPYRIGHT AND LICENSE -Copyright (C) 2003-2014 Mark Shelor +Copyright (C) 2003-2015 Mark Shelor This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/cpan/Digest-SHA/shasum b/cpan/Digest-SHA/shasum index c28d70dbe7..0a1256254d 100644 --- a/cpan/Digest-SHA/shasum +++ b/cpan/Digest-SHA/shasum @@ -2,10 +2,10 @@ ## shasum: filter for computing SHA digests (ref. sha1sum/md5sum) ## - ## Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved + ## Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved ## - ## Version: 5.93 - ## Sun Oct 26 06:00:48 MST 2014 + ## Version: 5.94 + ## Sat Jan 10 00:45:28 MST 2015 ## shasum SYNOPSIS adapted from GNU Coreutils sha1sum. Add ## "-a" option for algorithm selection, @@ -90,7 +90,7 @@ the 7-bit message I<0001100>: =head1 AUTHOR -Copyright (c) 2003-2014 Mark Shelor <mshelor@cpan.org>. +Copyright (c) 2003-2015 Mark Shelor <mshelor@cpan.org>. =head1 SEE ALSO @@ -101,7 +101,7 @@ L<Digest::SHA::PurePerl>. END_OF_POD -my $VERSION = "5.93"; +my $VERSION = "5.94"; sub usage { my($err, $msg) = @_; diff --git a/cpan/Digest-SHA/src/sha.c b/cpan/Digest-SHA/src/sha.c index 375696992d..c0daaaa6bd 100644 --- a/cpan/Digest-SHA/src/sha.c +++ b/cpan/Digest-SHA/src/sha.c @@ -3,10 +3,10 @@ * * Ref: NIST FIPS PUB 180-4 Secure Hash Standard * - * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved + * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved * - * Version: 5.93 - * Sun Oct 26 06:00:48 MST 2014 + * Version: 5.94 + * Sat Jan 10 00:45:28 MST 2015 * */ @@ -45,7 +45,7 @@ #define K3 C32(0x8f1bbcdc) #define K4 C32(0xca62c1d6) -static W32 K256[64] = /* SHA-224/256 constants */ +static const W32 K256[64] = /* SHA-224/256 constants */ { C32(0x428a2f98), C32(0x71374491), C32(0xb5c0fbcf), C32(0xe9b5dba5), C32(0x3956c25b), C32(0x59f111f1), C32(0x923f82a4), C32(0xab1c5ed5), @@ -65,19 +65,19 @@ static W32 K256[64] = /* SHA-224/256 constants */ C32(0x90befffa), C32(0xa4506ceb), C32(0xbef9a3f7), C32(0xc67178f2) }; -static W32 H01[8] = /* SHA-1 initial hash value */ +static const W32 H01[8] = /* SHA-1 initial hash value */ { C32(0x67452301), C32(0xefcdab89), C32(0x98badcfe), C32(0x10325476), C32(0xc3d2e1f0), C32(0x00000000), C32(0x00000000), C32(0x00000000) }; -static W32 H0224[8] = /* SHA-224 initial hash value */ +static const W32 H0224[8] = /* SHA-224 initial hash value */ { C32(0xc1059ed8), C32(0x367cd507), C32(0x3070dd17), C32(0xf70e5939), C32(0xffc00b31), C32(0x68581511), C32(0x64f98fa7), C32(0xbefa4fa4) }; -static W32 H0256[8] = /* SHA-256 initial hash value */ +static const W32 H0256[8] = /* SHA-256 initial hash value */ { C32(0x6a09e667), C32(0xbb67ae85), C32(0x3c6ef372), C32(0xa54ff53a), C32(0x510e527f), C32(0x9b05688c), C32(0x1f83d9ab), C32(0x5be0cd19) @@ -154,7 +154,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */ { W32 a, b, c, d, e, f, g, h, T1; W32 W[16]; - W32 *kp = K256; + const W32 *kp = K256; W32 *wp = W; W32 *H = s->H32; @@ -214,6 +214,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */ #include "sha64bit.c" +#define BITSET(s, pos) s[(pos) >> 3] & (UCHR) (0x01 << (7 - (pos) % 8)) #define SETBIT(s, pos) s[(pos) >> 3] |= (UCHR) (0x01 << (7 - (pos) % 8)) #define CLRBIT(s, pos) s[(pos) >> 3] &= (UCHR) ~(0x01 << (7 - (pos) % 8)) #define NBYTES(nbits) (((nbits) + 7) >> 3) @@ -359,45 +360,23 @@ static ULNG shabytes(UCHR *bitstr, ULNG bitcnt, SHA *s) /* shabits: updates state for bit-aligned data in s->block */ static ULNG shabits(UCHR *bitstr, ULNG bitcnt, SHA *s) { - UINT i; - UINT gap; - ULNG nbits; - UCHR buf[1<<9]; - UINT bufsize = sizeof(buf); - ULNG bufbits = (ULNG) bufsize << 3; - UINT nbytes = NBYTES(bitcnt); - ULNG savecnt = bitcnt; + ULNG i; - gap = 8 - s->blockcnt % 8; - s->block[s->blockcnt>>3] &= (UCHR) (~0 << gap); - s->block[s->blockcnt>>3] |= (UCHR) (*bitstr >> (8 - gap)); - s->blockcnt += bitcnt < gap ? bitcnt : gap; - if (bitcnt < gap) - return(savecnt); - if (s->blockcnt == s->blocksize) - s->sha(s, s->block), s->blockcnt = 0; - if ((bitcnt -= gap) == 0) - return(savecnt); - while (nbytes > bufsize) { - for (i = 0; i < bufsize; i++) - buf[i] = (UCHR) (bitstr[i] << gap) | - (UCHR) (bitstr[i+1] >> (8-gap)); - nbits = bitcnt < bufbits ? bitcnt : bufbits; - shabytes(buf, nbits, s); - bitcnt -= nbits, bitstr += bufsize, nbytes -= bufsize; + for (i = 0UL; i < bitcnt; i++) { + if (BITSET(bitstr, i)) + SETBIT(s->block, s->blockcnt), s->blockcnt++; + else + CLRBIT(s->block, s->blockcnt), s->blockcnt++; + if (s->blockcnt == s->blocksize) + s->sha(s, s->block), s->blockcnt = 0; } - for (i = 0; i < nbytes - 1; i++) - buf[i] = (UCHR) (bitstr[i] << gap) | - (UCHR) (bitstr[i+1] >> (8-gap)); - buf[nbytes-1] = (UCHR) (bitstr[nbytes-1] << gap); - shabytes(buf, bitcnt, s); - return(savecnt); + return(bitcnt); } /* shawrite: triggers a state update using data in bitstr/bitcnt */ static ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s) { - if (bitcnt < 1) + if (!bitcnt) return(0); if (SHA_LO32(s->lenll += bitcnt) < bitcnt) if (SHA_LO32(++s->lenlh) == 0) @@ -439,7 +418,7 @@ static void shafinish(SHA *s) #define shadigest(state) digcpy(state) /* xmap: translation map for hexadecimal encoding */ -static char xmap[] = +static const char xmap[] = "0123456789abcdef"; /* shahex: returns pointer to current digest (hexadecimal) */ @@ -462,7 +441,7 @@ static char *shahex(SHA *s) } /* bmap: translation map for Base 64 encoding */ -static char bmap[] = +static const char bmap[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* encbase64: encodes input (0 to 3 bytes) into Base 64 */ diff --git a/cpan/Digest-SHA/src/sha.h b/cpan/Digest-SHA/src/sha.h index 61f365e40c..5901811b29 100644 --- a/cpan/Digest-SHA/src/sha.h +++ b/cpan/Digest-SHA/src/sha.h @@ -3,10 +3,10 @@ * * Ref: NIST FIPS PUB 180-4 Secure Hash Standard * - * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved + * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved * - * Version: 5.93 - * Sun Oct 26 06:00:48 MST 2014 + * Version: 5.94 + * Sat Jan 10 00:45:28 MST 2015 * */ diff --git a/cpan/Digest-SHA/src/sha64bit.c b/cpan/Digest-SHA/src/sha64bit.c index add57e0d06..d5a6a6fb4a 100644 --- a/cpan/Digest-SHA/src/sha64bit.c +++ b/cpan/Digest-SHA/src/sha64bit.c @@ -3,10 +3,10 @@ * * Ref: NIST FIPS PUB 180-4 Secure Hash Standard * - * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved + * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved * - * Version: 5.93 - * Sun Oct 26 06:00:48 MST 2014 + * Version: 5.94 + * Sat Jan 10 00:45:28 MST 2015 * */ @@ -33,7 +33,7 @@ #define sigmaQ0(x) (ROTRQ(x, 1) ^ ROTRQ(x, 8) ^ SR64(x, 7)) #define sigmaQ1(x) (ROTRQ(x, 19) ^ ROTRQ(x, 61) ^ SR64(x, 6)) -static W64 K512[80] = /* SHA-384/512 constants */ +static const W64 K512[80] = /* SHA-384/512 constants */ { C64(0x428a2f98d728ae22), C64(0x7137449123ef65cd), C64(0xb5c0fbcfec4d3b2f), C64(0xe9b5dba58189dbbc), C64(0x3956c25bf348b538), C64(0x59f111f1b605d019), @@ -64,28 +64,28 @@ C64(0x431d67c49c100d4c), C64(0x4cc5d4becb3e42b6), C64(0x597f299cfc657e2a), C64(0x5fcb6fab3ad6faec), C64(0x6c44198c4a475817) }; -static W64 H0384[8] = /* SHA-384 initial hash value */ +static const W64 H0384[8] = /* SHA-384 initial hash value */ { C64(0xcbbb9d5dc1059ed8), C64(0x629a292a367cd507), C64(0x9159015a3070dd17), C64(0x152fecd8f70e5939), C64(0x67332667ffc00b31), C64(0x8eb44a8768581511), C64(0xdb0c2e0d64f98fa7), C64(0x47b5481dbefa4fa4) }; -static W64 H0512[8] = /* SHA-512 initial hash value */ +static const W64 H0512[8] = /* SHA-512 initial hash value */ { C64(0x6a09e667f3bcc908), C64(0xbb67ae8584caa73b), C64(0x3c6ef372fe94f82b), C64(0xa54ff53a5f1d36f1), C64(0x510e527fade682d1), C64(0x9b05688c2b3e6c1f), C64(0x1f83d9abfb41bd6b), C64(0x5be0cd19137e2179) }; -static W64 H0512224[8] = /* SHA-512/224 initial hash value */ +static const W64 H0512224[8] = /* SHA-512/224 initial hash value */ { C64(0x8c3d37c819544da2), C64(0x73e1996689dcd4d6), C64(0x1dfab7ae32ff9c82), C64(0x679dd514582f9fcf), C64(0x0f6d2b697bd44da8), C64(0x77e36f7304c48942), C64(0x3f9d85a86a1d36c8), C64(0x1112e6ad91d692a1) }; -static W64 H0512256[8] = /* SHA-512/256 initial hash value */ +static const W64 H0512256[8] = /* SHA-512/256 initial hash value */ { C64(0x22312194fc2bf72c), C64(0x9f555fa3c84c64c2), C64(0x2393b86b6f53b151), C64(0x963877195940eabd), C64(0x96283ee2a88effe3), C64(0xbe5e1e2553863992), diff --git a/cpan/Digest-SHA/src/sha64bit.h b/cpan/Digest-SHA/src/sha64bit.h index 01dadc546e..573594bddd 100644 --- a/cpan/Digest-SHA/src/sha64bit.h +++ b/cpan/Digest-SHA/src/sha64bit.h @@ -3,10 +3,10 @@ * * Ref: NIST FIPS PUB 180-4 Secure Hash Standard * - * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved + * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved * - * Version: 5.93 - * Sun Oct 26 06:00:48 MST 2014 + * Version: 5.94 + * Sat Jan 10 00:45:28 MST 2015 * * The following macros supply placeholder values that enable the * sha.c module to successfully compile when 64-bit integer types @@ -18,7 +18,7 @@ */ #define sha_384_512 0 -#define W64 SHA32 +#define W64 SHA64 #define sha512 NULL #define H0384 H01 #define H0512 H01 diff --git a/cpan/Digest-SHA/t/bit-order.t b/cpan/Digest-SHA/t/bit-order.t new file mode 100644 index 0000000000..5dd2ebceed --- /dev/null +++ b/cpan/Digest-SHA/t/bit-order.t @@ -0,0 +1,15 @@ +use strict; +use Digest::SHA; + +my $s1 = Digest::SHA->new; +my $s2 = Digest::SHA->new; +my $d1 = $s1->add_bits("110")->hexdigest; +my $d2 = $s2->add_bits("1")->add_bits("1")->add_bits("0")->hexdigest; + +my $numtests = 1; +print "1..$numtests\n"; + +for (1 .. $numtests) { + print "not " unless $d1 eq $d2; + print "ok ", $_, "\n"; +} diff --git a/cpan/Digest-SHA/typemap b/cpan/Digest-SHA/typemap index b881a1d471..8a4749914c 100644 --- a/cpan/Digest-SHA/typemap +++ b/cpan/Digest-SHA/typemap @@ -4,4 +4,4 @@ PerlIO * T_IN INPUT T_SHA - $var = getSHA($arg) + $var = getSHA(aTHX_ $arg) |