00001 /* md5.h - Declaration of functions and data types used for MD5 sum 00002 computing library functions. 00003 Copyright (C) 1995, 1996 Free Software Foundation, Inc. 00004 NOTE: The canonical source of this file is maintained with the GNU C 00005 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. 00006 00007 This program is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 2, or (at your option) any 00010 later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software Foundation, 00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 00020 00021 #ifndef _MD5_H 00022 #define _MD5_H 1 00023 00024 #include <stddef.h> 00025 #include <stdio.h> 00026 00027 #if defined HAVE_LIMITS_H || _LIBC 00028 # include <limits.h> 00029 #endif 00030 00031 /* The following contortions are an attempt to use the C preprocessor 00032 to determine an unsigned integral type that is 32 bits wide. An 00033 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but 00034 doing that would require that the configure script compile and *run* 00035 the resulting executable. Locally running cross-compiled executables 00036 is usually not possible. */ 00037 00038 #ifdef _LIBC 00039 # include <sys/types.h> 00040 typedef u_int32_t md5_uint32; 00041 #else 00042 # if defined __STDC__ && __STDC__ 00043 # define UINT_MAX_32_BITS 4294967295U 00044 # else 00045 # define UINT_MAX_32_BITS 0xFFFFFFFF 00046 # endif 00047 00048 /* If UINT_MAX isn't defined, assume it's a 32-bit type. 00049 This should be valid for all systems GNU cares about because 00050 that doesn't include 16-bit systems, and only modern systems 00051 (that certainly have <limits.h>) have 64+-bit integral types. */ 00052 00053 # ifndef UINT_MAX 00054 # define UINT_MAX UINT_MAX_32_BITS 00055 # endif 00056 00057 # if UINT_MAX == UINT_MAX_32_BITS 00058 typedef unsigned int md5_uint32; 00059 # else 00060 # if USHRT_MAX == UINT_MAX_32_BITS 00061 typedef unsigned short md5_uint32; 00062 # else 00063 # if ULONG_MAX == UINT_MAX_32_BITS 00064 typedef unsigned long md5_uint32; 00065 # else 00066 /* The following line is intended to evoke an error. 00067 Using #error is not portable enough. */ 00068 "Cannot determine unsigned 32-bit data type." 00069 # endif 00070 # endif 00071 # endif 00072 #endif 00073 #undef __P 00074 #if defined (__STDC__) && __STDC__ 00075 #define __P(x) x 00076 #else 00077 #define __P(x) () 00078 #endif 00079 /* Structure to save state of computation between the single steps. */ 00080 struct md5_ctx 00081 { 00082 md5_uint32 A; 00083 md5_uint32 B; 00084 md5_uint32 C; 00085 md5_uint32 D; 00086 00087 md5_uint32 total[2]; 00088 md5_uint32 buflen; 00089 char buffer[128]; 00090 }; 00091 00092 /* 00093 * The following three functions are build up the low level used in 00094 * the functions `md5_stream' and `md5_buffer'. 00095 */ 00096 00097 /* Initialize structure containing state of computation. 00098 (RFC 1321, 3.3: Step 3) */ 00099 extern void md5_init_ctx __P ((struct md5_ctx * ctx)); 00100 00101 00102 /* Starting with the result of former calls of this function (or the 00103 initialization function update the context for the next LEN bytes 00104 starting at BUFFER. 00105 00106 It is necessary that LEN is a multiple of 64!!! 00107 00108 IMPORTANT: On some systems it is required that buffer be 32-bit 00109 aligned. */ 00110 extern void md5_process_block __P ((const void *buffer, size_t len, 00111 struct md5_ctx * ctx)); 00112 00113 /* Starting with the result of former calls of this function (or the 00114 initialization function) update the context for the next LEN bytes 00115 starting at BUFFER. 00116 00117 It is NOT required that LEN is a multiple of 64. 00118 00119 IMPORTANT: On some systems it is required that buffer be 32-bit 00120 aligned. */ 00121 extern void md5_process_bytes __P ((const void *buffer, size_t len, 00122 struct md5_ctx * ctx)); 00123 00124 /* Process the remaining bytes in the buffer and put result from CTX 00125 in first 16 bytes following RESBUF. The result is always in little 00126 endian byte order, so that a byte-wise output yields to the wanted 00127 ASCII representation of the message digest. 00128 00129 IMPORTANT: On some systems it is required that RESBUF be correctly 00130 aligned for a 32 bits value. */ 00131 extern void *md5_finish_ctx __P ((struct md5_ctx * ctx, void *resbuf)); 00132 00133 00134 /* Put result from CTX in first 16 bytes following RESBUF. The result is 00135 always in little endian byte order, so that a byte-wise output yields 00136 to the wanted ASCII representation of the message digest. 00137 00138 IMPORTANT: On some systems it is required that RESBUF be correctly 00139 aligned for a 32 bits value. */ 00140 extern void *md5_read_ctx __P ((const struct md5_ctx * ctx, void *resbuf)); 00141 00142 00143 /* Compute MD5 message digest for bytes read from STREAM. The 00144 resulting message digest number will be written into the 16 bytes 00145 beginning at RESBLOCK. 00146 00147 IMPORTANT: On some systems it is required that resblock be 32-bit 00148 aligned. */ 00149 extern int md5_stream __P ((FILE * stream, void *resblock)); 00150 00151 00152 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The 00153 result is always in little endian byte order, so that a byte-wise 00154 output yields to the wanted ASCII representation of the message 00155 digest. 00156 00157 IMPORTANT: On some systems it is required that buffer and resblock 00158 be correctly 32-bit aligned. */ 00159 extern void *md5_buffer 00160 __P ((const char *buffer, size_t len, void *resblock)); 00161 00162 #endif