00001 /* md5.h - Declaration of functions and data types used for MD5 sum 00002 computing library functions. 00003 Copyright (C) 1995, 1996, 1999 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 LIBDVDREAD_MD5_H 00022 #define LIBDVDREAD_MD5_H 00023 00024 #include <stdio.h> 00025 00026 #if HAVE_LIMITS_H || _LIBC 00027 # include <limits.h> 00028 #endif 00029 00030 /* The following contortions are an attempt to use the C preprocessor 00031 to determine an unsigned integral type that is 32 bits wide. An 00032 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but 00033 doing that would require that the configure script compile and *run* 00034 the resulting executable. Locally running cross-compiled executables 00035 is usually not possible. */ 00036 00037 #ifdef _LIBC 00038 # include <sys/types.h> 00039 typedef u_int32_t md5_uint32; 00040 #else 00041 # if defined __STDC__ && __STDC__ 00042 # define UINT_MAX_32_BITS 4294967295U 00043 # else 00044 # define UINT_MAX_32_BITS 0xFFFFFFFF 00045 # endif 00046 00047 /* If UINT_MAX isn't defined, assume it's a 32-bit type. 00048 This should be valid for all systems GNU cares about because 00049 that doesn't include 16-bit systems, and only modern systems 00050 (that certainly have <limits.h>) have 64+-bit integral types. */ 00051 00052 # ifndef UINT_MAX 00053 # define UINT_MAX UINT_MAX_32_BITS 00054 # endif 00055 00056 # if UINT_MAX == UINT_MAX_32_BITS 00057 typedef unsigned int md5_uint32; 00058 # else 00059 # if USHRT_MAX == UINT_MAX_32_BITS 00060 typedef unsigned short md5_uint32; 00061 # else 00062 # if ULONG_MAX == UINT_MAX_32_BITS 00063 typedef unsigned long md5_uint32; 00064 # else 00065 /* The following line is intended to evoke an error. 00066 Using #error is not portable enough. */ 00067 "Cannot determine unsigned 32-bit data type." 00068 # endif 00069 # endif 00070 # endif 00071 #endif 00072 00073 #undef __P 00074 #if defined (__STDC__) && __STDC__ 00075 #define __P(x) x 00076 #else 00077 #define __P(x) () 00078 #endif 00079 00080 /* Structure to save state of computation between the single steps. */ 00081 struct md5_ctx 00082 { 00083 md5_uint32 A; 00084 md5_uint32 B; 00085 md5_uint32 C; 00086 md5_uint32 D; 00087 00088 md5_uint32 total[2]; 00089 md5_uint32 buflen; 00090 char buffer[128]; 00091 }; 00092 00093 /* 00094 * The following three functions are build up the low level used in 00095 * the functions `md5_stream' and `md5_buffer'. 00096 */ 00097 00098 /* Initialize structure containing state of computation. 00099 (RFC 1321, 3.3: Step 3) */ 00100 extern void md5_init_ctx __P ((struct md5_ctx *ctx)); 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 It is necessary that LEN is a multiple of 64!!! */ 00106 extern void md5_process_block __P ((const void *buffer, size_t len, 00107 struct md5_ctx *ctx)); 00108 00109 /* Starting with the result of former calls of this function (or the 00110 initialization function update the context for the next LEN bytes 00111 starting at BUFFER. 00112 It is NOT required that LEN is a multiple of 64. */ 00113 extern void md5_process_bytes __P ((const void *buffer, size_t len, 00114 struct md5_ctx *ctx)); 00115 00116 /* Process the remaining bytes in the buffer and put result from CTX 00117 in first 16 bytes following RESBUF. The result is always in little 00118 endian byte order, so that a byte-wise output yields to the wanted 00119 ASCII representation of the message digest. 00120 00121 IMPORTANT: On some systems it is required that RESBUF be correctly 00122 aligned for a 32 bits value. */ 00123 extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf)); 00124 00125 00126 /* Put result from CTX in first 16 bytes following RESBUF. The result is 00127 always in little endian byte order, so that a byte-wise output yields 00128 to the wanted ASCII representation of the message digest. 00129 00130 IMPORTANT: On some systems it is required that RESBUF is correctly 00131 aligned for a 32 bits value. */ 00132 extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf)); 00133 00134 00135 /* Compute MD5 message digest for bytes read from STREAM. The 00136 resulting message digest number will be written into the 16 bytes 00137 beginning at RESBLOCK. */ 00138 extern int md5_stream __P ((FILE *stream, void *resblock)); 00139 00140 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The 00141 result is always in little endian byte order, so that a byte-wise 00142 output yields to the wanted ASCII representation of the message 00143 digest. */ 00144 extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock)); 00145 00146 /* The following is from gnupg-1.0.2's cipher/bithelp.h. */ 00147 /* Rotate a 32 bit integer by n bytes */ 00148 #if defined __GNUC__ && defined __i386__ 00149 static inline md5_uint32 00150 rol(md5_uint32 x, int n) 00151 { 00152 __asm__("roll %%cl,%0" 00153 :"=r" (x) 00154 :"0" (x),"c" (n)); 00155 return x; 00156 } 00157 #else 00158 # define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) 00159 #endif 00160 00161 #endif /* LIBDVDREAD_MD5_H */
1.6.3