d3187d77 |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: md2.h,v 1.2 2004/04/08 01:36:15 mdw Exp $ |
d3187d77 |
4 | * |
5 | * The MD2 message digest function |
6 | * |
7 | * (c) 2001 Straylight/Edgeware |
8 | */ |
9 | |
45c0fd36 |
10 | /*----- Licensing notice --------------------------------------------------* |
d3187d77 |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
45c0fd36 |
18 | * |
d3187d77 |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
45c0fd36 |
23 | * |
d3187d77 |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
d3187d77 |
30 | /*----- Notes on the MD2 hash function ------------------------------------* |
31 | * |
32 | * MD2 was designed by Ron Rivest. It's not recommended for new applications |
33 | * because only the `checksum' part of the function resists collision-finding |
34 | * attacks. It's not very fast either. However, it's still used in |
35 | * standards, and having it available can be useful. |
36 | */ |
37 | |
38 | #ifndef CATACOMB_MD2_H |
39 | #define CATACOMB_MD2_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #include <mLib/bits.h> |
48 | |
49 | #ifndef CATACOMB_GHASH_H |
50 | # include "ghash.h" |
51 | #endif |
52 | |
53 | /*----- Magic numbers -----------------------------------------------------*/ |
54 | |
55 | #define MD2_BUFSZ 16 |
56 | #define MD2_HASHSZ 16 |
57 | #define MD2_STATESZ 32 |
58 | |
59 | /*----- Data structures ---------------------------------------------------*/ |
60 | |
61 | typedef struct md2_ctx { |
62 | octet c[MD2_BUFSZ]; /* Checksum buffer */ |
63 | octet h[MD2_BUFSZ]; /* Hash result buffer */ |
64 | octet buf[MD2_BUFSZ]; /* Input buffer */ |
65 | unsigned off; /* Offset into buffer */ |
66 | } md2_ctx; |
67 | |
68 | /*----- Functions provided ------------------------------------------------*/ |
69 | |
70 | /* --- @md2_compress@ --- * |
71 | * |
72 | * Arguments: @md2_ctx *ctx@ = pointer to context block |
73 | * @const void *sbuf@ = pointer to buffer of appropriate size |
74 | * |
75 | * Returns: --- |
76 | * |
77 | * Use: MD2 compression function. |
78 | */ |
79 | |
80 | extern void md2_compress(md2_ctx */*ctx*/, const void */*sbuf*/); |
81 | |
82 | /* --- @md2_init@ --- * |
83 | * |
84 | * Arguments: @md2_ctx *ctx@ = pointer to context block to initialize |
85 | * |
86 | * Returns: --- |
87 | * |
88 | * Use: Initializes a context block ready for hashing. |
89 | */ |
90 | |
91 | extern void md2_init(md2_ctx */*ctx*/); |
92 | |
93 | /* --- @md2_set@ --- * |
94 | * |
95 | * Arguments: @md2_ctx *ctx@ = pointer to context block |
96 | * @const void *buf@ = pointer to state buffer |
97 | * @unsigned long count@ = current count of bytes processed |
98 | * |
99 | * Returns: --- |
100 | * |
101 | * Use: Initializes a context block from a given state. This is |
102 | * useful in cases where the initial hash state is meant to be |
103 | * secret, e.g., for NMAC and HMAC support. |
104 | */ |
105 | |
106 | extern void md2_set(md2_ctx */*ctx*/, const void */*buf*/, |
107 | unsigned long /*count*/); |
108 | |
109 | /* --- @md2_hash@ --- * |
110 | * |
111 | * Arguments: @md2_ctx *ctx@ = pointer to context block |
112 | * @const void *buf@ = buffer of data to hash |
113 | * @size_t sz@ = size of buffer to hash |
114 | * |
115 | * Returns: --- |
116 | * |
117 | * Use: Hashes a buffer of data. The buffer may be of any size and |
118 | * alignment. |
119 | */ |
120 | |
121 | extern void md2_hash(md2_ctx */*ctx*/, const void */*buf*/, size_t /*sz*/); |
122 | |
123 | /* --- @md2_done@ --- * |
124 | * |
125 | * Arguments: @md2_ctx *ctx@ = pointer to context block |
126 | * @void *hash@ = pointer to output buffer |
127 | * |
128 | * Returns: --- |
129 | * |
130 | * Use: Returns the hash of the data read so far. |
131 | */ |
132 | |
133 | extern void md2_done(md2_ctx */*ctx*/, void */*hash*/); |
134 | |
135 | /* --- @md2_state@ --- * |
136 | * |
137 | * Arguments: @md2_ctx *ctx@ = pointer to context |
138 | * @void *state@ = pointer to buffer for current state |
139 | * |
140 | * Returns: Number of bytes written to the hash function so far. |
141 | * |
142 | * Use: Returns the current state of the hash function such that |
143 | * it can be passed to @md2_set@. |
144 | */ |
145 | |
146 | extern unsigned long md2_state(md2_ctx */*ctx*/, void */*state*/); |
147 | |
148 | /*----- Generic hash interface --------------------------------------------*/ |
149 | |
150 | extern const gchash md2; |
151 | |
152 | /*----- That's all, folks -------------------------------------------------*/ |
153 | |
154 | #ifdef __cplusplus |
155 | } |
156 | #endif |
157 | |
158 | #endif |