00001 /* Declaration of functions and data types used for MD4 hash computing 00002 library functions. 00003 Copyright (C) 2000,2002,2005 Bruce Guenter. 00004 00005 The GNU C Library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public License as 00007 published by the Free Software Foundation; either version 2 of the 00008 License, or (at your option) any later version. 00009 00010 The GNU C Library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with the GNU C Library; see the file COPYING.LIB. If not, 00017 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. */ 00019 00020 #ifndef _MD4_H 00021 #define _MD4_H 1 00022 00023 #include <stdio.h> 00024 00025 #if defined HAVE_LIMITS_H || _LIBC 00026 # include <limits.h> 00027 #endif 00028 00029 /* The following contortions are an attempt to use the C preprocessor 00030 to determine an unsigned integral type that is 32 bits wide. An 00031 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but 00032 doing that would require that the configure script compile and *run* 00033 the resulting executable. Locally running cross-compiled executables 00034 is usually not possible. */ 00035 00036 #ifdef _LIBC 00037 # include <sys/types.h> 00038 typedef u_int32_t md4_uint32; 00039 #else 00040 # if defined __STDC__ && __STDC__ 00041 # define UINT_MAX_32_BITS 4294967295U 00042 # else 00043 # define UINT_MAX_32_BITS 0xFFFFFFFF 00044 # endif 00045 00046 /* If UINT_MAX isn't defined, assume it's a 32-bit type. 00047 This should be valid for all systems GNU cares about because 00048 that doesn't include 16-bit systems, and only modern systems 00049 (that certainly have <limits.h>) have 64+-bit integral types. */ 00050 00051 # ifndef UINT_MAX 00052 # define UINT_MAX UINT_MAX_32_BITS 00053 # endif 00054 00055 # if UINT_MAX == UINT_MAX_32_BITS 00056 typedef unsigned int md4_uint32; 00057 # else 00058 # if USHRT_MAX == UINT_MAX_32_BITS 00059 typedef unsigned short md4_uint32; 00060 # else 00061 # if ULONG_MAX == UINT_MAX_32_BITS 00062 typedef unsigned long md4_uint32; 00063 # else 00064 /* The following line is intended to evoke an error. 00065 Using #error is not portable enough. */ 00066 "Cannot determine unsigned 32-bit data type." 00067 # endif 00068 # endif 00069 # endif 00070 #endif 00071 00072 #undef __P 00073 #if defined (__STDC__) && __STDC__ 00074 # define __P(x) x 00075 #else 00076 # define __P(x) () 00077 #endif 00078 00079 /* Structure to save state of computation between the single steps. */ 00080 struct md4_ctx 00081 { 00082 md4_uint32 A; 00083 md4_uint32 B; 00084 md4_uint32 C; 00085 md4_uint32 D; 00086 00087 md4_uint32 total[2]; 00088 md4_uint32 buflen; 00089 char buffer[64]; 00090 }; 00091 typedef struct md4_ctx MD4_CTX; 00092 00093 /* 00094 * The following three functions are build up the low level used in 00095 * the functions `md4_stream' and `md4_buffer'. 00096 */ 00097 00098 /* Initialize structure containing state of computation. 00099 (RFC 1320, 3.3: Step 3) */ 00100 extern void md4_init_ctx __P ((struct md4_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 md4_process_block __P ((const void *buffer, struct md4_ctx *ctx)); 00107 00108 /* Starting with the result of former calls of this function (or the 00109 initialization function update the context for the next LEN bytes 00110 starting at BUFFER. 00111 It is NOT required that LEN is a multiple of 64. */ 00112 extern void md4_process_bytes __P ((const void *buffer, size_t len, 00113 struct md4_ctx *ctx)); 00114 00115 /* Process the remaining bytes in the buffer and put result from CTX 00116 in first 16 bytes following RESBUF. The result is always in little 00117 endian byte order, so that a byte-wise output yields to the wanted 00118 ASCII representation of the message digest. 00119 00120 IMPORTANT: On some systems it is required that RESBUF is correctly 00121 aligned for a 32 bits value. */ 00122 extern void *md4_finish_ctx __P ((struct md4_ctx *ctx, void *resbuf)); 00123 00124 00125 /* Put result from CTX in first 16 bytes following RESBUF. The result is 00126 always in little endian byte order, so that a byte-wise output yields 00127 to the wanted ASCII representation of the message digest. 00128 00129 IMPORTANT: On some systems it is required that RESBUF is correctly 00130 aligned for a 32 bits value. */ 00131 extern void *md4_read_ctx __P ((const struct md4_ctx *ctx, void *resbuf)); 00132 00133 #endif /* md4.h */