3 * The MD4 message digest function
5 * (c) 1998 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Notes on the MD4 hash function ------------------------------------*
30 * MD4 was designed by Ron Rivest. It's now well and truly broken: not only
31 * have collisions been discovered, a slightly cut-down version has been
32 * shown to be non-preimage-resistant. On the other hand, MD4 is fast and
33 * makes a good heavy-duty checksum. Just don't rely on it being
34 * cryptographically strong, 'cos it ain't.
37 #ifndef CATACOMB_MD4_H
38 #define CATACOMB_MD4_H
44 /*----- Header files ------------------------------------------------------*/
46 #include <mLib/bits.h>
48 #ifndef CATACOMB_GHASH_H
52 /*----- Magic numbers -----------------------------------------------------*/
56 #define MD4_STATESZ 16
58 /*----- Data structures ---------------------------------------------------*/
60 typedef struct md4_ctx {
61 uint32 a, b, c, d; /* Chaining variables */
62 uint32 nl, nh; /* Byte count so far */
63 unsigned off; /* Offset into buffer */
64 octet buf[MD4_BUFSZ]; /* Accumulation buffer */
67 /*----- Functions provided ------------------------------------------------*/
69 /* --- @md4_compress@ --- *
71 * Arguments: @md4_ctx *ctx@ = pointer to context block
72 * @const void *sbuf@ = pointer to buffer of appropriate size
76 * Use: MD4 compression function.
79 extern void md4_compress(md4_ctx */*ctx*/, const void */*sbuf*/);
81 /* --- @md4_init@ --- *
83 * Arguments: @md4_ctx *ctx@ = pointer to context block to initialize
87 * Use: Initializes a context block ready for hashing.
90 extern void md4_init(md4_ctx */*ctx*/);
92 /* --- @md4_set@ --- *
94 * Arguments: @md4_ctx *ctx@ = pointer to context block
95 * @const void *buf@ = pointer to state buffer
96 * @unsigned long count@ = current count of bytes processed
100 * Use: Initializes a context block from a given state. This is
101 * useful in cases where the initial hash state is meant to be
102 * secret, e.g., for NMAC and HMAC support.
105 extern void md4_set(md4_ctx */*ctx*/, const void */*buf*/,
106 unsigned long /*count*/);
108 /* --- @md4_hash@ --- *
110 * Arguments: @md4_ctx *ctx@ = pointer to context block
111 * @const void *buf@ = buffer of data to hash
112 * @size_t sz@ = size of buffer to hash
116 * Use: Hashes a buffer of data. The buffer may be of any size and
120 extern void md4_hash(md4_ctx */*ctx*/, const void */*buf*/, size_t /*sz*/);
122 /* --- @md4_done@ --- *
124 * Arguments: @md4_ctx *ctx@ = pointer to context block
125 * @void *hash@ = pointer to output buffer
129 * Use: Returns the hash of the data read so far.
132 extern void md4_done(md4_ctx */*ctx*/, void */*hash*/);
134 /* --- @md4_state@ --- *
136 * Arguments: @md4_ctx *ctx@ = pointer to context
137 * @void *state@ = pointer to buffer for current state
139 * Returns: Number of bytes written to the hash function so far.
141 * Use: Returns the current state of the hash function such that
142 * it can be passed to @md4_set@.
145 extern unsigned long md4_state(md4_ctx */*ctx*/, void */*state*/);
147 /*----- Generic hash interface --------------------------------------------*/
149 extern const gchash md4;
151 /*----- That's all, folks -------------------------------------------------*/