diff options
author | Karl Williamson <khw@cpan.org> | 2014-05-28 19:19:03 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-05-28 19:30:07 -0600 |
commit | c2de4d02ec9abcb746fff0e08aa79b17a217dbfa (patch) | |
tree | 310bc89ab772f928625501c13a3ef888dda3091f /cpan/Digest-SHA/SHA.xs | |
parent | 663bce880acdd4bee8f6d5b50dbb3fee75e1d0ec (diff) | |
download | perl-c2de4d02ec9abcb746fff0e08aa79b17a217dbfa.tar.gz |
Revert "Upgrade Digest::SHA from version 5.88 to 5.91"
This reverts commit d3013bbfc3b14e06bdc794c44d15e95024343369,
because it is breaking blead compiles of C++ because it is using 'class'
as a formal parameter, and that is a reserved word in C++
Diffstat (limited to 'cpan/Digest-SHA/SHA.xs')
-rw-r--r-- | cpan/Digest-SHA/SHA.xs | 268 |
1 files changed, 79 insertions, 189 deletions
diff --git a/cpan/Digest-SHA/SHA.xs b/cpan/Digest-SHA/SHA.xs index 7200a6260b..c38fcc4d9d 100644 --- a/cpan/Digest-SHA/SHA.xs +++ b/cpan/Digest-SHA/SHA.xs @@ -12,47 +12,37 @@ #define SvPVbyte SvPV #endif -#ifndef PerlIO - #define PerlIO FILE - #define PerlIO_read(f, buf, count) fread(buf, 1, count, f) -#endif - -#ifndef sv_derived_from - #include "src/sdf.c" -#endif - -#ifndef Newx - #define Newx(ptr, num, type) New(0, ptr, num, type) - #define Newxz(ptr, num, type) Newz(0, ptr, num, type) -#endif - #include "src/sha.c" static int ix2alg[] = {1,1,1,224,224,224,256,256,256,384,384,384,512,512,512, 512224,512224,512224,512256,512256,512256}; +MODULE = Digest::SHA PACKAGE = Digest::SHA + +PROTOTYPES: ENABLE + #ifndef INT2PTR #define INT2PTR(p, i) (p) (i) #endif #define MAX_WRITE_SIZE 16384 -#define IO_BUFFER_SIZE 4096 - -static SHA *getSHA(SV *self) -{ - if (!sv_isobject(self) || !sv_derived_from(self, "Digest::SHA")) - return(NULL); - return INT2PTR(SHA *, SvIV(SvRV(self))); -} - -MODULE = Digest::SHA PACKAGE = Digest::SHA - -PROTOTYPES: ENABLE int -shainit(s, alg) +shaclose(s) + SHA * s +CODE: + RETVAL = shaclose(s); + sv_setiv(SvRV(ST(0)), 0); +OUTPUT: + RETVAL + +SHA * +shadup(s) SHA * s + +SHA * +shaopen(alg) int alg void @@ -65,48 +55,7 @@ shawrite(bitstr, bitcnt, s) unsigned long bitcnt SHA * s -SV * -newSHA(class, alg) - char * class - int alg -PREINIT: - SHA *state; -CODE: - Newxz(state, 1, SHA); - if (!shainit(state, alg)) { - Safefree(state); - XSRETURN_UNDEF; - } - RETVAL = newSV(0); - sv_setref_pv(RETVAL, class, (void *) state); - SvREADONLY_on(SvRV(RETVAL)); -OUTPUT: - RETVAL - -SV * -clone(self) - SV * self -PREINIT: - SHA *state; - SHA *clone; -CODE: - if ((state = getSHA(self)) == NULL) - XSRETURN_UNDEF; - Newx(clone, 1, SHA); - RETVAL = newSV(0); - sv_setref_pv(RETVAL, sv_reftype(SvRV(self), 1), (void *) clone); - SvREADONLY_on(SvRV(RETVAL)); - Copy(state, clone, 1, SHA); -OUTPUT: - RETVAL - void -DESTROY(s) - SHA * s -CODE: - Safefree(s); - -SV * sha1(...) ALIAS: Digest::SHA::sha1 = 0 @@ -134,35 +83,35 @@ PREINIT: int i; UCHR *data; STRLEN len; - SHA sha; + SHA *state; char *result; -CODE: - if (!shainit(&sha, ix2alg[ix])) +PPCODE: + if ((state = shaopen(ix2alg[ix])) == NULL) XSRETURN_UNDEF; for (i = 0; i < items; i++) { data = (UCHR *) (SvPVbyte(ST(i), len)); while (len > MAX_WRITE_SIZE) { - shawrite(data, MAX_WRITE_SIZE << 3, &sha); + shawrite(data, MAX_WRITE_SIZE << 3, state); data += MAX_WRITE_SIZE; len -= MAX_WRITE_SIZE; } - shawrite(data, len << 3, &sha); + shawrite(data, len << 3, state); } - shafinish(&sha); + shafinish(state); len = 0; if (ix % 3 == 0) { - result = (char *) shadigest(&sha); - len = sha.digestlen; + result = (char *) digcpy(state); + len = state->digestlen; } else if (ix % 3 == 1) - result = shahex(&sha); + result = shahex(state); else - result = shabase64(&sha); - RETVAL = newSVpv(result, len); -OUTPUT: - RETVAL + result = shabase64(state); + ST(0) = sv_2mortal(newSVpv(result, len)); + shaclose(state); + XSRETURN(1); -SV * +void hmac_sha1(...) ALIAS: Digest::SHA::hmac_sha1 = 0 @@ -188,41 +137,39 @@ ALIAS: Digest::SHA::hmac_sha512256_base64 = 20 PREINIT: int i; - UCHR *key = (UCHR *) ""; + UCHR *key; UCHR *data; - STRLEN len = 0; - HMAC hmac; + STRLEN len; + HMAC *state; char *result; -CODE: - if (items > 0) { - key = (UCHR *) (SvPVbyte(ST(items-1), len)); - } - if (hmacinit(&hmac, ix2alg[ix], key, len) == NULL) +PPCODE: + key = (UCHR *) (SvPVbyte(ST(items-1), len)); + if ((state = hmacopen(ix2alg[ix], key, len)) == NULL) XSRETURN_UNDEF; for (i = 0; i < items - 1; i++) { data = (UCHR *) (SvPVbyte(ST(i), len)); while (len > MAX_WRITE_SIZE) { - hmacwrite(data, MAX_WRITE_SIZE << 3, &hmac); + hmacwrite(data, MAX_WRITE_SIZE << 3, state); data += MAX_WRITE_SIZE; len -= MAX_WRITE_SIZE; } - hmacwrite(data, len << 3, &hmac); + hmacwrite(data, len << 3, state); } - hmacfinish(&hmac); + hmacfinish(state); len = 0; if (ix % 3 == 0) { - result = (char *) hmacdigest(&hmac); - len = hmac.digestlen; + result = (char *) digcpy(state->osha); + len = state->osha->digestlen; } else if (ix % 3 == 1) - result = hmachex(&hmac); + result = hmachex(state); else - result = hmacbase64(&hmac); - RETVAL = newSVpv(result, len); -OUTPUT: - RETVAL + result = hmacbase64(state); + ST(0) = sv_2mortal(newSVpv(result, len)); + hmacclose(state); + XSRETURN(1); -int +void hashsize(self) SV * self ALIAS: @@ -230,12 +177,14 @@ ALIAS: Digest::SHA::algorithm = 1 PREINIT: SHA *state; -CODE: - if ((state = getSHA(self)) == NULL) + int result; +PPCODE: + if (!sv_isa(self, "Digest::SHA")) XSRETURN_UNDEF; - RETVAL = ix ? state->alg : state->digestlen << 3; -OUTPUT: - RETVAL + state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self)))); + result = ix ? state->alg : state->digestlen << 3; + ST(0) = sv_2mortal(newSViv(result)); + XSRETURN(1); void add(self, ...) @@ -246,8 +195,9 @@ PREINIT: STRLEN len; SHA *state; PPCODE: - if ((state = getSHA(self)) == NULL) + if (!sv_isa(self, "Digest::SHA")) XSRETURN_UNDEF; + state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self)))); for (i = 1; i < items; i++) { data = (UCHR *) (SvPVbyte(ST(i), len)); while (len > MAX_WRITE_SIZE) { @@ -259,75 +209,75 @@ PPCODE: } XSRETURN(1); -SV * +void digest(self) SV * self ALIAS: Digest::SHA::digest = 0 - Digest::SHA::hexdigest = 1 - Digest::SHA::b64digest = 2 + Digest::SHA::Hexdigest = 1 + Digest::SHA::B64digest = 2 PREINIT: STRLEN len; SHA *state; char *result; -CODE: - if ((state = getSHA(self)) == NULL) +PPCODE: + if (!sv_isa(self, "Digest::SHA")) XSRETURN_UNDEF; + state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self)))); shafinish(state); len = 0; if (ix == 0) { - result = (char *) shadigest(state); + result = (char *) digcpy(state); len = state->digestlen; } else if (ix == 1) result = shahex(state); else result = shabase64(state); - RETVAL = newSVpv(result, len); + ST(0) = sv_2mortal(newSVpv(result, len)); sharewind(state); -OUTPUT: - RETVAL + XSRETURN(1); -SV * +void _getstate(self) SV * self PREINIT: SHA *state; UCHR buf[256]; UCHR *ptr = buf; -CODE: - if ((state = getSHA(self)) == NULL) +PPCODE: + if (!sv_isa(self, "Digest::SHA")) XSRETURN_UNDEF; - Copy(digcpy(state), ptr, state->alg <= SHA256 ? 32 : 64, UCHR); + state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self)))); + memcpy(ptr, digcpy(state), state->alg <= SHA256 ? 32 : 64); ptr += state->alg <= SHA256 ? 32 : 64; - Copy(state->block, ptr, state->alg <= SHA256 ? 64 : 128, UCHR); + memcpy(ptr, state->block, state->alg <= SHA256 ? 64 : 128); ptr += state->alg <= SHA256 ? 64 : 128; ptr = w32mem(ptr, state->blockcnt); ptr = w32mem(ptr, state->lenhh); ptr = w32mem(ptr, state->lenhl); ptr = w32mem(ptr, state->lenlh); ptr = w32mem(ptr, state->lenll); - RETVAL = newSVpv((char *) buf, ptr - buf); -OUTPUT: - RETVAL + ST(0) = sv_2mortal(newSVpv((char *) buf, ptr - buf)); + XSRETURN(1); void -_putstate(self, packed_state) +_putstate(self, ...) SV * self - SV * packed_state PREINIT: UINT bc; STRLEN len; SHA *state; UCHR *data; PPCODE: - if ((state = getSHA(self)) == NULL) + if (!sv_isa(self, "Digest::SHA")) XSRETURN_UNDEF; - data = (UCHR *) SvPV(packed_state, len); + state = INT2PTR(SHA *, SvIV(SvRV(SvRV(self)))); + data = (UCHR *) SvPV(ST(1), len); if (len != (state->alg <= SHA256 ? 116 : 212)) XSRETURN_UNDEF; data = statecpy(state, data); - Copy(data, state->block, state->blocksize >> 3, UCHR); + memcpy(state->block, data, state->blocksize >> 3); data += (state->blocksize >> 3); bc = memw32(data), data += 4; if (bc >= (state->alg <= SHA256 ? 512 : 1024)) @@ -338,63 +288,3 @@ PPCODE: state->lenlh = memw32(data), data += 4; state->lenll = memw32(data); XSRETURN(1); - -void -_addfilebin(self, f) - SV * self - PerlIO * f -PREINIT: - SHA *state; - int n; - UCHR in[IO_BUFFER_SIZE]; -PPCODE: - if (!f || (state = getSHA(self)) == NULL) - XSRETURN_UNDEF; - while ((n = PerlIO_read(f, in, sizeof(in))) > 0) - shawrite(in, n << 3, state); - XSRETURN(1); - -void -_addfileuniv(self, f) - SV * self - PerlIO * f -PREINIT: - char c; - int n; - int cr = 0; - UCHR *src, *dst; - UCHR in[IO_BUFFER_SIZE+1]; - SHA *state; -PPCODE: - if (!f || (state = getSHA(self)) == NULL) - XSRETURN_UNDEF; - while ((n = PerlIO_read(f, in+1, IO_BUFFER_SIZE)) > 0) { - for (dst = in, src = in + 1; n; n--) { - c = *src++; - if (!cr) { - if (c == '\015') - cr = 1; - else - *dst++ = c; - } - else { - if (c == '\015') - *dst++ = '\012'; - else if (c == '\012') { - *dst++ = '\012'; - cr = 0; - } - else { - *dst++ = '\012'; - *dst++ = c; - cr = 0; - } - } - } - shawrite(in, (dst - in) << 3, state); - } - if (cr) { - in[0] = '\012'; - shawrite(in, 1 << 3, state); - } - XSRETURN(1); |