Add gcrypt to tdigest.

CVS patchset: 6722
CVS date: 2003/03/28 22:11:06
This commit is contained in:
jbj 2003-03-28 22:11:06 +00:00
parent 53f81816ea
commit 485f497e21
3 changed files with 41 additions and 12 deletions

View File

@ -63,7 +63,7 @@ lint:
$(LINT) $(DEFS) $(INCLUDES) $(librpmio_la_SOURCES)
tdigest_SOURCES = tdigest.c
tdigest_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
tdigest_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la -lgcrypt
tdir_SOURCES = tdir.c
tdir_LDFLAGS = -all-static

View File

@ -18,7 +18,7 @@ static int rpmsw_type = 0;
/*@unchecked@*/
static int rpmsw_initialized = 0;
#if 0 /* XXX defined(__i386__) */
#if 1 /* XXX defined(__i386__) */
/* Swiped from glibc-2.3.2 sysdeps/i386/i686/hp-timing.h */
#define HP_TIMING_ZERO(Var) (Var) = (0)

View File

@ -1,14 +1,15 @@
#include "system.h"
#include <gcrypt.h>
#include "rpmio_internal.h"
#include "popt.h"
#include "debug.h"
static pgpHashAlgo hashalgo = PGPHASHALGO_MD5;
static rpmDigestFlags flags = RPMDIGEST_NONE;
extern int _rpmio_debug;
static int fips = 0;
static int gcrypt = 0;
const char * FIPSAdigest = "a9993e364706816aba3e25717850c26c9cd0d89d";
const char * FIPSBdigest = "84983e441c3bd26ebaae4aa1f95129e5e54670f1";
@ -23,6 +24,7 @@ static struct poptOption optionsTable[] = {
{ "fipsa",'\0', POPT_ARG_VAL, &fips, 1, NULL, NULL },
{ "fipsb",'\0', POPT_ARG_VAL, &fips, 2, NULL, NULL },
{ "fipsc",'\0', POPT_ARG_VAL, &fips, 3, NULL, NULL },
{ "gcrypt",'\0', POPT_ARG_VAL, &gcrypt, 1, NULL, NULL },
{ "debug",'d', POPT_ARG_VAL, &_rpmio_debug, -1, NULL, NULL },
POPT_AUTOHELP
POPT_TABLEEND
@ -39,6 +41,7 @@ main(int argc, const char *argv[])
const char * ifn;
const char * ofn = "/dev/null";
DIGEST_CTX ctx;
GcryMDHd gcry;
const char * idigest;
const char * odigest;
const char * sdigest;
@ -54,38 +57,63 @@ main(int argc, const char *argv[])
while ((rc = poptGetNextOpt(optCon)) > 0)
;
#ifdef DYING
reverse = (flags & RPMDIGEST_REVERSE);
#endif
if (fips) {
ctx = rpmDigestInit(PGPHASHALGO_SHA1, flags);
struct rpmsw_s begin, end;
(void) rpmswNow(&begin);
if (gcrypt)
gcry = gcry_md_open(GCRY_MD_SHA1, 0);
else
ctx = rpmDigestInit(PGPHASHALGO_SHA1, flags);
ifn = NULL;
appendix = ' ';
sdigest = NULL;
switch (fips) {
case 1:
ifn = "abc";
rpmDigestUpdate(ctx, ifn, strlen(ifn));
if (gcrypt)
gcry_md_write (gcry, ifn, strlen(ifn));
else
rpmDigestUpdate(ctx, ifn, strlen(ifn));
sdigest = FIPSAdigest;
appendix = 'A';
break;
case 2:
ifn = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
rpmDigestUpdate(ctx, ifn, strlen(ifn));
if (gcrypt)
gcry_md_write (gcry, ifn, strlen(ifn));
else
rpmDigestUpdate(ctx, ifn, strlen(ifn));
sdigest = FIPSBdigest;
appendix = 'B';
break;
case 3:
ifn = "aaaaaaaaaaa ...";
for (i = 0; i < 1000000; i++)
rpmDigestUpdate(ctx, ifn, 1);
for (i = 0; i < 1000000; i++) {
if (gcrypt)
gcry_md_write (gcry, ifn, strlen(ifn));
else
rpmDigestUpdate(ctx, ifn, 1);
}
sdigest = FIPSCdigest;
appendix = 'C';
break;
}
if (ifn == NULL)
return 1;
rpmDigestFinal(ctx, (void **)&digest, &digestlen, asAscii);
if (gcrypt) {
const char * s = gcry_md_read (gcry, GCRY_MD_SHA1);
digestlen = 2*16;
digest = xcalloc(1, digestlen+1);
for (i = 0; i < digestlen; i += 2) {
static const char hex[] = "0123456789abcdef";
digest[i ] = hex[ (unsigned)((*s >> 4) & 0x0f) ];
digest[i+1] = hex[ (unsigned)((*s++ ) & 0x0f) ];
}
digest[digestlen] = '\0';
} else
rpmDigestFinal(ctx, (void **)&digest, &digestlen, asAscii);
(void) rpmswNow(&end);
if (digest) {
fprintf(stdout, "%s %s\n", digest, ifn);
@ -97,6 +125,7 @@ main(int argc, const char *argv[])
appendix);
fflush(stdout);
}
fprintf(stderr, "*** time %lu usecs\n", (unsigned long)rpmswDiff(&end, &begin));
return 0;
}