chiark / gitweb /
Added. No idea why this wasn't done before.
[become] / src / md5.h
1 /* -*-c-*-
2  *
3  * $Id: md5.h,v 1.2 1997/08/04 10:24:23 mdw Exp $
4  *
5  * MD-5 secure hash routines
6  *  Based on RSA MD-5 code
7  *
8  * (c) 1996, 1997 Mark Wooding
9  */
10
11 /*----- Licensing notice --------------------------------------------------*
12  *
13  * This file is part of `become'
14  *
15  * `Become' is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * `Become' is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with `become'; if not, write to the Free Software Foundation,
27  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28  */
29
30 /*----- Revision history --------------------------------------------------*
31  *
32  * $Log: md5.h,v $
33  * Revision 1.2  1997/08/04 10:24:23  mdw
34  * Sources placed under CVS control.
35  *
36  * Revision 1.1  1997/07/21  13:47:47  mdw
37  * Initial revision
38  *
39  */
40
41 #ifndef MD5_H
42 #define MD5_H
43
44 #ifdef __cplusplus
45   extern "C" {
46 #endif
47
48 /*----- Required headers --------------------------------------------------*/
49
50 #include <stddef.h>
51
52 #ifndef CONFIG_H
53 #  include "config.h"
54 #endif
55
56 /*----- Useful constants --------------------------------------------------*/
57
58 #define MD5_HASHSIZE (16u)              /* Size of an MD5 hash */
59
60 /*----- Type definitions --------------------------------------------------*/
61
62 /* --- MD5 context buffer --- */
63
64 typedef struct {
65   uint_32 val[4];                       /* Result of the hash function */
66   unsigned long size;                   /* Current size of data in bytes */
67   unsigned char buf[64];                /* Buffer accumulating next block */
68 } md5;
69
70 /*----- Functions provided ------------------------------------------------*/
71
72 /* --- @md5_trans@ --- *
73  *
74  * Arguments:   @unsigned char *v@ = pointer to chaining block (updated)
75  *              @const unsigned char *buf@ = pointer to input buffer
76  *
77  * Returns:     ---
78  *
79  * Use:         Performs the MD5 transformation on a chunk of data.  This may
80  *              be useful for using MD5 in MDC-type cipher constructions.
81  */
82
83 extern void md5_trans(unsigned char */*v*/, const unsigned char */*buf*/);
84
85 /* --- @md5_buffer@ --- *
86  *
87  * Arguments:   @md5 *m@ = pointer to an MD5 context
88  *              @const void *buff@ = pointer to buffer of data
89  *              @size_t size@ = size of buffer
90  *
91  * Returns:     ---
92  *
93  * Use:         Hashes the buffer of data.  You can call md5_buffer
94  *              lots of times during an MD5 job, to allow big files to be
95  *              split into little ones.
96  *
97  *              This routine could be improved lots, to compare with the
98  *              Straylight ARM assembler implementation, although that
99  *              requires lots of work.  Remember that the ARM version
100  *              doesn't need to do endianness-fiddling.
101  */
102
103 extern void md5_buffer(md5 */*m*/, const void */*buff*/, size_t /*size*/);
104
105 /* --- @md5_key@ --- *
106  *
107  * Arguments:   @md5 *m@ = pointer to an MD5 context
108  *              @const unsigned char *k@ = pointer to a 4-word `key'
109  *
110  * Returns:     ---
111  *
112  * Use:         Initialises a context buffer, with a chosen initialisation
113  *              string (instead of the standard MD5 value).  This allows you
114  *              to use NMAC message authentication, should the urge take you.
115  */
116
117 extern void md5_key(md5 */*m*/, const unsigned char */*k*/);
118
119 /* --- @md5_init@ --- *
120  *
121  * Arguments:   @md5 *m@ = pointer to an MD5 context
122  *
123  * Returns:     ---
124  *
125  * Use:         Initialises the context buffer, so that you can do an
126  *              MD5 job.
127  */
128
129 extern void md5_init(md5 */*m*/);
130
131 /* --- @md5_final@ --- *
132  *
133  * Arguments:   @md5 *m@ = pointer to context buffer
134  *              @unsigned char *v@ = where to store the value
135  *
136  * Returns:     ---
137  *
138  * Use:         Finalises an MD5 buffer, so that you can use the result.
139  */
140
141 extern void md5_final(md5 */*m*/, unsigned char */*v*/);
142
143 /*----- That's all, folks -------------------------------------------------*/
144
145 #ifdef __cplusplus
146   }
147 #endif
148
149 #endif