From dc2f0497fdfded94ef783b9a34943f26c85aba2b Mon Sep 17 00:00:00 2001 From: mdw Date: Fri, 10 Dec 1999 23:20:03 +0000 Subject: [PATCH] New hash interface requirements. --- md4.c | 18 ++++++++++++++---- md4.h | 19 +++++++++++++++---- md5.c | 18 ++++++++++++++---- md5.h | 19 +++++++++++++++---- rmd160.c | 18 ++++++++++++++---- rmd160.h | 19 +++++++++++++++---- sha.c | 22 ++++++++++++++++------ sha.h | 19 +++++++++++++++---- 8 files changed, 118 insertions(+), 34 deletions(-) diff --git a/md4.c b/md4.c index 406c3a0..19c74d2 100644 --- a/md4.c +++ b/md4.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md4.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: md4.c,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The MD4 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: md4.c,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -39,6 +42,8 @@ #include +#include "ghash.h" +#include "ghash-def.h" #include "hash.h" #include "md4.h" @@ -168,7 +173,7 @@ void md4_init(md4_ctx *ctx) ctx->c = 0x98badcfe; ctx->d = 0x10325476; ctx->off = 0; - ctx->count = 0; + ctx->nl = ctx->nh = 0; } /* --- @md4_set@ --- * @@ -192,7 +197,8 @@ void md4_set(md4_ctx *ctx, const void *buf, unsigned long count) ctx->c = LOAD32_L(p + 8); ctx->d = LOAD32_L(p + 12); ctx->off = 0; - ctx->count = count; + ctx->nl = U32(count); + ctx->nh = U32((count >> 16) >> 16); } /* --- @md4_hash@ --- * @@ -250,9 +256,13 @@ unsigned long md4_state(md4_ctx *ctx, void *state) STORE32_L(p + 4, ctx->b); STORE32_L(p + 8, ctx->c); STORE32_L(p + 12, ctx->d); - return (ctx->count); + return (ctx->nl | ((ctx->nh >> 16) >> 16)); } +/* --- Generic interface --- */ + +GHASH_DEF(MD4, md4) + /* --- Test rig --- */ HASH_TEST(MD4, md4) diff --git a/md4.h b/md4.h index 1697814..80ad906 100644 --- a/md4.h +++ b/md4.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md4.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: md4.h,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The MD4 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: md4.h,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -44,8 +47,8 @@ * cryptographically strong, 'cos it ain't. */ -#ifndef MD4_H -#define MD4_H +#ifndef CATACOMB_MD4_H +#define CATACOMB_MD4_H #ifdef __cplusplus extern "C" { @@ -55,6 +58,10 @@ #include +#ifndef CATACOMB_GHASH_H +# include "ghash.h" +#endif + /*----- Magic numbers -----------------------------------------------------*/ #define MD4_BUFSZ 64 @@ -64,7 +71,7 @@ typedef struct md4_ctx { uint32 a, b, c, d; /* Chaining variables */ - unsigned long count; /* Byte count so far */ + uint32 nl, nh; /* Byte count so far */ int off; /* Offset into buffer */ octet buf[MD4_BUFSZ]; /* Accumulation buffer */ } md4_ctx; @@ -149,6 +156,10 @@ extern void md4_done(md4_ctx */*ctx*/, void */*hash*/); extern unsigned long md4_state(md4_ctx */*ctx*/, void */*state*/); +/*----- Generic hash interface --------------------------------------------*/ + +extern const gchash md4; + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus diff --git a/md5.c b/md5.c index c6e2a2a..55a0aaa 100644 --- a/md5.c +++ b/md5.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md5.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: md5.c,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The MD5 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: md5.c,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -39,6 +42,8 @@ #include +#include "ghash.h" +#include "ghash-def.h" #include "hash.h" #include "md5.h" @@ -187,7 +192,7 @@ void md5_init(md5_ctx *ctx) ctx->c = 0x98badcfe; ctx->d = 0x10325476; ctx->off = 0; - ctx->count = 0; + ctx->nl = ctx->nh = 0; } /* --- @md5_set@ --- * @@ -211,7 +216,8 @@ void md5_set(md5_ctx *ctx, const void *buf, unsigned long count) ctx->c = LOAD32_L(p + 8); ctx->d = LOAD32_L(p + 12); ctx->off = 0; - ctx->count = count; + ctx->nl = U32(count); + ctx->nh = U32((count >> 16) >> 16); } /* --- @md5_hash@ --- * @@ -269,9 +275,13 @@ unsigned long md5_state(md5_ctx *ctx, void *state) STORE32_L(p + 4, ctx->b); STORE32_L(p + 8, ctx->c); STORE32_L(p + 12, ctx->d); - return (ctx->count); + return (ctx->nl | ((ctx->nh << 16) << 16)); } +/* --- Generic interface --- */ + +GHASH_DEF(MD5, md5) + /* --- Test code --- */ HASH_TEST(MD5, md5) diff --git a/md5.h b/md5.h index 8c54e6d..ca08dd1 100644 --- a/md5.h +++ b/md5.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md5.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: md5.h,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The MD5 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: md5.h,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -45,8 +48,8 @@ * applications. It's also still useful in constructions such as HMAC. */ -#ifndef MD5_H -#define MD5_H +#ifndef CATACOMB_MD5_H +#define CATACOMB_MD5_H #ifdef __cplusplus extern "C" { @@ -56,6 +59,10 @@ #include +#ifndef CATACOMB_GHASH_H +# include "ghash.h" +#endif + /*----- Magic numbers -----------------------------------------------------*/ #define MD5_BUFSZ 64 @@ -65,7 +72,7 @@ typedef struct md5_ctx { uint32 a, b, c, d; /* Chaining variables */ - unsigned long count; /* Byte count so far */ + uint32 nl, nh; /* Byte count so far */ int off; /* Offset into buffer */ octet buf[MD5_BUFSZ]; /* Accumulation buffer */ } md5_ctx; @@ -150,6 +157,10 @@ extern void md5_done(md5_ctx */*ctx*/, void */*hash*/); extern unsigned long md5_state(md5_ctx */*ctx*/, void */*state*/); +/*----- Generic hash interface --------------------------------------------*/ + +extern const gchash md5; + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus diff --git a/rmd160.c b/rmd160.c index a42c21c..60b67a7 100644 --- a/rmd160.c +++ b/rmd160.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd160.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: rmd160.c,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The RIPEMD-160 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd160.c,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -39,6 +42,8 @@ #include +#include "ghash.h" +#include "ghash-def.h" #include "hash.h" #include "rmd160.h" @@ -307,7 +312,7 @@ void rmd160_init(rmd160_ctx *ctx) ctx->d = 0x10325476; ctx->e = 0xc3d2e1f0; ctx->off = 0; - ctx->count = 0; + ctx->nl = ctx->nh = 0; } /* --- @rmd160_set@ --- * @@ -332,7 +337,8 @@ void rmd160_set(rmd160_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32_L(p + 12); ctx->e = LOAD32_L(p + 16); ctx->off = 0; - ctx->count = count; + ctx->nl = U32(count); + ctx->nh = U32((count >> 16) >> 16); } /* --- @rmd160_hash@ --- * @@ -392,9 +398,13 @@ unsigned long rmd160_state(rmd160_ctx *ctx, void *state) STORE32_L(p + 8, ctx->c); STORE32_L(p + 12, ctx->d); STORE32_L(p + 16, ctx->e); - return (ctx->count); + return (ctx->nl | ((ctx->nh << 16) << 16)); } +/* --- Generic interface --- */ + +GHASH_DEF(RMD160, rmd160) + /* --- Test code --- */ HASH_TEST(RMD160, rmd160) diff --git a/rmd160.h b/rmd160.h index 5aa9579..1022ddf 100644 --- a/rmd160.h +++ b/rmd160.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd160.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: rmd160.h,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * The RIPEMD-160 message digest function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd160.h,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -45,8 +48,8 @@ * best alternative hash function. */ -#ifndef RMD160_H -#define RMD160_H +#ifndef CATACOMB_RMD160_H +#define CATACOMB_RMD160_H #ifdef __cplusplus extern "C" { @@ -56,6 +59,10 @@ #include +#ifndef CATACOMB_GHASH_H +# include "ghash.h" +#endif + /*----- Magic numbers -----------------------------------------------------*/ #define RMD160_BUFSZ 64 @@ -65,7 +72,7 @@ typedef struct rmd160_ctx { uint32 a, b, c, d, e; /* Chaining variables */ - unsigned long count; /* Byte count so far */ + uint32 nl, nh; /* Byte count so far */ int off; /* Offset into buffer */ octet buf[RMD160_BUFSZ]; /* Accumulation buffer */ } rmd160_ctx; @@ -151,6 +158,10 @@ extern void rmd160_done(rmd160_ctx */*ctx*/, void */*hash*/); extern unsigned long rmd160_state(rmd160_ctx */*ctx*/, void */*state*/); +/*----- Generic hash interface --------------------------------------------*/ + +extern const gchash rmd160; + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus diff --git a/sha.c b/sha.c index a5a3bf3..2fe1846 100644 --- a/sha.c +++ b/sha.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sha.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: sha.c,v 1.2 1999/12/10 23:20:03 mdw Exp $ * * Implementation of the SHA-1 hash function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: sha.c,v $ + * Revision 1.2 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -39,6 +42,8 @@ #include +#include "ghash.h" +#include "ghash-def.h" #include "hash.h" #include "sha.h" @@ -209,7 +214,7 @@ void sha_init(sha_ctx *ctx) ctx->d = 0x10325476; ctx->e = 0xc3d2e1f0; ctx->off = 0; - ctx->count = 0; + ctx->nl = ctx->nh = 0; } /* --- @sha_set@ --- * @@ -234,7 +239,8 @@ void sha_set(sha_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32(p + 12); ctx->e = LOAD32(p + 16); ctx->off = 0; - ctx->count = count; + ctx->nl = U32(count); + ctx->nh = U32((count >> 16) >> 16); } /* --- @sha_hash@ --- * @@ -268,8 +274,8 @@ void sha_done(sha_ctx *ctx, void *hash) { octet *p = hash; HASH_PAD(SHA, sha, ctx, 0x80, 0, 8); - STORE32(ctx->buf + SHA_BUFSZ - 8, ctx->count >> 29); - STORE32(ctx->buf + SHA_BUFSZ - 4, ctx->count << 3); + STORE32(ctx->buf + SHA_BUFSZ - 8, (ctx->nl >> 29) | (ctx->nh << 3)); + STORE32(ctx->buf + SHA_BUFSZ - 4, ctx->nl << 3); sha_compress(ctx, ctx->buf); STORE32(p + 0, ctx->a); STORE32(p + 4, ctx->b); @@ -297,9 +303,13 @@ unsigned long sha_state(sha_ctx *ctx, void *state) STORE32(p + 8, ctx->c); STORE32(p + 12, ctx->d); STORE32(p + 16, ctx->e); - return (ctx->count); + return (ctx->nl | ((ctx->nh << 16) << 16)); } +/* --- Generic interface --- */ + +GHASH_DEF(SHA, sha) + /* --- Test code --- */ HASH_TEST(SHA, sha) diff --git a/sha.h b/sha.h index ec00cc9..c231da0 100644 --- a/sha.h +++ b/sha.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sha.h,v 1.2 1999/11/19 13:20:08 mdw Exp $ + * $Id: sha.h,v 1.3 1999/12/10 23:20:03 mdw Exp $ * * Implementation of the SHA-1 hash function * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: sha.h,v $ + * Revision 1.3 1999/12/10 23:20:03 mdw + * New hash interface requirements. + * * Revision 1.2 1999/11/19 13:20:08 mdw * Modify notes section slightly. * @@ -47,8 +50,8 @@ * RIPEMD-160, for no particularly good reasons. */ -#ifndef SHA_H -#define SHA_H +#ifndef CATACOMB_SHA_H +#define CATACOMB_SHA_H #ifdef __cplusplus extern "C" { @@ -58,6 +61,10 @@ #include +#ifndef CATACOMB_GHASH_H +# include "ghash.h" +#endif + /*----- Magic numbers -----------------------------------------------------*/ #define SHA_BUFSZ 64 @@ -67,7 +74,7 @@ typedef struct sha_ctx { uint32 a, b, c, d, e; /* Chaining variables */ - unsigned long count; /* Byte count so far */ + uint32 nl, nh; /* Byte count so far */ int off; /* Offset into buffer */ octet buf[SHA_BUFSZ]; /* Accumulation buffer */ } sha_ctx; @@ -152,6 +159,10 @@ extern void sha_done(sha_ctx */*ctx*/, void */*hash*/); extern unsigned long sha_state(sha_ctx */*ctx*/, void */*state*/); +/*----- Generic hash interface --------------------------------------------*/ + +extern const gchash sha; + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus -- 2.11.0