cpan/Digest-SHA/README Digest::SHA README
cpan/Digest-SHA/shasum shasum script
cpan/Digest-SHA/SHA.xs Digest::SHA extension
-cpan/Digest-SHA/src/hmac.c Digest::SHA extension
-cpan/Digest-SHA/src/hmac.h Digest::SHA extension
-cpan/Digest-SHA/src/hmacxtra.c Digest::SHA extension
cpan/Digest-SHA/src/sha64bit.c Digest::SHA extension
cpan/Digest-SHA/src/sha64bit.h Digest::SHA extension
cpan/Digest-SHA/src/sha.c Digest::SHA extension
cpan/Digest-SHA/src/sha.h Digest::SHA extension
-cpan/Digest-SHA/src/shaxtra.c Digest::SHA extension
cpan/Digest-SHA/t/allfcns.t See if Digest::SHA works
cpan/Digest-SHA/t/base64.t See if Digest::SHA works
cpan/Digest-SHA/t/bitbuf.t See if Digest::SHA works
'Digest::SHA' => {
'MAINTAINER' => 'mshelor',
- 'DISTRIBUTION' => 'MSHELOR/Digest-SHA-5.82.tar.gz',
+ 'DISTRIBUTION' => 'MSHELOR/Digest-SHA-5.83.tar.gz',
'FILES' => q[cpan/Digest-SHA],
'EXCLUDED' => [
qw( t/pod.t
Revision history for Perl extension Digest::SHA.
+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+
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_PerlIO') if $] >= 5.004;
push(@defines, '-DNO_SHA_384_512') if $opts{'x'};
my $define = join(' ', @defines);
push(@extra, OPTIMIZE => '-O1 -fomit-frame-pointer');
}
+my @srcs = map { "src/$_" } qw(sha.c sha64bit.c);
+my @hdrs = map { "src/$_" } qw(sha.h sha64bit.h);
+my $deps = join(' ', @srcs, @hdrs);
+
my %att = (
'NAME' => 'Digest::SHA',
'VERSION_FROM' => $PM,
'INC' => '-I.',
'EXE_FILES' => [ 'shasum' ],
'INSTALLDIRS' => ($] >= 5.010 and $] < 5.011) ? 'perl' : 'site',
+ 'depend' => { 'SHA.c' => $deps },
@extra,
);
-Digest::SHA version 5.82
+Digest::SHA version 5.83
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
#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,
PROTOTYPES: ENABLE
-#include "src/sha.h"
-#include "src/hmac.h"
-
#ifndef INT2PTR
#define INT2PTR(p, i) (p) (i)
#endif
use Fcntl;
use integer;
-$VERSION = '5.82';
+$VERSION = '5.83';
require Exporter;
require DynaLoader;
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 bytes, where each byte is equal to the ordinal value
-(viz. code point) of its corresponding Unicode character. That way,
-the Unicode version of the string 'abc' has exactly the same digest
-value as the ordinary string 'abc'.
+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:
+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:
$str1 = pack('U*', (0..255));
print sha1_hex($str1); # ok
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 only influences the way Perl stores data internally.
+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
##
## Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
##
- ## Version: 5.82
- ## Thu Jan 24 04:54:12 MST 2013
+ ## Version: 5.83
+ ## Mon Mar 4 08:12:00 MST 2013
## shasum SYNOPSIS adapted from GNU Coreutils sha1sum.
## Add an "-a" option for algorithm selection, a "-p"
use Fcntl;
use Getopt::Long;
-my $VERSION = "5.82";
+my $VERSION = "5.83";
## Try to use Digest::SHA. If not installed, use the slower
+++ /dev/null
-/*
- * hmac.c: routines to compute HMAC-SHA-1/224/256/384/512 digests
- *
- * Ref: FIPS PUB 198 The Keyed-Hash Message Authentication Code
- *
- * Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
- *
- * Version: 5.82
- * Thu Jan 24 04:54:12 MST 2013
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "hmac.h"
-#include "sha.h"
-
-/* hmacopen: creates a new HMAC-SHA digest object */
-HMAC *hmacopen(int alg, unsigned char *key, unsigned int keylen)
-{
- unsigned int 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 */
-unsigned long hmacwrite(unsigned char *bitstr, unsigned long bitcnt, HMAC *h)
-{
- return(shawrite(bitstr, bitcnt, h->isha));
-}
-
-/* hmacfinish: computes final digest state */
-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) */
-unsigned char *hmacdigest(HMAC *h)
-{
- return(shadigest(h->osha));
-}
-
-/* hmachex: returns pointer to digest (hexadecimal) */
-char *hmachex(HMAC *h)
-{
- return(shahex(h->osha));
-}
-
-/* hmacbase64: returns pointer to digest (Base 64) */
-char *hmacbase64(HMAC *h)
-{
- return(shabase64(h->osha));
-}
-
-/* hmacclose: de-allocates digest object */
-int hmacclose(HMAC *h)
-{
- if (h != NULL) {
- shaclose(h->osha);
- memset(h, 0, sizeof(HMAC));
- SHA_free(h);
- }
- return(0);
-}
+++ /dev/null
-/*
- * hmac.h: header file for HMAC-SHA-1/224/256/384/512 routines
- *
- * Ref: FIPS PUB 198 The Keyed-Hash Message Authentication Code
- *
- * Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
- *
- * Version: 5.82
- * Thu Jan 24 04:54:12 MST 2013
- *
- */
-
-#ifndef _INCLUDE_HMAC_H_
-#define _INCLUDE_HMAC_H_
-
-#include "sha.h"
-
-typedef struct {
- SHA *ksha;
- SHA *isha;
- SHA *osha;
- unsigned char key[SHA_MAX_BLOCK_BITS/8];
-} HMAC;
-
-#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_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);
-unsigned char *hmac512224digest (_HMAC_DATA, _HMAC_KEY);
-char *hmac512224hex (_HMAC_DATA, _HMAC_KEY);
-char *hmac512224base64 (_HMAC_DATA, _HMAC_KEY);
-unsigned char *hmac512256digest (_HMAC_DATA, _HMAC_KEY);
-char *hmac512256hex (_HMAC_DATA, _HMAC_KEY);
-char *hmac512256base64 (_HMAC_DATA, _HMAC_KEY);
-
-#endif
-
-#endif /* _INCLUDE_HMAC_H_ */
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include "hmac.h"
-
-static unsigned char *hmaccomp(alg, fmt, bitstr, bitcnt, key, keylen)
-int alg;
-int fmt;
-unsigned char *bitstr;
-unsigned long bitcnt;
-unsigned char *key;
-unsigned int keylen;
-{
- HMAC *h;
- static unsigned char digest[SHA_MAX_HEX_LEN+1];
- unsigned char *ret = digest;
-
- if ((h = hmacopen(alg, key, keylen)) == NULL)
- return(NULL);
- hmacwrite(bitstr, bitcnt, h);
- hmacfinish(h);
- if (fmt == SHA_FMT_RAW)
- memcpy(digest, hmacdigest(h), h->osha->digestlen);
- else if (fmt == SHA_FMT_HEX)
- strcpy((char *) digest, hmachex(h));
- else if (fmt == SHA_FMT_BASE64)
- strcpy((char *) digest, hmacbase64(h));
- else
- ret = NULL;
- hmacclose(h);
- return(ret);
-}
-
-#define HMAC_DIRECT(type, name, alg, fmt) \
-type name(bitstr, bitcnt, key, keylen) \
-unsigned char *bitstr; \
-unsigned long bitcnt; \
-unsigned char *key; \
-unsigned int keylen; \
-{ \
- return((type) hmaccomp(alg, fmt, bitstr, bitcnt, \
- key, keylen)); \
-}
-
-HMAC_DIRECT(unsigned char *, hmac1digest, SHA1, SHA_FMT_RAW)
-HMAC_DIRECT(char *, hmac1hex, SHA1, SHA_FMT_HEX)
-HMAC_DIRECT(char *, hmac1base64, SHA1, SHA_FMT_BASE64)
-
-HMAC_DIRECT(unsigned char *, hmac224digest, SHA224, SHA_FMT_RAW)
-HMAC_DIRECT(char *, hmac224hex, SHA224, SHA_FMT_HEX)
-HMAC_DIRECT(char *, hmac224base64, SHA224, SHA_FMT_BASE64)
-
-HMAC_DIRECT(unsigned char *, hmac256digest, SHA256, SHA_FMT_RAW)
-HMAC_DIRECT(char *, hmac256hex, SHA256, SHA_FMT_HEX)
-HMAC_DIRECT(char *, hmac256base64, SHA256, SHA_FMT_BASE64)
-
-HMAC_DIRECT(unsigned char *, hmac384digest, SHA384, SHA_FMT_RAW)
-HMAC_DIRECT(char *, hmac384hex, SHA384, SHA_FMT_HEX)
-HMAC_DIRECT(char *, hmac384base64, SHA384, SHA_FMT_BASE64)
-
-HMAC_DIRECT(unsigned char *, hmac512digest, SHA512, SHA_FMT_RAW)
-HMAC_DIRECT(char *, hmac512hex, SHA512, SHA_FMT_HEX)
-HMAC_DIRECT(char *, hmac512base64, SHA512, SHA_FMT_BASE64)
*
* Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
*
- * Version: 5.82
- * Thu Jan 24 04:54:12 MST 2013
+ * Version: 5.83
+ * Mon Mar 4 08:12:00 MST 2013
*
*/
} 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);
}
/* shaopen: creates a new digest object */
-SHA *shaopen(int alg)
+static SHA *shaopen(int alg)
{
SHA *s = NULL;
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)
{
}
/* 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);
}
/* shafinish: pads remaining block(s) and computes final digest state */
-void shafinish(SHA *s)
+static void shafinish(SHA *s)
{
UINT lenpos, lhpos, llpos;
}
/* 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;
}
/* shabase64: returns pointer to current digest (Base 64) */
-char *shabase64(SHA *s)
+static char *shabase64(SHA *s)
{
int n;
UCHR *q;
}
/* 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;
}
/* 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;
}
/* shaload: creates digest object corresponding to contents of dump file */
-SHA *shaload(char *file)
+static SHA *shaload(char *file)
{
int alg;
SHA *s = NULL;
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);
}
*
* Copyright (C) 2003-2013 Mark Shelor, All Rights Reserved
*
- * Version: 5.82
- * Thu Jan 24 04:54:12 MST 2013
+ * Version: 5.83
+ * Mon Mar 4 08:12:00 MST 2013
*
*/
(SHA64) b[6] << 8 | (SHA64) b[7]; }
#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
+#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()
#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
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_ */
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include "sha.h"
-
-static unsigned char *shacomp(alg, fmt, bitstr, bitcnt)
-int alg;
-int fmt;
-unsigned char *bitstr;
-unsigned long bitcnt;
-{
- SHA *s;
- static unsigned char digest[SHA_MAX_HEX_LEN+1];
- unsigned char *ret = digest;
-
- if ((s = shaopen(alg)) == NULL)
- return(NULL);
- shawrite(bitstr, bitcnt, s);
- shafinish(s);
- if (fmt == SHA_FMT_RAW)
- memcpy(digest, shadigest(s), s->digestlen);
- else if (fmt == SHA_FMT_HEX)
- strcpy((char *) digest, shahex(s));
- else if (fmt == SHA_FMT_BASE64)
- strcpy((char *) digest, shabase64(s));
- else
- ret = NULL;
- shaclose(s);
- return(ret);
-}
-
-#define SHA_DIRECT(type, name, alg, fmt) \
-type name(bitstr, bitcnt) \
-unsigned char *bitstr; \
-unsigned long bitcnt; \
-{ \
- return((type) shacomp(alg, fmt, bitstr, bitcnt)); \
-}
-
-SHA_DIRECT(unsigned char *, sha1digest, SHA1, SHA_FMT_RAW)
-SHA_DIRECT(char *, sha1hex, SHA1, SHA_FMT_HEX)
-SHA_DIRECT(char *, sha1base64, SHA1, SHA_FMT_BASE64)
-
-SHA_DIRECT(unsigned char *, sha224digest, SHA224, SHA_FMT_RAW)
-SHA_DIRECT(char *, sha224hex, SHA224, SHA_FMT_HEX)
-SHA_DIRECT(char *, sha224base64, SHA224, SHA_FMT_BASE64)
-
-SHA_DIRECT(unsigned char *, sha256digest, SHA256, SHA_FMT_RAW)
-SHA_DIRECT(char *, sha256hex, SHA256, SHA_FMT_HEX)
-SHA_DIRECT(char *, sha256base64, SHA256, SHA_FMT_BASE64)
-
-SHA_DIRECT(unsigned char *, sha384digest, SHA384, SHA_FMT_RAW)
-SHA_DIRECT(char *, sha384hex, SHA384, SHA_FMT_HEX)
-SHA_DIRECT(char *, sha384base64, SHA384, SHA_FMT_BASE64)
-
-SHA_DIRECT(unsigned char *, sha512digest, SHA512, SHA_FMT_RAW)
-SHA_DIRECT(char *, sha512hex, SHA512, SHA_FMT_HEX)
-SHA_DIRECT(char *, sha512base64, SHA512, SHA_FMT_BASE64)