From c850c0da81ad9f72315f8e6e26bdfbd98daf9d89 Mon Sep 17 00:00:00 2001 From: mdw Date: Sun, 15 Oct 2000 19:09:20 +0000 Subject: [PATCH] Support HMAC mode for hash functions which need to store more state than the hash output size. --- hmac-def.h | 14 +++++++++----- hmac.h | 12 ++++++++---- md4.h | 7 ++++++- md5.h | 7 ++++++- rmd128.h | 7 ++++++- rmd160.h | 7 ++++++- rmd256.h | 7 ++++++- rmd320.h | 7 ++++++- sha.h | 7 ++++++- sha256.h | 7 ++++++- sha512.h | 8 +++++++- tiger.h | 7 ++++++- 12 files changed, 78 insertions(+), 19 deletions(-) diff --git a/hmac-def.h b/hmac-def.h index a8f2640..19df631 100644 --- a/hmac-def.h +++ b/hmac-def.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: hmac-def.h,v 1.4 2000/07/15 10:00:58 mdw Exp $ + * $Id: hmac-def.h,v 1.5 2000/10/15 19:09:20 mdw Exp $ * * Definitions for HMAC and NMAC * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: hmac-def.h,v $ + * Revision 1.5 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.4 2000/07/15 10:00:58 mdw * New generic hash operation for copying hash contexts. * @@ -89,7 +93,7 @@ \ /* --- Useful constants --- */ \ \ -const octet pre##_mackeysz[] = { KSZ_ANY, PRE##_HASHSZ }; \ +const octet pre##_mackeysz[] = { KSZ_ANY, PRE##_STATESZ }; \ \ /* --- @pre_nmacinit@ --- * \ * \ @@ -104,8 +108,8 @@ const octet pre##_mackeysz[] = { KSZ_ANY, PRE##_HASHSZ }; \ \ void pre##_nmacinit(pre##_mackey *key, const void *ok, const void *ik) \ { \ - memcpy(key->ochain, ok, PRE##_HASHSZ); \ - memcpy(key->ichain, ik, PRE##_HASHSZ); \ + memcpy(key->ochain, ok, PRE##_STATESZ); \ + memcpy(key->ichain, ik, PRE##_STATESZ); \ key->ocount = key->icount = 0; \ } \ \ @@ -169,7 +173,7 @@ void pre##_hmacinit(pre##_mackey *key, const void *k, size_t sz) \ \ void pre##_macinit(pre##_macctx *ctx, const pre##_mackey *key) \ { \ - memcpy(ctx->chain, key->ochain, PRE##_HASHSZ); \ + memcpy(ctx->chain, key->ochain, PRE##_STATESZ); \ ctx->count = key->ocount; \ pre##_set(&ctx->ctx, key->ichain, key->icount); \ } \ diff --git a/hmac.h b/hmac.h index 7ad01f7..b489e54 100644 --- a/hmac.h +++ b/hmac.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: hmac.h,v 1.3 2000/06/17 11:23:57 mdw Exp $ + * $Id: hmac.h,v 1.4 2000/10/15 19:09:20 mdw Exp $ * * Generic code for HMAC and NMAC * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: hmac.h,v $ + * Revision 1.4 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.3 2000/06/17 11:23:57 mdw * New key size interface. * @@ -84,9 +88,9 @@ /* --- An HMAC or NMAC key --- */ \ \ typedef struct pre##_mackey { \ - octet ochain[PRE##_HASHSZ]; /* Chaining for outer hash */ \ + octet ochain[PRE##_STATESZ]; /* Chaining for outer hash */ \ unsigned ocount; /* Byte count for outer hash */ \ - octet ichain[PRE##_HASHSZ]; /* Chaining for inner hash */ \ + octet ichain[PRE##_STATESZ]; /* Chaining for inner hash */ \ unsigned icount; /* Byte count for inner hash */ \ } pre##_mackey; \ \ @@ -94,7 +98,7 @@ typedef struct pre##_mackey { \ \ typedef struct pre##_macctx { \ pre##_ctx ctx; /* Context for main hashing */ \ - octet chain[PRE##_HASHSZ]; /* Chaining for outer hash */ \ + octet chain[PRE##_STATESZ]; /* Chaining for outer hash */ \ unsigned count; /* Byte count for outer hash */ \ } pre##_macctx; \ \ diff --git a/md4.h b/md4.h index 5c9419f..32202ae 100644 --- a/md4.h +++ b/md4.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md4.h,v 1.3 2000/06/17 11:32:52 mdw Exp $ + * $Id: md4.h,v 1.4 2000/10/15 19:09:20 mdw Exp $ * * The MD4 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: md4.h,v $ + * Revision 1.4 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.3 2000/06/17 11:32:52 mdw * Change buffer offset to be unsigned. * @@ -69,6 +73,7 @@ #define MD4_BUFSZ 64 #define MD4_HASHSZ 16 +#define MD4_STATESZ 16 /*----- Data structures ---------------------------------------------------*/ diff --git a/md5.h b/md5.h index 13b114e..5dc6c3b 100644 --- a/md5.h +++ b/md5.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: md5.h,v 1.3 2000/06/17 11:32:52 mdw Exp $ + * $Id: md5.h,v 1.4 2000/10/15 19:09:20 mdw Exp $ * * The MD5 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: md5.h,v $ + * Revision 1.4 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.3 2000/06/17 11:32:52 mdw * Change buffer offset to be unsigned. * @@ -70,6 +74,7 @@ #define MD5_BUFSZ 64 #define MD5_HASHSZ 16 +#define MD5_STATESZ 16 /*----- Data structures ---------------------------------------------------*/ diff --git a/rmd128.h b/rmd128.h index ac776de..d5dc313 100644 --- a/rmd128.h +++ b/rmd128.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd128.h,v 1.1 2000/07/09 21:30:31 mdw Exp $ + * $Id: rmd128.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * The RIPEMD-128 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd128.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/07/09 21:30:31 mdw * New RIPEMD variants. * @@ -61,6 +65,7 @@ #define RMD128_BUFSZ 64 #define RMD128_HASHSZ 16 +#define RMD128_STATESZ 16 /*----- Data structures ---------------------------------------------------*/ diff --git a/rmd160.h b/rmd160.h index ad64f09..47454e9 100644 --- a/rmd160.h +++ b/rmd160.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd160.h,v 1.3 2000/06/17 11:32:52 mdw Exp $ + * $Id: rmd160.h,v 1.4 2000/10/15 19:09:20 mdw Exp $ * * The RIPEMD-160 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd160.h,v $ + * Revision 1.4 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.3 2000/06/17 11:32:52 mdw * Change buffer offset to be unsigned. * @@ -70,6 +74,7 @@ #define RMD160_BUFSZ 64 #define RMD160_HASHSZ 20 +#define RMD160_STATESZ 20 /*----- Data structures ---------------------------------------------------*/ diff --git a/rmd256.h b/rmd256.h index cc7d4f6..28a9dfd 100644 --- a/rmd256.h +++ b/rmd256.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd256.h,v 1.1 2000/07/09 21:30:31 mdw Exp $ + * $Id: rmd256.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * The RIPEMD-256 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd256.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/07/09 21:30:31 mdw * New RIPEMD variants. * @@ -64,6 +68,7 @@ #define RMD256_BUFSZ 64 #define RMD256_HASHSZ 32 +#define RMD256_STATESZ 32 /*----- Data structures ---------------------------------------------------*/ diff --git a/rmd320.h b/rmd320.h index 017e422..5afa688 100644 --- a/rmd320.h +++ b/rmd320.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rmd320.h,v 1.1 2000/07/09 21:30:31 mdw Exp $ + * $Id: rmd320.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * The RIPEMD-320 message digest function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: rmd320.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/07/09 21:30:31 mdw * New RIPEMD variants. * @@ -64,6 +68,7 @@ #define RMD320_BUFSZ 64 #define RMD320_HASHSZ 40 +#define RMD320_STATESZ 40 /*----- Data structures ---------------------------------------------------*/ diff --git a/sha.h b/sha.h index c22b3c3..97003ef 100644 --- a/sha.h +++ b/sha.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sha.h,v 1.4 2000/06/17 11:32:52 mdw Exp $ + * $Id: sha.h,v 1.5 2000/10/15 19:09:20 mdw Exp $ * * Implementation of the SHA-1 hash function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: sha.h,v $ + * Revision 1.5 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.4 2000/06/17 11:32:52 mdw * Change buffer offset to be unsigned. * @@ -72,6 +76,7 @@ #define SHA_BUFSZ 64 #define SHA_HASHSZ 20 +#define SHA_STATESZ 20 /*----- Data structures ---------------------------------------------------*/ diff --git a/sha256.h b/sha256.h index c35a38e..50d61fa 100644 --- a/sha256.h +++ b/sha256.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sha256.h,v 1.1 2000/10/15 17:48:15 mdw Exp $ + * $Id: sha256.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * Implementation of the SHA-256 hash function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: sha256.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/10/15 17:48:15 mdw * New SHA variants with longer outputs. * @@ -62,6 +66,7 @@ #define SHA256_BUFSZ 64 #define SHA256_HASHSZ 32 +#define SHA256_STATESZ 32 /*----- Data structures ---------------------------------------------------*/ diff --git a/sha512.h b/sha512.h index 8d35595..0a695f9 100644 --- a/sha512.h +++ b/sha512.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sha512.h,v 1.1 2000/10/15 17:48:15 mdw Exp $ + * $Id: sha512.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * Implementation of the SHA-512 hash function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: sha512.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/10/15 17:48:15 mdw * New SHA variants with longer outputs. * @@ -65,9 +69,11 @@ #define SHA512_BUFSZ 128 #define SHA512_HASHSZ 64 +#define SHA512_STATESZ 64 #define SHA384_BUFSZ 128 #define SHA384_HASHSZ 48 +#define SHA384_STATESZ 64 /*----- Data structures ---------------------------------------------------*/ diff --git a/tiger.h b/tiger.h index e1011a0..ece7c86 100644 --- a/tiger.h +++ b/tiger.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tiger.h,v 1.1 2000/07/15 10:02:43 mdw Exp $ + * $Id: tiger.h,v 1.2 2000/10/15 19:09:20 mdw Exp $ * * The Tiger hash function * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: tiger.h,v $ + * Revision 1.2 2000/10/15 19:09:20 mdw + * Support HMAC mode for hash functions which need to store more state than + * the hash output size. + * * Revision 1.1 2000/07/15 10:02:43 mdw * Anderson and Biham's Tiger hash function added. * @@ -64,6 +68,7 @@ #define TIGER_BUFSZ 64 #define TIGER_HASHSZ 24 +#define TIGER_STATESZ 24 /*----- Data structures ---------------------------------------------------*/ -- 2.11.0