1 /* $Id: md5.h,v 1.2 1998/07/12 09:39:20 src Exp $ 2 * 3 * md5 - RSA Data Security, Inc. MD5 Message-Digest Algorithm 4 * 5 * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO 6 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- 7 * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT 8 * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 9 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 10 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 11 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 12 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 13 * 14 * See md5drvr.c for version and modification history. 15 * 16 * $Log: md5.h,v $ 17 * Revision 1.2 1998/07/12 09:39:20 src 18 * NewsX version 1.0 19 * 20 */ 21 22 /* 23 *********************************************************************** 24 ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** 25 ** ** 26 ** License to copy and use this software is granted provided that ** 27 ** it is identified as the "RSA Data Security, Inc. MD5 Message- ** 28 ** Digest Algorithm" in all material mentioning or referencing this ** 29 ** software or this function. ** 30 ** ** 31 ** License is also granted to make and use derivative works ** 32 ** provided that such works are identified as "derived from the RSA ** 33 ** Data Security, Inc. MD5 Message-Digest Algorithm" in all ** 34 ** material mentioning or referencing the derived work. ** 35 ** ** 36 ** RSA Data Security, Inc. makes no representations concerning ** 37 ** either the merchantability of this software or the suitability ** 38 ** of this software for any particular purpose. It is provided "as ** 39 ** is" without express or implied warranty of any kind. ** 40 ** ** 41 ** These notices must be retained in any copies of any part of this ** 42 ** documentation and/or software. ** 43 *********************************************************************** 44 */ 45 46 #if !defined(MD5_H) 47 #define MD5_H 48 49 #include <sys/types.h> 50 #include <sys/stat.h> 51 52 /* 53 * determine if we are checked in 54 */ 55 #define MD5_H_WHAT "@(#)" /* will be @(#) or @(#) */ 56 57 /* 58 * These macros are in common with shs.h, shs1.h and md5.h. We use 59 * HASH_MACROS to gaurd against multiple inclusion by external progs 60 * that may want to use multiple hash codes in one module. 61 */ 62 #if !defined(HASH_MACROS) 63 #define HASH_MACROS 64 65 /* 66 * Useful defines/typedefs 67 */ 68 typedef unsigned char BYTE; 69 typedef unsigned int UINT; 70 71 #endif /* HASH_MACROS */ 72 73 /* MD5_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */ 74 #define MD5_CHUNKSIZE (1<<6) 75 #define MD5_CHUNKWORDS (MD5_CHUNKSIZE/sizeof(U_INT32_T)) 76 77 /* MD5_DIGESTSIZE is a the length of the digest as defined by the algorithm */ 78 #define MD5_DIGESTSIZE (16) 79 #define MD5_DIGESTWORDS (MD5_DIGESTSIZE/sizeof(U_INT32_T)) 80 81 /* MD5_LOW - where low 32 bits of 64 bit count is stored during final */ 82 #define MD5_LOW 14 83 84 /* MD5_HIGH - where high 32 bits of 64 bit count is stored during final */ 85 #define MD5_HIGH 15 86 87 /* 88 * MD5_MAXBLOCK - maximum blocking factor 89 * 90 * must be power of 2 > MD5_CHUNKSIZE and < MD5_READSIZE and < 2^29 91 */ 92 #define MD5_MAXBLOCK (MD5_CHUNKSIZE<<7) 93 94 /* MD5_READSIZE must be a multiple of MD5_CHUNKSIZE >= MD5_MAXBLOCK */ 95 #define MD5_READSIZE (MD5_CHUNKSIZE<<9) 96 #define MD5_READWORDS (MD5_READSIZE/sizeof(U_INT32_T)) 97 98 /* maximum size of pre_file that is used <= MD5_MAXBLOCK */ 99 #define MD5_MAX_PRE_FILE MD5_MAXBLOCK 100 101 /* 102 * MD5COUNT(MD5_CTX*, U_INT32_T) - update the 64 bit count in an MD5_CTX 103 * 104 * We will count bytes and convert to bit count during the final 105 * transform. 106 */ 107 #define MD5COUNT(md5info, count) { \ 108 U_INT32_T tmp_countLo; \ 109 tmp_countLo = (md5info)->countLo; \ 110 if (((md5info)->countLo += (count)) < tmp_countLo) { \ 111 (md5info)->countHi++; \ 112 } \ 113 } 114 115 /* 116 * MD5_ROUNDUP(x,y) - round x up to the next multiple of y 117 */ 118 #define MD5_ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y)) 119 120 /* 121 * Data structure for MD5 (Message-Digest) computation 122 */ 123 typedef struct { 124 BYTE digest[MD5_DIGESTSIZE]; /* actual digest after MD5Final call */ 125 U_INT32_T countLo; /* 64 bit count: bits 3-34 */ 126 U_INT32_T countHi; /* 64 bit count: bits 35-63 (64-66 ignored) */ 127 U_INT32_T datalen; /* length of data in inp.inp_BYTE */ 128 U_INT32_T sub_block; /* length of current partial block or 0 */ 129 union { 130 BYTE inp_BYTE[MD5_CHUNKSIZE]; /* BYTE chunk buffer */ 131 U_INT32_T inp_ULONG[MD5_CHUNKWORDS]; /* U_INT32_T chunk buffer */ 132 } inp; 133 U_INT32_T buf[MD5_DIGESTWORDS]; /* scratch buffer */ 134 } MD5_CTX; 135 #define in_byte inp.inp_BYTE 136 #define in_ulong inp.inp_ULONG 137 138 /* 139 * elements of the stat structure that we will process 140 */ 141 struct md5_stat { 142 dev_t stat_dev; 143 ino_t stat_ino; 144 mode_t stat_mode; 145 nlink_t stat_nlink; 146 uid_t stat_uid; 147 gid_t stat_gid; 148 off_t stat_size; 149 time_t stat_mtime; 150 time_t stat_ctime; 151 }; 152 153 /* 154 * Turn off prototypes if requested 155 */ 156 #if (defined(NOPROTO) && defined(PROTO)) 157 # undef PROTO 158 #endif 159 160 /* 161 * Used to remove arguments in function prototypes for non-ANSI C 162 */ 163 #ifdef PROTO 164 # define P(a) a 165 #else /* !PROTO */ 166 # define P(a) () 167 #endif /* ?PROTO */ 168 169 /* md5.c */ 170 void MD5Init P((MD5_CTX*)); 171 void MD5Update P((MD5_CTX*, BYTE*, UINT)); 172 void MD5fullUpdate P((MD5_CTX*, BYTE*, UINT)); 173 void MD5Final P((MD5_CTX*)); 174 extern char *MD5_what; 175 176 /* md5io.c */ 177 void MD5Stream P((BYTE*, UINT, FILE*, MD5_CTX*)); 178 void MD5File P((BYTE*, UINT, char*, int, MD5_CTX*)); 179 extern U_INT32_T md5_zero[]; 180 181 /* 182 * Some external programs use the functions found in md5.c and md5io.c. 183 * These routines define MD5_IO so that such external programs will not 184 * pick up the following declarations. 185 */ 186 187 #if !defined(MD5_IO) 188 189 /* md5dual.c */ 190 void dualMain P((int, char**, BYTE*, UINT, char*)); 191 void dualTest P((void)); 192 extern char *MD5dual_what; 193 194 /* md5drvr.c */ 195 void MD5Print P((MD5_CTX*)); 196 extern char *program; 197 extern int i_flag; 198 extern int q_flag; 199 extern int dot_zero; 200 #endif /* MD5_IO */ 201 extern int debug; 202 extern char *program; 203 204 #endif /* MD5_H */ 205