summaryrefslogtreecommitdiff
path: root/rpmio
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-03-28 22:11:06 +0000
committerjbj <devnull@localhost>2003-03-28 22:11:06 +0000
commit485f497e21a63a7d9dd75f2197b5223a5965959c (patch)
tree7110dd9f602d9e5709e78683b496ddb0013edde3 /rpmio
parent53f81816ea838ac251ea69b9b143f2ac764ec5b5 (diff)
downloadrpm-485f497e21a63a7d9dd75f2197b5223a5965959c.tar.gz
rpm-485f497e21a63a7d9dd75f2197b5223a5965959c.tar.bz2
rpm-485f497e21a63a7d9dd75f2197b5223a5965959c.zip
Add gcrypt to tdigest.
CVS patchset: 6722 CVS date: 2003/03/28 22:11:06
Diffstat (limited to 'rpmio')
-rw-r--r--rpmio/Makefile.am2
-rw-r--r--rpmio/rpmsw.c2
-rw-r--r--rpmio/tdigest.c49
3 files changed, 41 insertions, 12 deletions
diff --git a/rpmio/Makefile.am b/rpmio/Makefile.am
index 1202039d2..72e18c67f 100644
--- a/rpmio/Makefile.am
+++ b/rpmio/Makefile.am
@@ -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
diff --git a/rpmio/rpmsw.c b/rpmio/rpmsw.c
index 9824221b4..1e70f7d87 100644
--- a/rpmio/rpmsw.c
+++ b/rpmio/rpmsw.c
@@ -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)
diff --git a/rpmio/tdigest.c b/rpmio/tdigest.c
index 9b2428f12..7f36d13da 100644
--- a/rpmio/tdigest.c
+++ b/rpmio/tdigest.c
@@ -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;
}