Revision history for Perl extension Digest::SHA.
+5.43 Sat Aug 5 02:36:18 MST 2006
+ - undid Perl Best Practice of favoring 3-argument "open"
+ -- 3-arg version uses different semantics for "-"
+ causing bugs in addfile and shasum
+ - modified underlying C functions to use ANSI prototypes
+ -- requested by Steve Hay (ref. Smoke [5.9.4] 28630)
+ -- K&R style was causing numerous warnings from
+ Borland compiler
+
5.42 Mon Jul 24 04:04:40 MST 2006
- minor code changes suggested by Perl::Critic
-- e.g. no bareword filehandles, no 2-argument open's
-Digest::SHA version 5.42
+Digest::SHA version 5.43
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
use warnings;
use integer;
-our $VERSION = '5.42_01';
+our $VERSION = '5.43';
require Exporter;
our @ISA = qw(Exporter);
my ($binary, $portable) = map { $_ eq $mode } ("b", "p");
my $text = -T $file;
- open(my $fh, q{<}, $file) or _bail("Open failed");
+ open(my $fh, "<$file") ## no critic
+ or _bail("Open failed");
binmode($fh) if $binary || $portable;
unless ($portable && $text) {
#
# Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
#
- # Version: 5.42
- # Mon Jul 24 04:04:40 MST 2006
+ # Version: 5.43
+ # Sat Aug 5 02:36:18 MST 2006
=head1 NAME
use strict;
use Getopt::Long;
-my $VERSION = "5.42";
+my $VERSION = "5.43";
# Try to use Digest::SHA, since it's faster. If not installed,
my ($fh, $sum, $fname, $rsp);
die "shasum: $checkfile: $!\n"
- unless open($fh, q{<}, $checkfile);
+ unless open($fh, "<$checkfile"); ## no critic
while (<$fh>) {
s/\s+$//;
($sum, $modesym, $fname) = /^(\S+) (.)(.*)$/;
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.42
- * Mon Jul 24 04:04:40 MST 2006
+ * Version: 5.43
+ * Sat Aug 5 02:36:18 MST 2006
*
*/
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.42
- * Mon Jul 24 04:04:40 MST 2006
+ * Version: 5.43
+ * Sat Aug 5 02:36:18 MST 2006
*
*/
unsigned char key[SHA_MAX_BLOCK_BITS/8];
} HMAC;
-#if defined(__STDC__) && __STDC__ != 0
- #define _HMAC_P(protos) protos
-#else
- #define _HMAC_P(protos) ()
-#endif
-
#define _HMAC_STATE HMAC *h
#define _HMAC_ALG int alg
#define _HMAC_DATA unsigned char *bitstr, unsigned long bitcnt
#define _HMAC_KEY unsigned char *key, unsigned int keylen
-HMAC *hmacopen _HMAC_P((_HMAC_ALG, _HMAC_KEY));
-unsigned long hmacwrite _HMAC_P((_HMAC_DATA, _HMAC_STATE));
-void hmacfinish _HMAC_P((_HMAC_STATE));
-unsigned char *hmacdigest _HMAC_P((_HMAC_STATE));
-char *hmachex _HMAC_P((_HMAC_STATE));
-char *hmacbase64 _HMAC_P((_HMAC_STATE));
-int hmacclose _HMAC_P((_HMAC_STATE));
-
-unsigned char *hmac1digest _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac1hex _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac1base64 _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-unsigned char *hmac224digest _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac224hex _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac224base64 _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-unsigned char *hmac256digest _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac256hex _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac256base64 _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-unsigned char *hmac384digest _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac384hex _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac384base64 _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-unsigned char *hmac512digest _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac512hex _HMAC_P((_HMAC_DATA, _HMAC_KEY));
-char *hmac512base64 _HMAC_P((_HMAC_DATA, _HMAC_KEY));
+HMAC *hmacopen (_HMAC_ALG, _HMAC_KEY);
+unsigned long hmacwrite (_HMAC_DATA, _HMAC_STATE);
+void hmacfinish (_HMAC_STATE);
+unsigned char *hmacdigest (_HMAC_STATE);
+char *hmachex (_HMAC_STATE);
+char *hmacbase64 (_HMAC_STATE);
+int hmacclose (_HMAC_STATE);
+
+#ifndef SHA_PERL_MODULE
+
+unsigned char *hmac1digest (_HMAC_DATA, _HMAC_KEY);
+char *hmac1hex (_HMAC_DATA, _HMAC_KEY);
+char *hmac1base64 (_HMAC_DATA, _HMAC_KEY);
+unsigned char *hmac224digest (_HMAC_DATA, _HMAC_KEY);
+char *hmac224hex (_HMAC_DATA, _HMAC_KEY);
+char *hmac224base64 (_HMAC_DATA, _HMAC_KEY);
+unsigned char *hmac256digest (_HMAC_DATA, _HMAC_KEY);
+char *hmac256hex (_HMAC_DATA, _HMAC_KEY);
+char *hmac256base64 (_HMAC_DATA, _HMAC_KEY);
+unsigned char *hmac384digest (_HMAC_DATA, _HMAC_KEY);
+char *hmac384hex (_HMAC_DATA, _HMAC_KEY);
+char *hmac384base64 (_HMAC_DATA, _HMAC_KEY);
+unsigned char *hmac512digest (_HMAC_DATA, _HMAC_KEY);
+char *hmac512hex (_HMAC_DATA, _HMAC_KEY);
+char *hmac512base64 (_HMAC_DATA, _HMAC_KEY);
+
+#endif
#endif /* _INCLUDE_HMAC_H_ */
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.42
- * Mon Jul 24 04:04:40 MST 2006
+ * Version: 5.43
+ * Sat Aug 5 02:36:18 MST 2006
*
*/
C32(0x510e527f), C32(0x9b05688c), C32(0x1f83d9ab), C32(0x5be0cd19)
};
-static void sha1(s, block) /* SHA-1 transform */
-SHA *s;
-UCHR *block;
+static void sha1(SHA *s, UCHR *block) /* SHA-1 transform */
{
W32 a, b, c, d, e;
SHA_STO_CLASS W32 W[16];
H[0] += a; H[1] += b; H[2] += c; H[3] += d; H[4] += e;
}
-static void sha256(s, block) /* SHA-224/256 transform */
-SHA *s;
-UCHR *block;
+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];
: ((nbytes) / 3) * 4 + ((nbytes) % 3) + 1)
/* w32mem: writes 32-bit word to memory in big-endian order */
-static void w32mem(mem, w32)
-UCHR *mem;
-W32 w32;
+static void w32mem(UCHR *mem, W32 w32)
{
int i;
}
/* digcpy: writes current state to digest buffer */
-static void digcpy(s)
-SHA *s;
+static void digcpy(SHA *s)
{
UINT i;
UCHR *d = s->digest;
} while (0)
/* sharewind: re-initializes the digest object */
-void sharewind(s)
-SHA *s;
+void sharewind(SHA *s)
{
if (s->alg == SHA1) SHA_INIT(1, 1);
else if (s->alg == SHA224) SHA_INIT(224, 256);
}
/* shaopen: creates a new digest object */
-SHA *shaopen(alg)
-int alg;
+SHA *shaopen(int alg)
{
SHA *s;
}
/* shadirect: updates state directly (w/o going through s->block) */
-static ULNG shadirect(bitstr, bitcnt, s)
-UCHR *bitstr;
-ULNG bitcnt;
-SHA *s;
+static ULNG shadirect(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
ULNG savecnt = bitcnt;
}
/* shabytes: updates state for byte-aligned input data */
-static ULNG shabytes(bitstr, bitcnt, s)
-UCHR *bitstr;
-ULNG bitcnt;
-SHA *s;
+static ULNG shabytes(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
UINT offset;
UINT nbits;
}
/* shabits: updates state for bit-aligned input data */
-static ULNG shabits(bitstr, bitcnt, s)
-UCHR *bitstr;
-ULNG bitcnt;
-SHA *s;
+static ULNG shabits(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
UINT i;
UINT gap;
}
/* shawrite: triggers a state update using data in bitstr/bitcnt */
-ULNG shawrite(bitstr, bitcnt, s)
-UCHR *bitstr;
-ULNG bitcnt;
-SHA *s;
+ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
if (bitcnt < 1)
return(0);
}
/* shafinish: pads remaining block(s) and computes final digest state */
-void shafinish(s)
-SHA *s;
+void shafinish(SHA *s)
{
UINT lenpos, lhpos, llpos;
}
/* shadigest: returns pointer to current digest (binary) */
-UCHR *shadigest(s)
-SHA *s;
+UCHR *shadigest(SHA *s)
{
digcpy(s);
return(s->digest);
}
/* shahex: returns pointer to current digest (hexadecimal) */
-char *shahex(s)
-SHA *s;
+char *shahex(SHA *s)
{
int i;
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* encbase64: encodes input (0 to 3 bytes) into Base 64 */
-static void encbase64(in, n, out)
-UCHR *in;
-int n;
-char *out;
+static void encbase64(UCHR *in, int n, char *out)
{
UCHR byte[3] = {0, 0, 0};
}
/* shabase64: returns pointer to current digest (Base 64) */
-char *shabase64(s)
-SHA *s;
+char *shabase64(SHA *s)
{
int n;
UCHR *q;
}
/* shadsize: returns length of digest in bytes */
-int shadsize(s)
-SHA *s;
+int shadsize(SHA *s)
{
return(s->digestlen);
}
/* shadup: duplicates current digest object */
-SHA *shadup(s)
-SHA *s;
+SHA *shadup(SHA *s)
{
SHA *p;
}
/* shadump: dumps digest object to a human-readable ASCII file */
-int shadump(file, s)
-char *file;
-SHA *s;
+int shadump(char *file, SHA *s)
{
int i, j;
SHA_FILE *f;
}
/* fgetstr: reads (and returns pointer to) next line of file */
-static char *fgetstr(line, maxsize, f)
-char *line;
-UINT maxsize;
-SHA_FILE *f;
+static char *fgetstr(char *line, UINT maxsize, SHA_FILE *f)
{
char *p;
}
/* empty: returns true if line contains only whitespace characters */
-static int empty(line)
-char *line;
+static int empty(char *line)
{
char *p;
}
/* getval: null-terminates field value, and sets pointer to rest of line */
-static char *getval(line, pprest)
-char *line;
-char **pprest;
+static char *getval(char *line, char **pprest)
{
char *p, *v;
#define T_Q 4 /* 64-bit value */
/* ldvals: checks next line in dump file against tag, and loads values */
-static int ldvals(f, tag, type, pval, reps, base)
-SHA_FILE *f;
-char *tag;
-int type;
-void *pval;
-int reps;
-int base;
+static int ldvals(
+ SHA_FILE *f,
+ char *tag,
+ int type,
+ void *pval,
+ int reps,
+ int base)
{
char *p, *pr, line[512];
UCHR *pc = (UCHR *) pval; UINT *pi = (UINT *) pval;
}
/* closeall: closes dump file and de-allocates digest object */
-static SHA *closeall(f, s)
-SHA_FILE *f;
-SHA *s;
+static SHA *closeall(SHA_FILE *f, SHA *s)
{
if (f != NULL && f != SHA_stdin())
SHA_close(f);
}
/* shaload: creates digest object corresponding to contents of dump file */
-SHA *shaload(file)
-char *file;
+SHA *shaload(char *file)
{
int alg;
SHA *s = NULL;
}
/* shaclose: de-allocates digest object */
-int shaclose(s)
-SHA *s;
+int shaclose(SHA *s)
{
if (s != NULL) {
memset(s, 0, sizeof(SHA));
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.42
- * Mon Jul 24 04:04:40 MST 2006
+ * Version: 5.43
+ * Sat Aug 5 02:36:18 MST 2006
*
*/
#define SHA_H_SIZE sizeof(SHA32) * 8
#endif
-typedef struct {
+typedef struct SHA {
int alg;
- void (*sha)();
+ void (*sha)(struct SHA *, unsigned char *);
unsigned char H[SHA_H_SIZE];
unsigned char block[SHA_MAX_BLOCK_BITS/8];
unsigned int blockcnt;
#define SHA_FMT_HEX 2
#define SHA_FMT_BASE64 3
-#if defined(__STDC__) && __STDC__ != 0
- #define _SHA_P(protos) protos
-#else
- #define _SHA_P(protos) ()
-#endif
-
#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_P((_SHA_ALG));
-unsigned long shawrite _SHA_P((_SHA_DATA, _SHA_STATE));
-void shafinish _SHA_P((_SHA_STATE));
-void sharewind _SHA_P((_SHA_STATE));
-unsigned char *shadigest _SHA_P((_SHA_STATE));
-char *shahex _SHA_P((_SHA_STATE));
-char *shabase64 _SHA_P((_SHA_STATE));
-int shadsize _SHA_P((_SHA_STATE));
-SHA *shadup _SHA_P((_SHA_STATE));
-int shadump _SHA_P((_SHA_FNAME, _SHA_STATE));
-SHA *shaload _SHA_P((_SHA_FNAME));
-int shaclose _SHA_P((_SHA_STATE));
-
-unsigned char *sha1digest _SHA_P((_SHA_DATA));
-char *sha1hex _SHA_P((_SHA_DATA));
-char *sha1base64 _SHA_P((_SHA_DATA));
-unsigned char *sha224digest _SHA_P((_SHA_DATA));
-char *sha224hex _SHA_P((_SHA_DATA));
-char *sha224base64 _SHA_P((_SHA_DATA));
-unsigned char *sha256digest _SHA_P((_SHA_DATA));
-char *sha256hex _SHA_P((_SHA_DATA));
-char *sha256base64 _SHA_P((_SHA_DATA));
-unsigned char *sha384digest _SHA_P((_SHA_DATA));
-char *sha384hex _SHA_P((_SHA_DATA));
-char *sha384base64 _SHA_P((_SHA_DATA));
-unsigned char *sha512digest _SHA_P((_SHA_DATA));
-char *sha512hex _SHA_P((_SHA_DATA));
-char *sha512base64 _SHA_P((_SHA_DATA));
+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);
+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);
+
+#endif
#endif /* _INCLUDE_SHA_H_ */
};
/* strto64: converts hex string to a 64-bit word */
-static W64 strto64(s)
-char *s;
+static W64 strto64(char *s)
{
char str[2] = {0, 0};
W64 u = C64(0);
return(u);
}
-static void sha512(s, block) /* SHA-384/512 transform */
-SHA *s;
-unsigned char *block;
+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];