chiark / gitweb /
Initial revision
[become] / src / md5.h
1 /* -*-c-*-
2  *
3  * $Id: md5.h,v 1.1 1997/07/21 13:47:47 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 /*----- Licencing 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
27  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  */
29
30 /*----- Revision history --------------------------------------------------*
31  *
32  * $Log: md5.h,v $
33  * Revision 1.1  1997/07/21 13:47:47  mdw
34  * Initial revision
35  *
36  */
37
38 #ifndef MD5_H
39 #define MD5_H
40
41 #ifdef __cplusplus
42   extern "C" {
43 #endif
44
45 /*----- Required headers --------------------------------------------------*/
46
47 #include <stddef.h>
48
49 #ifndef CONFIG_H
50 #  include "config.h"
51 #endif
52
53 /*----- Useful constants --------------------------------------------------*/
54
55 #define MD5_HASHSIZE (16u)              /* Size of an MD5 hash */
56
57 /*----- Type definitions --------------------------------------------------*/
58
59 /* --- MD5 context buffer --- */
60
61 typedef struct {
62   uint_32 val[4];                       /* Result of the hash function */
63   unsigned long size;                   /* Current size of data in bytes */
64   unsigned char buf[64];                /* Buffer accumulating next block */
65 } md5;
66
67 /*----- Functions provided ------------------------------------------------*/
68
69 /* --- @md5_trans@ --- *
70  *
71  * Arguments:   @unsigned char *v@ = pointer to chaining block (updated)
72  *              @const unsigned char *buf@ = pointer to input buffer
73  *
74  * Returns:     ---
75  *
76  * Use:         Performs the MD5 transformation on a chunk of data.  This may
77  *              be useful for using MD5 in MDC-type cipher constructions.
78  */
79
80 extern void md5_trans(unsigned char */*v*/, const unsigned char */*buf*/);
81
82 /* --- @md5_buffer@ --- *
83  *
84  * Arguments:   @md5 *m@ = pointer to an MD5 context
85  *              @const void *buff@ = pointer to buffer of data
86  *              @size_t size@ = size of buffer
87  *
88  * Returns:     ---
89  *
90  * Use:         Hashes the buffer of data.  You can call md5_buffer
91  *              lots of times during an MD5 job, to allow big files to be
92  *              split into little ones.
93  *
94  *              This routine could be improved lots, to compare with the
95  *              Straylight ARM assembler implementation, although that
96  *              requires lots of work.  Remember that the ARM version
97  *              doesn't need to do endianness-fiddling.
98  */
99
100 extern void md5_buffer(md5 */*m*/, const void */*buff*/, size_t /*size*/);
101
102 /* --- @md5_key@ --- *
103  *
104  * Arguments:   @md5 *m@ = pointer to an MD5 context
105  *              @const unsigned char *k@ = pointer to a 4-word `key'
106  *
107  * Returns:     ---
108  *
109  * Use:         Initialises a context buffer, with a chosen initialisation
110  *              string (instead of the standard MD5 value).  This allows you
111  *              to use NMAC message authentication, should the urge take you.
112  */
113
114 extern void md5_key(md5 */*m*/, const unsigned char */*k*/);
115
116 /* --- @md5_init@ --- *
117  *
118  * Arguments:   @md5 *m@ = pointer to an MD5 context
119  *
120  * Returns:     ---
121  *
122  * Use:         Initialises the context buffer, so that you can do an
123  *              MD5 job.
124  */
125
126 extern void md5_init(md5 */*m*/);
127
128 /* --- @md5_final@ --- *
129  *
130  * Arguments:   @md5 *m@ = pointer to context buffer
131  *              @unsigned char *v@ = where to store the value
132  *
133  * Returns:     ---
134  *
135  * Use:         Finalises an MD5 buffer, so that you can use the result.
136  */
137
138 extern void md5_final(md5 */*m*/, unsigned char */*v*/);
139
140 /*----- That's all, folks -------------------------------------------------*/
141
142 #ifdef __cplusplus
143   }
144 #endif
145
146 #endif