home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / hash / md5.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-25  |  5.1 KB  |  176 lines  |  [TEXT/R*ch]

  1. /* @(#)md5.h    10.1 3/25/94 08:04:11 */
  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.  
  17. /*
  18.  ***********************************************************************
  19.  ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
  20.  **                                      **
  21.  ** License to copy and use this software is granted provided that    **
  22.  ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
  23.  ** Digest Algorithm" in all material mentioning or referencing this  **
  24.  ** software or this function.                          **
  25.  **                                      **
  26.  ** License is also granted to make and use derivative works          **
  27.  ** provided that such works are identified as "derived from the RSA  **
  28.  ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
  29.  ** material mentioning or referencing the derived work.          **
  30.  **                                      **
  31.  ** RSA Data Security, Inc. makes no representations concerning       **
  32.  ** either the merchantability of this software or the suitability    **
  33.  ** of this software for any particular purpose.  It is provided "as  **
  34.  ** is" without express or implied warranty of any kind.              **
  35.  **                                      **
  36.  ** These notices must be retained in any copies of any part of this  **
  37.  ** documentation and/or software.                      **
  38.  ***********************************************************************
  39.  */
  40.  
  41. #if !defined(MD5_H)
  42. #define MD5_H
  43.  
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46.  
  47. /*
  48.  * determine if we are checked in
  49.  */
  50. #define MD5_H_WHAT "@(#)"        /* will be @(#) or @(#) */
  51.  
  52. /*
  53.  * Useful defines/typedefs
  54.  */
  55. typedef unsigned char BYTE;
  56. typedef unsigned long ULONG;
  57. typedef unsigned int UINT;
  58.  
  59. /* MD5_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */
  60. #define MD5_CHUNKSIZE    (1<<6)
  61. #define MD5_CHUNKWORDS (MD5_CHUNKSIZE/sizeof(ULONG))
  62.  
  63. /* MD5_DIGESTSIZE is a the length of the digest as defined by the algorithm */
  64. #define MD5_DIGESTSIZE    (16)
  65. #define MD5_DIGESTWORDS (MD5_DIGESTSIZE/sizeof(ULONG))
  66.  
  67. /* MD5_LOW - where low 32 bits of 64 bit count is stored during final */
  68. #define MD5_LOW 14
  69.  
  70. /* MD5_HIGH - where high 32 bits of 64 bit count is stored during final */
  71. #define MD5_HIGH 15
  72.  
  73. /*
  74.  * MAXBLOCK - maximum blocking factor
  75.  *
  76.  * must be power of 2 > MD5_CHUNKSIZE and < READSIZE and < 2^29
  77.  */
  78. #define MAXBLOCK (MD5_CHUNKSIZE<<7)
  79.  
  80. /* READSIZE must be a multiple of MD5_CHUNKSIZE >= MAXBLOCK */
  81. #define READSIZE (MD5_CHUNKSIZE<<9)
  82. #define READWORDS (READSIZE/sizeof(ULONG))
  83.  
  84. /* maximum size of pre_file that is used <= MAXBLOCK */
  85. #define MAX_PRE_FILE MAXBLOCK
  86.  
  87. /*
  88.  * COUNT(MD5_CTX*, ULONG) - update the 64 bit count in an MD5_CTX
  89.  *
  90.  * We will count bytes and convert to bit count during the final
  91.  * transform.
  92.  */
  93. #define COUNT(md5info, count) {                    \
  94.     long tmp_countLo;                        \
  95.     tmp_countLo = (md5info)->countLo;                \
  96.     if (((md5info)->countLo += (count)) < tmp_countLo) {    \
  97.     (md5info)->countHi++;                    \
  98.     }                                \
  99. }
  100.  
  101. /*
  102.  * ROUNDUP(x,y) - round x up to the next multiple of y
  103.  */
  104. #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
  105.  
  106. /*
  107.  * Data structure for MD5 (Message-Digest) computation
  108.  */
  109. typedef struct {
  110.     BYTE digest[MD5_DIGESTSIZE];    /* actual digest after MD5Final call */
  111.     ULONG countLo;        /* 64 bit count: bits 3-34 */
  112.     ULONG countHi;        /* 64 bit count: bits 35-63 (64-66 ignored) */
  113.     ULONG datalen;        /* length of data in inp.inp_BYTE */
  114.     ULONG sub_block;        /* length of current partial block or 0 */
  115.     union {
  116.     BYTE inp_BYTE[MD5_CHUNKSIZE];               /* BYTE chunk buffer */
  117.     ULONG inp_ULONG[MD5_CHUNKWORDS];  /* ULONG chunk buffer */
  118.     } inp;
  119.     ULONG buf[MD5_DIGESTWORDS];           /* scratch buffer */
  120. } MD5_CTX;
  121. #define in_byte inp.inp_BYTE
  122. #define in_ulong inp.inp_ULONG
  123.  
  124. /*
  125.  * elements of the stat structure that we will process
  126.  */
  127. struct hashstat {
  128.     dev_t st_dev;
  129.     ino_t st_ino;
  130.     mode_t st_mode;
  131.     nlink_t st_nlink;
  132.     uid_t st_uid;
  133.     gid_t st_gid;
  134.     off_t st_size;
  135.     time_t st_mtime;
  136.     time_t st_ctime;
  137. };
  138.  
  139. /*
  140.  * Turn off prototypes if requested
  141.  */
  142. #if (defined(NOPROTO) && defined(PROTO))
  143. # undef PROTO
  144. #endif
  145.  
  146. /*
  147.  * Used to remove arguments in function prototypes for non-ANSI C
  148.  */
  149. #ifdef PROTO
  150. # define P(a) a
  151. #else    /* !PROTO */
  152. # define P(a) ()
  153. #endif    /* ?PROTO */
  154.  
  155. /* md5.c */
  156. void MD5Init P((MD5_CTX*));
  157. void MD5Update P((MD5_CTX*, BYTE*, UINT));
  158. void MD5fullUpdate P((MD5_CTX*, BYTE*, UINT));
  159. void MD5Final P((MD5_CTX*));
  160. char *MD5_what;
  161.  
  162. /* md5dual.c */
  163. void dualMain P((int, char**, BYTE*, UINT, char*));
  164. void dualTest P((void));
  165. char *MD5dual_what;
  166.  
  167. /* md5drvr.c */
  168. void MD5Print P((MD5_CTX*));
  169. ULONG zero[];
  170. char *program;
  171. int i_flag;
  172. int q_flag;
  173. int dot_zero;
  174.  
  175. #endif /* MD5_H */
  176.