New hash variant SHA224.
[u/mdw/catacomb] / sha256.h
index 50d61fa..ca6e18c 100644 (file)
--- a/sha256.h
+++ b/sha256.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sha256.h,v 1.2 2000/10/15 19:09:20 mdw Exp $
+ * $Id: sha256.h,v 1.3 2004/03/21 22:43:34 mdw Exp $
  *
  * Implementation of the SHA-256 hash function
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: sha256.h,v $
+ * Revision 1.3  2004/03/21 22:43:34  mdw
+ * New hash variant SHA224.
+ *
  * 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.
 #define SHA256_HASHSZ 32
 #define SHA256_STATESZ 32
 
+#define SHA224_BUFSZ 64
+#define SHA224_HASHSZ 28
+#define SHA224_STATESZ 32
+
 /*----- Data structures ---------------------------------------------------*/
 
 typedef struct sha256_ctx {
@@ -75,11 +82,11 @@ typedef struct sha256_ctx {
   uint32 nl, nh;                       /* Byte count so far */
   unsigned off;                                /* Offset into buffer */
   octet buf[SHA256_BUFSZ];             /* Accumulation buffer */
-} sha256_ctx;
+} sha256_ctx, sha224_ctx;
 
 /*----- Functions provided ------------------------------------------------*/
 
-/* --- @sha256_compress@ --- *
+/* --- @sha256_compress@, @sha224_compress@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context block
  *             @const void *sbuf@ = pointer to buffer of appropriate size
@@ -90,8 +97,9 @@ typedef struct sha256_ctx {
  */
 
 extern void sha256_compress(sha256_ctx */*ctx*/, const void */*sbuf*/);
+#define sha224_compress sha256_compress
 
-/* --- @sha256_init@ --- *
+/* --- @sha256_init@, @sha224_init@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context block to initialize
  *
@@ -101,8 +109,9 @@ extern void sha256_compress(sha256_ctx */*ctx*/, const void */*sbuf*/);
  */
 
 extern void sha256_init(sha256_ctx */*ctx*/);
+extern void sha224_init(sha256_ctx */*ctx*/);
 
-/* --- @sha256_set@ --- *
+/* --- @sha256_set@, @sha224_set@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context block
  *             @const void *buf@ = pointer to state buffer
@@ -117,8 +126,9 @@ extern void sha256_init(sha256_ctx */*ctx*/);
 
 extern void sha256_set(sha256_ctx */*ctx*/, const void */*buf*/,
                       unsigned long /*count*/);
+#define sha224_set sha256_set
 
-/* --- @sha256_hash@ --- *
+/* --- @sha256_hash@, @sha224_hash@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context block
  *             @const void *buf@ = buffer of data to hash
@@ -132,8 +142,9 @@ extern void sha256_set(sha256_ctx */*ctx*/, const void */*buf*/,
 
 extern void sha256_hash(sha256_ctx */*ctx*/,
                        const void */*buf*/, size_t /*sz*/);
+#define sha224_hash sha256_hash
 
-/* --- @sha256_done@ --- *
+/* --- @sha256_done@, @sha224_done@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context block
  *             @void *hash@ = pointer to output buffer
@@ -144,8 +155,9 @@ extern void sha256_hash(sha256_ctx */*ctx*/,
  */
 
 extern void sha256_done(sha256_ctx */*ctx*/, void */*hash*/);
+extern void sha224_done(sha256_ctx */*ctx*/, void */*hash*/);
 
-/* --- @sha256_state@ --- *
+/* --- @sha256_state@, @sha224_state@ --- *
  *
  * Arguments:  @sha256_ctx *ctx@ = pointer to context
  *             @void *state@ = pointer to buffer for current state
@@ -157,10 +169,12 @@ extern void sha256_done(sha256_ctx */*ctx*/, void */*hash*/);
  */
 
 extern unsigned long sha256_state(sha256_ctx */*ctx*/, void */*state*/);
+#define sha224_state sha256_state
 
 /*----- Generic hash interface --------------------------------------------*/
 
 extern const gchash sha256;
+extern const gchash sha224;
 
 /*----- That's all, folks -------------------------------------------------*/