summaryrefslogtreecommitdiff
path: root/rpmio/digest.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2001-10-19 01:35:57 +0000
committerjbj <devnull@localhost>2001-10-19 01:35:57 +0000
commitca1d809cb1d9125b7029e2d5d378d2a04955f178 (patch)
tree927f851af4b890e3d70f2298a8a4d66f3a415242 /rpmio/digest.c
parentaaaaf45ba6713203598c5f0c1373bdb11f5e41fe (diff)
downloadrpm-ca1d809cb1d9125b7029e2d5d378d2a04955f178.tar.gz
rpm-ca1d809cb1d9125b7029e2d5d378d2a04955f178.tar.bz2
rpm-ca1d809cb1d9125b7029e2d5d378d2a04955f178.zip
Rewire digests, step 2.
CVS patchset: 5122 CVS date: 2001/10/19 01:35:57
Diffstat (limited to 'rpmio/digest.c')
-rw-r--r--rpmio/digest.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/rpmio/digest.c b/rpmio/digest.c
index 4c51914ee..af4f8c02d 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;
}