From: jbj Date: Fri, 19 Oct 2001 01:35:57 +0000 (+0000) Subject: Rewire digests, step 2. X-Git-Tag: rpm-4.4-release~1397 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca1d809cb1d9125b7029e2d5d378d2a04955f178;p=platform%2Fupstream%2Frpm.git Rewire digests, step 2. CVS patchset: 5122 CVS date: 2001/10/19 01:35:57 --- diff --git a/build/pack.c b/build/pack.c index e0b40c7..d784e20 100644 --- a/build/pack.c +++ b/build/pack.c @@ -514,13 +514,13 @@ int writeRPM(Header *hdrp, const char *fileName, int type, sigtarget, Fstrerror(fd)); } - fdInitSHA1(fd, 0); + fdInitDigest(fd, PGPHASHALGO_SHA1, 0); if (headerWrite(fd, h, HEADER_MAGIC_NO)) { rc = RPMERR_NOSPACE; rpmError(RPMERR_NOSPACE, _("Unable to write final header\n")); } (void) Fflush(fd); - fdFiniSHA1(fd, (void **)&sha1, NULL, 1); + fdFiniDigest(fd, (void **)&sha1, NULL, 1); (void) Fclose(fd); fd = NULL; diff --git a/lib/fsm.c b/lib/fsm.c index 7457e60..51f9470 100644 --- a/lib/fsm.c +++ b/lib/fsm.c @@ -696,7 +696,7 @@ static int expandRegular(/*@special@*/ FSM_t fsm) fmd5sum = fsm->fmd5sum; if (st->st_size > 0 && fmd5sum) - fdInitMD5(fsm->wfd, 0); + fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0); while (left) { @@ -720,7 +720,7 @@ static int expandRegular(/*@special@*/ FSM_t fsm) const char * md5sum = NULL; (void) Fflush(fsm->wfd); - fdFiniMD5(fsm->wfd, (void **)&md5sum, NULL, 1); + fdFiniDigest(fsm->wfd, (void **)&md5sum, NULL, 1); if (md5sum == NULL) { rc = CPIOERR_MD5SUM_MISMATCH; diff --git a/lib/misc.c b/lib/misc.c index 427dec7..efa31c6 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -33,11 +33,11 @@ int domd5(const char * fn, unsigned char * digest, int asAscii) return 1; } - fdInitMD5(fd, 0); + fdInitDigest(fd, PGPHASHALGO_MD5, 0); while ((rc = Fread(buf, sizeof(buf[0]), sizeof(buf), fd)) > 0) {}; - fdFiniMD5(fd, (void **)&md5sum, &md5len, asAscii); + fdFiniDigest(fd, (void **)&md5sum, &md5len, asAscii); if (Ferror(fd)) rc = 1; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 76502a5..7ea354d 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -94,15 +94,15 @@ static int copyFile(FD_t *sfdp, const char **sfnp, /*@-type@*/ /* FIX: cast? */ if (dig != NULL) { - dig->md5ctx = rpmDigestInit(RPMDIGEST_MD5); - (void) fdInitSHA1(*sfdp, 0); + (void) fdInitDigest(*sfdp, PGPHASHALGO_MD5, 0); + dig->sha1ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE); } /*@=type@*/ while ((count = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), *sfdp)) > 0) { /*@-type@*/ /* FIX: cast? */ if (dig) - rpmDigestUpdate(dig->md5ctx, buffer, count); + (void) rpmDigestUpdate(dig->sha1ctx, buffer, count); /*@=type@*/ if (Fwrite(buffer, sizeof(buffer[0]), count, *tfdp) != count) { @@ -118,8 +118,8 @@ static int copyFile(FD_t *sfdp, const char **sfnp, /*@-type@*/ /* FIX: cast? */ if (dig != NULL) { - dig->sha1ctx = _free(dig->sha1ctx); - dig->sha1ctx = (*sfdp)->digest; + dig->md5ctx = _free(dig->md5ctx); + dig->md5ctx = (*sfdp)->digest; (*sfdp)->digest = NULL; } /*@=type@*/ @@ -358,8 +358,8 @@ fprintf(stderr, "========================= Package RSA Signature\n"); /*@-type@*/ /* FIX: cast? */ { DIGEST_CTX ctx = rpmDigestDup(dig->md5ctx); - rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); - rpmDigestFinal(ctx, (void **)&dig->md5, &dig->md5len, 1); + (void) rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); + (void) rpmDigestFinal(ctx, (void **)&dig->md5, &dig->md5len, 1); /* XXX compare leading 16 bits of digest for quick check. */ } @@ -402,8 +402,8 @@ fprintf(stderr, "========================= Package DSA Signature\n"); (void) pgpPrtPkts(ptr, count, dig, rpmIsVerbose()); /*@-type@*/ /* FIX: cast? */ { DIGEST_CTX ctx = rpmDigestDup(dig->sha1ctx); - rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); - rpmDigestFinal(ctx, (void **)&dig->sha1, &dig->sha1len, 1); + (void) rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); + (void) rpmDigestFinal(ctx, (void **)&dig->sha1, &dig->sha1len, 1); mp32nzero(&dig->hm); mp32nsethex(&dig->hm, dig->sha1); } /*@=type@*/ @@ -567,10 +567,10 @@ fprintf(stderr, "========================= Red Hat DSA Public Key\n"); (void) unlink(sigtarget); sigtarget = _free(sigtarget); } - dig->sha1ctx = _free(dig->sha1ctx); - dig->sha1 = _free(dig->sha1); dig->md5ctx = _free(dig->md5ctx); dig->md5 = _free(dig->md5); + dig->sha1ctx = _free(dig->sha1ctx); + dig->sha1 = _free(dig->sha1); dig->hash_data = _free(dig->hash_data); mp32nfree(&dig->hm); @@ -584,10 +584,10 @@ fprintf(stderr, "========================= Red Hat DSA Public Key\n"); } /*@=branchstate@*/ - dig->sha1ctx = _free(dig->sha1ctx); - dig->sha1 = _free(dig->sha1); dig->md5ctx = _free(dig->md5ctx); dig->md5 = _free(dig->md5); + dig->sha1ctx = _free(dig->sha1ctx); + dig->sha1 = _free(dig->sha1); dig->hash_data = _free(dig->hash_data); mp32bfree(&dig->p); diff --git a/lib/verify.c b/lib/verify.c index 44a7115..612ff0f 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -312,18 +312,12 @@ int rpmVerifyDigest(Header h) int_32 uhc; const char * hdigest; rpmTagType hdt; - int flags = RPMDIGEST_SHA1; int ec = 0; /* assume no problems */ /* Retrieve header digest. */ if (!hge(h, RPMTAG_SHA1HEADER, &hdt, (void **) &hdigest, NULL) && !hge(h, RPMTAG_SHA1RHN, &hdt, (void **) &hdigest, NULL)) { -#ifdef DYING - if (hge(h, RPMTAG_BADSHA1HEADER, &hdt, (void **) &hdigest, NULL)) - flags |= (RPMDIGEST_REVERSE|RPMDIGEST_BCSWAP); - else -#endif return 0; } /* Regenerate original header. */ @@ -334,12 +328,12 @@ int rpmVerifyDigest(Header h) return 0; /* Compute header digest. */ - { DIGEST_CTX ctx = rpmDigestInit(flags); + { DIGEST_CTX ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE); const char * digest; size_t digestlen; - rpmDigestUpdate(ctx, uh, uhc); - rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1); + (void) rpmDigestUpdate(ctx, uh, uhc); + (void) rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1); /* XXX can't happen: report NULL malloc return as a digest failure. */ ec = (digest == NULL || strcmp(hdigest, digest)) ? 1 : 0; diff --git a/po/rpm.pot b/po/rpm.pot index ca6cb35..5fb7477 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-10-18 21:22-0400\n" +"POT-Creation-Date: 2001-10-18 21:28-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3442,27 +3442,27 @@ msgstr "" msgid "package lacks both group name and id lists (this should never happen)\n" msgstr "" -#: lib/verify.c:404 +#: lib/verify.c:398 #, c-format msgid "missing %s" msgstr "" -#: lib/verify.c:501 +#: lib/verify.c:495 #, c-format msgid "Unsatisfied dependencies for %s-%s-%s: " msgstr "" -#: lib/verify.c:543 +#: lib/verify.c:537 #, c-format msgid "%s-%s-%s: immutable header region digest check failed\n" msgstr "" -#: rpmdb/db1.c:101 rpmdb/db3.c:98 +#: rpmdb/db1.c:101 rpmdb/db3.c:100 #, c-format msgid "db%d error(%d) from %s: %s\n" msgstr "" -#: rpmdb/db1.c:104 rpmdb/db3.c:101 +#: rpmdb/db1.c:104 rpmdb/db3.c:103 #, c-format msgid "db%d error(%d): %s\n" msgstr "" @@ -3505,50 +3505,50 @@ msgstr "" msgid "cannot get %s lock on database\n" msgstr "" -#: rpmdb/db1.c:576 rpmdb/db3.c:1209 +#: rpmdb/db1.c:576 rpmdb/db3.c:1211 msgid "exclusive" msgstr "" -#: rpmdb/db1.c:576 rpmdb/db3.c:1209 +#: rpmdb/db1.c:576 rpmdb/db3.c:1211 msgid "shared" msgstr "" -#: rpmdb/db3.c:129 +#: rpmdb/db3.c:131 #, c-format msgid "closed db environment %s/%s\n" msgstr "" -#: rpmdb/db3.c:147 +#: rpmdb/db3.c:149 #, c-format msgid "removed db environment %s/%s\n" msgstr "" -#: rpmdb/db3.c:188 +#: rpmdb/db3.c:190 #, c-format msgid "opening db environment %s/%s %s\n" msgstr "" -#: rpmdb/db3.c:708 +#: rpmdb/db3.c:710 #, c-format msgid "closed db index %s/%s\n" msgstr "" -#: rpmdb/db3.c:773 +#: rpmdb/db3.c:775 #, c-format msgid "verified db index %s/%s\n" msgstr "" -#: rpmdb/db3.c:986 +#: rpmdb/db3.c:988 #, c-format msgid "opening db index %s/%s %s mode=0x%x\n" msgstr "" -#: rpmdb/db3.c:1207 +#: rpmdb/db3.c:1209 #, c-format msgid "cannot get %s lock on %s/%s\n" msgstr "" -#: rpmdb/db3.c:1213 +#: rpmdb/db3.c:1215 #, c-format msgid "locked db index %s/%s\n" msgstr "" @@ -3840,59 +3840,59 @@ msgstr "" msgid "File %s is smaller than %u bytes\n" msgstr "" -#: rpmio/rpmio.c:632 +#: rpmio/rpmio.c:644 msgid "Success" msgstr "" -#: rpmio/rpmio.c:635 +#: rpmio/rpmio.c:647 msgid "Bad server response" msgstr "" -#: rpmio/rpmio.c:638 +#: rpmio/rpmio.c:650 msgid "Server I/O error" msgstr "" -#: rpmio/rpmio.c:641 +#: rpmio/rpmio.c:653 msgid "Server timeout" msgstr "" -#: rpmio/rpmio.c:644 +#: rpmio/rpmio.c:656 msgid "Unable to lookup server host address" msgstr "" -#: rpmio/rpmio.c:647 +#: rpmio/rpmio.c:659 msgid "Unable to lookup server host name" msgstr "" -#: rpmio/rpmio.c:650 +#: rpmio/rpmio.c:662 msgid "Failed to connect to server" msgstr "" -#: rpmio/rpmio.c:653 +#: rpmio/rpmio.c:665 msgid "Failed to establish data connection to server" msgstr "" -#: rpmio/rpmio.c:656 +#: rpmio/rpmio.c:668 msgid "I/O error to local file" msgstr "" -#: rpmio/rpmio.c:659 +#: rpmio/rpmio.c:671 msgid "Error setting remote server to passive mode" msgstr "" -#: rpmio/rpmio.c:662 +#: rpmio/rpmio.c:674 msgid "File not found on server" msgstr "" -#: rpmio/rpmio.c:665 +#: rpmio/rpmio.c:677 msgid "Abort in progress" msgstr "" -#: rpmio/rpmio.c:669 +#: rpmio/rpmio.c:681 msgid "Unknown or unexpected error" msgstr "" -#: rpmio/rpmio.c:1341 +#: rpmio/rpmio.c:1353 #, c-format msgid "logging into %s as %s, pw %s\n" msgstr "" diff --git a/python/Makefile.am b/python/Makefile.am index 95db6a9..487d89b 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -9,6 +9,7 @@ INCLUDES = \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/rpmdb \ -I$(top_srcdir)/rpmio \ + -I$(top_srcdir)/beecrypt \ -I$(top_srcdir)/popt \ -I/usr/include/python${PYVER} \ @INCPATH@ diff --git a/python/Makefile.in b/python/Makefile.in index 1a58cde..98ea3a4 100644 --- a/python/Makefile.in +++ b/python/Makefile.in @@ -192,6 +192,7 @@ INCLUDES = \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/rpmdb \ -I$(top_srcdir)/rpmio \ + -I$(top_srcdir)/beecrypt \ -I$(top_srcdir)/popt \ -I/usr/include/python${PYVER} \ @INCPATH@ diff --git a/python/rpmmodule.c b/python/rpmmodule.c index e162706..115dcc8 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -475,7 +475,7 @@ static PyObject * rhnUnload(hdrObject * s, PyObject * args) { headerGetEntry(h, RPMTAG_HEADERIMMUTABLE, &uht, (void **)&uh, &uhc); - ctx = rpmDigestInit(RPMDIGEST_SHA1); + ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE); rpmDigestUpdate(ctx, uh, uhc); rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1); diff --git a/rpmdb/db3.c b/rpmdb/db3.c index d0d27a2..46c6330 100644 --- a/rpmdb/db3.c +++ b/rpmdb/db3.c @@ -13,12 +13,14 @@ static int _debug = 1; /* XXX if < 0 debugging, > 0 unusual error returns */ #endif #if defined(__LCLINT__) +/*@-redef@*/ /* FIX: rpmio/rpmio.c also declares */ typedef unsigned int u_int32_t; typedef unsigned short u_int16_t; typedef unsigned char u_int8_t; /*@-incondefs@*/ /* LCLint 3.0.0.15 */ typedef int int32_t; /*@=incondefs@*/ +/*@=redef@*/ #endif #include diff --git a/rpmio/digest.c b/rpmio/digest.c index 4c51914..af4f8c0 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -23,8 +23,9 @@ */ struct DIGEST_CTX_s { rpmDigestFlags flags; /*!< Bit(s) to control digest operation. */ - uint32 digestlen; /*!< No. bytes of digest. */ uint32 datalen; /*!< No. bytes in block of plaintext data. */ + uint32 paramlen; /*!< No. bytes of digest parameters. */ + uint32 digestlen; /*!< No. bytes of digest. */ void * param; /*!< Digest parameters. */ int (*Reset) (void * param) /*@modifies param @*/; /*!< Digest initialize. */ @@ -37,60 +38,70 @@ struct DIGEST_CTX_s { DIGEST_CTX rpmDigestDup(DIGEST_CTX octx) { - DIGEST_CTX nctx = xcalloc(1, sizeof(*nctx)); - memcpy(nctx, octx, sizeof(*nctx)); + DIGEST_CTX nctx = memcpy(xcalloc(1, sizeof(*nctx)), octx, sizeof(*nctx)); + nctx->param = memcpy(xcalloc(1, nctx->paramlen), octx->param, nctx->paramlen); return nctx; } DIGEST_CTX -rpmDigestInit(rpmDigestFlags flags) +rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags) { DIGEST_CTX ctx = xcalloc(1, sizeof(*ctx)); + int xx; ctx->flags = flags; - if (flags & RPMDIGEST_MD5) { + switch (hashalgo) { + case PGPHASHALGO_MD5: ctx->digestlen = 16; ctx->datalen = 64; /*@-sizeoftype@*/ /* FIX: union, not void pointer */ - ctx->param = xcalloc(1, sizeof(md5Param)); + ctx->paramlen = sizeof(md5Param); /*@=sizeoftype@*/ + ctx->param = xcalloc(1, ctx->paramlen); /*@-type@*/ /* FIX: cast? */ ctx->Reset = (void *) md5Reset; ctx->Update = (void *) md5Update; ctx->Digest = (void *) md5Digest; /*@=type@*/ - } - - if (flags & RPMDIGEST_SHA1) { + break; + case PGPHASHALGO_SHA1: ctx->digestlen = 20; ctx->datalen = 64; /*@-sizeoftype@*/ /* FIX: union, not void pointer */ - ctx->param = xcalloc(1, sizeof(sha1Param)); + ctx->paramlen = sizeof(sha1Param); /*@=sizeoftype@*/ + ctx->param = xcalloc(1, ctx->paramlen); /*@-type@*/ /* FIX: cast? */ ctx->Reset = (void *) sha1Reset; ctx->Update = (void *) sha1Update; ctx->Digest = (void *) sha1Digest; /*@=type@*/ + break; + case PGPHASHALGO_RIPEMD160: + case PGPHASHALGO_MD2: + case PGPHASHALGO_TIGER192: + case PGPHASHALGO_HAVAL_5_160: + default: + free(ctx); + return NULL; + /*@notreached@*/ break; } - /*@-noeffectuncon@*/ /* FIX: check rc */ - (void) (*ctx->Reset) (ctx->param); - /*@=noeffectuncon@*/ /* FIX: check rc */ + xx = (*ctx->Reset) (ctx->param); DPRINTF((stderr, "*** Init(%x) ctx %p param %p\n", flags, ctx, ctx->param)); return ctx; } -void +/*@-mustmod@*/ /* LCL: ctx->param may be modified, but ctx is abstract @*/ +int rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len) { DPRINTF((stderr, "*** Update(%p,%p,%d) param %p \"%s\"\n", ctx, data, len, ctx->param, ((char *)data))); - /*@-noeffectuncon@*/ /* FIX: check rc */ - (void) (*ctx->Update) (ctx->param, data, len); - /*@=noeffectuncon@*/ + return (*ctx->Update) (ctx->param, data, len); } +/*@=mustmod@*/ /*@unchecked@*/ static int _ie = 0x44332211; @@ -104,7 +115,7 @@ static union _dendian { #define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') #define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') -void +int rpmDigestFinal(/*@only@*/ DIGEST_CTX ctx, /*@out@*/ void ** datap, /*@out@*/ size_t *lenp, int asAscii) { @@ -150,7 +161,9 @@ DPRINTF((stderr, "*** Final(%p,%p,%p,%d) param %p digest %p\n", ctx, datap, lenp memset(digest, 0, ctx->digestlen); /* In case it's sensitive */ free(digest); } + memset(ctx->param, 0, ctx->paramlen); /* In case it's sensitive */ free(ctx->param); memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ free(ctx); + return 0; } diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 91a9edb..36478fc 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -15,6 +15,18 @@ #if HAVE_NETINET_IN_SYSTM_H # include + +#if defined(__LCLINT__) +/*@-redef@*/ /* FIX: rpmdb/db3.c also declares */ +typedef unsigned int u_int32_t; +typedef unsigned short u_int16_t; +typedef unsigned char u_int8_t; +/*@-incondefs@*/ /* LCLint 3.0.0.15 */ +typedef int int32_t; +/*@=incondefs@*/ +/*@=redef@*/ +#endif + # include #endif @@ -358,7 +370,7 @@ ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count) rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->digest && rc > 0) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); /*@-modfilesys@*/ DBGIO(fd, (stderr, "==>\tfdRead(%p,%p,%ld) rc %ld %s\n", cookie, buf, (long)count, (long)rc, fdbg(fd))); @@ -377,7 +389,7 @@ ssize_t fdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) rpmDigestUpdate(fd->digest, buf, count); + if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); if (fd->wr_chunked) { char chunksize[20]; @@ -2176,7 +2188,7 @@ DBGIO(fd, (stderr, "==>\tgzdRead(%p,%p,%u) rc %lx %s\n", cookie, buf, (unsigned) } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); /*@-compdef@*/ - if (fd->digest && rc > 0) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); /*@=compdef@*/ } return rc; @@ -2193,7 +2205,7 @@ static ssize_t gzdWrite(void * cookie, const char * buf, size_t count) if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) rpmDigestUpdate(fd->digest, buf, count); + if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); gzfile = gzdFileno(fd); fdstat_enter(fd, FDSTAT_WRITE); @@ -2410,7 +2422,7 @@ static ssize_t bzdRead(void * cookie, /*@out@*/ char * buf, size_t count) } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); /*@-compdef@*/ - if (fd->digest && rc > 0) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); /*@=compdef@*/ } return rc; @@ -2429,7 +2441,7 @@ static ssize_t bzdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) rpmDigestUpdate(fd->digest, buf, count); + if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); bzfile = bzdFileno(fd); fdstat_enter(fd, FDSTAT_WRITE); diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index c91df87..7fc3db8 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -8,6 +8,7 @@ #include #include +#include /** \ingroup rpmio */ @@ -49,14 +50,15 @@ typedef /*@abstract@*/ struct { * Bit(s) to control digest operation. */ typedef enum rpmDigestFlags_e { + RPMDIGEST_NONE = 0, +#ifdef DYING RPMDIGEST_MD5 = (1 << 0), /*!< MD5 digest. */ RPMDIGEST_SHA1 = (1 << 1) /*!< SHA1 digest. */ -#ifdef DYING RPMDIGEST_REVERSE = (1 << 16), /*!< Should bytes be reversed? */ RPMDIGEST_BCSWAP = (1 << 17), /*!< Should bit count be reversed? */ +#define RPMDIGEST_MASK 0xffff #endif } rpmDigestFlags; -#define RPMDIGEST_MASK 0xffff /** */ @@ -78,7 +80,7 @@ DIGEST_CTX rpmDigestDup(DIGEST_CTX octx) * @return digest context */ /*@only@*/ -DIGEST_CTX rpmDigestInit(rpmDigestFlags flags) +DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags) /*@*/; /** \ingroup rpmio @@ -86,8 +88,9 @@ DIGEST_CTX rpmDigestInit(rpmDigestFlags flags) * @param ctx digest context * @param data next data buffer * @param len no. bytes of data + * @return 0 on success */ -void rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len) +int rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len) /*@modifies ctx @*/; /** \ingroup rpmio @@ -99,8 +102,9 @@ void rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len) * @retval datap address of returned digest * @retval lenp address of digest length * @param asAscii return digest as ascii string? + * @return 0 on success */ -void rpmDigestFinal(/*@only@*/ DIGEST_CTX ctx, +int rpmDigestFinal(/*@only@*/ DIGEST_CTX ctx, /*@null@*/ /*@out@*/ void ** datap, /*@null@*/ /*@out@*/ size_t * lenp, int asAscii) /*@modifies *datap, *lenp @*/; @@ -448,14 +452,44 @@ FD_t c2f(/*@null@*/ void * cookie) /** \ingroup rpmio */ /*@unused@*/ static inline +void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags) + /*@modifies fd @*/ +{ + fd->digest = rpmDigestInit(hashalgo, flags); +} + +/** \ingroup rpmio + */ +/*@unused@*/ static inline +void fdFiniDigest(FD_t fd, + /*@null@*/ /*@out@*/ void ** datap, + /*@null@*/ /*@out@*/ size_t * lenp, + int asAscii) + /*@modifies fd, *datap, *lenp @*/ +{ + if (fd->digest == NULL) { + if (datap) *datap = NULL; + if (lenp) *lenp = 0; + return; + } + /*@-mayaliasunique@*/ + (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); + /*@=mayaliasunique@*/ + fd->digest = NULL; +} + +#ifdef DYING +/** \ingroup rpmio + */ +/*@unused@*/ static inline void fdInitMD5(FD_t fd, int flags) /*@modifies fd @*/ { #ifdef DYING if (flags) flags = RPMDIGEST_REVERSE; -#endif flags |= RPMDIGEST_MD5; - fd->digest = rpmDigestInit(flags); +#endif + fd->digest = rpmDigestInit(PGPHASHALGO_MD5, flags); } /** \ingroup rpmio @@ -466,9 +500,9 @@ void fdInitSHA1(FD_t fd, int flags) { #ifdef DYING if (flags) flags = RPMDIGEST_REVERSE; -#endif flags |= RPMDIGEST_SHA1; - fd->digest = rpmDigestInit(flags); +#endif + fd->digest = rpmDigestInit(PGPHASHALGO_SHA1, flags); } /** \ingroup rpmio @@ -486,7 +520,7 @@ void fdFiniMD5(FD_t fd, return; } /*@-mayaliasunique@*/ - rpmDigestFinal(fd->digest, datap, lenp, asAscii); + (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); /*@=mayaliasunique@*/ fd->digest = NULL; } @@ -506,10 +540,11 @@ void fdFiniSHA1(FD_t fd, return; } /*@-mayaliasunique@*/ - rpmDigestFinal(fd->digest, datap, lenp, asAscii); + (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); /*@=mayaliasunique@*/ fd->digest = NULL; } +#endif /*@-shadow@*/ /** \ingroup rpmio diff --git a/rpmio/tdigest.c b/rpmio/tdigest.c index ab9627e..da850ce 100644 --- a/rpmio/tdigest.c +++ b/rpmio/tdigest.c @@ -4,7 +4,8 @@ #include "debug.h" -static rpmDigestFlags flags = RPMDIGEST_MD5; +static pgpHashAlgo hashalgo = PGPHASHALGO_MD5; +static rpmDigestFlags flags = RPMDIGEST_NONE; extern int _rpmio_debug; static int fips = 0; @@ -14,14 +15,14 @@ const char * FIPSBdigest = "84983e441c3bd26ebaae4aa1f95129e5e54670f1"; const char * FIPSCdigest = "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; static struct poptOption optionsTable[] = { - { "md5", '\0', POPT_BIT_SET, &flags, RPMDIGEST_MD5, NULL, NULL }, - { "sha1",'\0', POPT_BIT_SET, &flags, RPMDIGEST_SHA1, NULL, NULL }, + { "md5", '\0', POPT_ARG_VAL, &hashalgo, PGPHASHALGO_MD5, NULL, NULL }, + { "sha1",'\0', POPT_ARG_VAL, &hashalgo, PGPHASHALGO_SHA1, NULL, NULL }, #ifdef DYING { "reverse",'\0', POPT_BIT_SET, &flags, RPMDIGEST_REVERSE, NULL, NULL }, #endif - { "fipsa",'\0', POPT_BIT_SET, &fips, 1, NULL, NULL }, - { "fipsb",'\0', POPT_BIT_SET, &fips, 2, NULL, NULL }, - { "fipsc",'\0', POPT_BIT_SET, &fips, 3, NULL, NULL }, + { "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 }, { "debug",'d', POPT_ARG_VAL, &_rpmio_debug, -1, NULL, NULL }, POPT_AUTOHELP POPT_TABLEEND @@ -53,14 +54,11 @@ main(int argc, const char *argv[]) while ((rc = poptGetNextOpt(optCon)) > 0) ; - if (flags & RPMDIGEST_SHA1) flags &= ~RPMDIGEST_MD5; #ifdef DYING reverse = (flags & RPMDIGEST_REVERSE); #endif if (fips) { - flags &= ~RPMDIGEST_MD5; - flags |= RPMDIGEST_SHA1; - ctx = rpmDigestInit(flags); + ctx = rpmDigestInit(PGPHASHALGO_SHA1, flags); ifn = NULL; appendix = ' '; sdigest = NULL; @@ -117,7 +115,7 @@ main(int argc, const char *argv[]) se = buf; *se = '\0'; - se = stpcpy(se, ((flags & RPMDIGEST_SHA1) ? SHA1_CMD : MD5_CMD)); + se = stpcpy(se, ((hashalgo == PGPHASHALGO_SHA1) ? SHA1_CMD : MD5_CMD)); *se++ = ' '; se = stpcpy(se, ifn); if ((sfp = popen(buf, "r")) != NULL) { @@ -137,7 +135,7 @@ main(int argc, const char *argv[]) continue; } idigest = NULL; - (flags & RPMDIGEST_SHA1) ? fdInitSHA1(ifd, reverse) : fdInitMD5(ifd, reverse); + fdInitDigest(ifd, hashalgo, reverse); ofd = Fopen(ofn, "w.ufdio"); if (ofd == NULL || Ferror(ofd)) { @@ -148,24 +146,20 @@ main(int argc, const char *argv[]) continue; } odigest = NULL; - (flags & RPMDIGEST_SHA1) ? fdInitSHA1(ofd, reverse) : fdInitMD5(ofd, reverse); + fdInitDigest(ofd, hashalgo, reverse); - ctx = rpmDigestInit(flags); + ctx = rpmDigestInit(hashalgo, flags); while ((nb = Fread(buf, 1, sizeof(buf), ifd)) > 0) { rpmDigestUpdate(ctx, buf, nb); (void) Fwrite(buf, 1, nb, ofd); } - (flags & RPMDIGEST_SHA1) - ? fdFiniSHA1(ifd, (void **)&idigest, NULL, asAscii) - : fdFiniMD5(ifd, (void **)&idigest, NULL, asAscii); + fdFiniDigest(ifd, (void **)&idigest, NULL, asAscii); Fclose(ifd); Fflush(ofd); - (flags & RPMDIGEST_SHA1) - ? fdFiniSHA1(ofd, (void **)&odigest, NULL, asAscii) - : fdFiniMD5(ofd, (void **)&odigest, NULL, asAscii); + fdFiniDigest(ofd, (void **)&odigest, NULL, asAscii); Fclose(ofd); rpmDigestFinal(ctx, (void **)&digest, &digestlen, asAscii); diff --git a/rpmio/tkey.c b/rpmio/tkey.c index e03094b..caab066 100644 --- a/rpmio/tkey.c +++ b/rpmio/tkey.c @@ -143,13 +143,11 @@ fprintf(stderr, "=============================== GPG Signature of \"abc\"\n"); if ((rc = doit(abcSignatureDSA, dig, printing)) != 0) fprintf(stderr, "==> FAILED: rc %d\n", rc); - { DIGEST_CTX ctx = rpmDigestInit(RPMDIGEST_SHA1); + { DIGEST_CTX ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE); const char * digest = NULL; size_t digestlen = 0; const char * txt = "abc"; - ctx = rpmDigestInit(RPMDIGEST_SHA1); - rpmDigestUpdate(ctx, txt, strlen(txt)); rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1);