2 * md5 - RSA Data Security, Inc. MD5 Message-Digest Algorithm
4 * @(#) $Revision: 13.5 $
5 * @(#) $Id: md5.h,v 13.5 2010/10/12 21:10:17 chongo Exp $
6 * @(#) $Source: /usr/local/src/cmd/hash/RCS/md5.h,v $
8 * This file was written by RSA Data Security.
10 * This file was modified by Landon Curt Noll.
12 * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
13 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
14 * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
15 * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
17 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
18 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * chongo (was here) /\oo/\
22 * http://www.isthe.com/chongo/index.html
24 * Share and enjoy! :-)
26 * See md5drvr.c for version and modification history.
30 ***********************************************************************
31 ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
33 ** License to copy and use this software is granted provided that **
34 ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
35 ** Digest Algorithm" in all material mentioning or referencing this **
36 ** software or this function. **
38 ** License is also granted to make and use derivative works **
39 ** provided that such works are identified as "derived from the RSA **
40 ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
41 ** material mentioning or referencing the derived work. **
43 ** RSA Data Security, Inc. makes no representations concerning **
44 ** either the merchantability of this software or the suitability **
45 ** of this software for any particular purpose. It is provided "as **
46 ** is" without express or implied warranty of any kind. **
48 ** These notices must be retained in any copies of any part of this **
49 ** documentation and/or software. **
50 ***********************************************************************
57 #include <sys/types.h>
63 #define MD5_VERSION "$Revision: 13.5 $"
66 * These macros are in common with shs.h, shs1.h and md5.h. We use
67 * HASH_MACROS to gaurd against multiple inclusion by external progs
68 * that may want to use multiple hash codes in one module.
70 #if !defined(HASH_MACROS)
74 * Useful defines/typedefs
76 typedef u_int8_t BYTE
; /* must be 1 byte unsigned value */
77 typedef u_int16_t UINT
; /* must be 2 byte unsigned value */
78 typedef u_int32_t ULONG
; /* must be 4 byte unsigned value */
79 typedef u_int64_t ULLONG
; /* must be 8 byte unsigned value */
81 #endif /* HASH_MACROS */
83 /* MD5_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */
84 #define MD5_CHUNKSIZE (1<<6)
85 #define MD5_CHUNKWORDS (MD5_CHUNKSIZE/sizeof(ULONG))
87 /* MD5_DIGESTSIZE is a the length of the digest as defined by the algorithm */
88 #define MD5_DIGESTSIZE (16)
89 #define MD5_DIGESTWORDS (MD5_DIGESTSIZE/sizeof(ULONG))
91 /* MD5_LOW - where low 32 bits of 64 bit count is stored during final */
94 /* MD5_HIGH - where high 32 bits of 64 bit count is stored during final */
98 * MD5_MAXBLOCK - maximum blocking factor
100 * must be power of 2 > MD5_CHUNKSIZE and < MD5_READSIZE and < 2^29
102 #define MD5_MAXBLOCK (MD5_CHUNKSIZE<<7)
104 /* MD5_READSIZE must be a multiple of MD5_CHUNKSIZE >= MD5_MAXBLOCK */
105 #define MD5_READSIZE (MD5_CHUNKSIZE<<9)
106 #define MD5_READWORDS (MD5_READSIZE/sizeof(ULONG))
108 /* maximum size of pre_file that is used <= MD5_MAXBLOCK */
109 #define MD5_MAX_PRE_FILE MD5_MAXBLOCK
112 * MD5COUNT(MD5_CTX*, ULONG) - update the 64 bit count in an MD5_CTX
114 * We will count bytes and convert to bit count during the final
117 #define MD5COUNT(md5info, count) { \
118 unsigned long tmp_countLo; \
119 tmp_countLo = (md5info)->countLo; \
120 if (((md5info)->countLo += (count)) < tmp_countLo) { \
121 (md5info)->countHi++; \
126 * MD5_ROUNDUP(x,y) - round x up to the next multiple of y
128 #define MD5_ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
131 * Data structure for MD5 (Message-Digest) computation
134 BYTE digest
[MD5_DIGESTSIZE
]; /* actual digest after MD5Final call */
135 ULONG countLo
; /* 64 bit count: bits 3-34 */
136 ULONG countHi
; /* 64 bit count: bits 35-63 (64-66 ignored) */
137 ULONG datalen
; /* length of data in inp.inp_BYTE */
138 ULONG sub_block
; /* length of current partial block or 0 */
140 BYTE inp_BYTE
[MD5_CHUNKSIZE
]; /* BYTE chunk buffer */
141 ULONG inp_ULONG
[MD5_CHUNKWORDS
]; /* ULONG chunk buffer */
143 ULONG buf
[MD5_DIGESTWORDS
]; /* scratch buffer */
145 #define in_byte inp.inp_BYTE
146 #define in_ulong inp.inp_ULONG
149 * elements of the stat structure that we will process
164 * Turn off prototypes if requested
166 #if (defined(NOPROTO) && defined(PROTO))
171 void MD5Init(MD5_CTX
*);
172 void MD5Update(MD5_CTX
*, BYTE
*, UINT
);
173 void MD5fullUpdate(MD5_CTX
*, BYTE
*, UINT
);
174 void MD5Final(MD5_CTX
*);
175 void MD5Transform(ULONG
*buf
, ULONG
*in
);
176 extern char *MD5_what
;
179 void MD5Stream(BYTE
*, UINT
, FILE*, MD5_CTX
*);
180 void MD5File(BYTE
*, UINT
, char*, int, MD5_CTX
*);
181 extern ULONG md5_zero
[];
184 * Some external programs use the functions found in md5.c and md5io.c.
185 * These routines define MD5_IO so that such external programs will not
186 * pick up the following declarations.
192 void dualMain(int, char**, BYTE
*, UINT
, char*);
194 extern char *MD5dual_what
;
197 void MD5Print(MD5_CTX
*);
198 extern char *program
;
204 extern char *program
;