Back to index

cell-binutils  2.17cvs20070401
md5.h
Go to the documentation of this file.
00001 /* md5.h - Declaration of functions and data types used for MD5 sum
00002    computing library functions.
00003    Copyright 1995, 1996, 2000 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 <stdio.h>
00025 
00026 #if defined HAVE_LIMITS_H || _LIBC
00027 # include <limits.h>
00028 #endif
00029 
00030 #include "ansidecl.h"
00031 
00032 /* The following contortions are an attempt to use the C preprocessor
00033    to determine an unsigned integral type that is 32 bits wide.  An
00034    alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
00035    doing that would require that the configure script compile and *run*
00036    the resulting executable.  Locally running cross-compiled executables
00037    is usually not possible.  */
00038 
00039 #ifdef _LIBC
00040 # include <sys/types.h>
00041 typedef u_int32_t md5_uint32;
00042 typedef uintptr_t md5_uintptr;
00043 #else
00044 #  define INT_MAX_32_BITS 2147483647
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 INT_MAX
00052 #  define INT_MAX INT_MAX_32_BITS
00053 # endif
00054 
00055 # if INT_MAX == INT_MAX_32_BITS
00056    typedef unsigned int md5_uint32;
00057 # else
00058 #  if SHRT_MAX == INT_MAX_32_BITS
00059     typedef unsigned short md5_uint32;
00060 #  else
00061 #   if LONG_MAX == INT_MAX_32_BITS
00062      typedef unsigned long md5_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 /* We have to make a guess about the integer type equivalent in size
00071    to pointers which should always be correct.  */
00072 typedef unsigned long int md5_uintptr;
00073 #endif
00074 
00075 /* Structure to save state of computation between the single steps.  */
00076 struct md5_ctx
00077 {
00078   md5_uint32 A;
00079   md5_uint32 B;
00080   md5_uint32 C;
00081   md5_uint32 D;
00082 
00083   md5_uint32 total[2];
00084   md5_uint32 buflen;
00085   char buffer[128] ATTRIBUTE_ALIGNED_ALIGNOF(md5_uint32);
00086 };
00087 
00088 /*
00089  * The following three functions are build up the low level used in
00090  * the functions `md5_stream' and `md5_buffer'.
00091  */
00092 
00093 /* Initialize structure containing state of computation.
00094    (RFC 1321, 3.3: Step 3)  */
00095 extern void md5_init_ctx (struct md5_ctx *ctx);
00096 
00097 /* Starting with the result of former calls of this function (or the
00098    initialization function update the context for the next LEN bytes
00099    starting at BUFFER.
00100    It is necessary that LEN is a multiple of 64!!! */
00101 extern void md5_process_block (const void *buffer, size_t len,
00102                                struct md5_ctx *ctx);
00103 
00104 /* Starting with the result of former calls of this function (or the
00105    initialization function update the context for the next LEN bytes
00106    starting at BUFFER.
00107    It is NOT required that LEN is a multiple of 64.  */
00108 extern void md5_process_bytes (const void *buffer, size_t len,
00109                                struct md5_ctx *ctx);
00110 
00111 /* Process the remaining bytes in the buffer and put result from CTX
00112    in first 16 bytes following RESBUF.  The result is always in little
00113    endian byte order, so that a byte-wise output yields to the wanted
00114    ASCII representation of the message digest.
00115 
00116    IMPORTANT: On some systems it is required that RESBUF is correctly
00117    aligned for a 32 bits value.  */
00118 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
00119 
00120 
00121 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
00122    always in little endian byte order, so that a byte-wise output yields
00123    to the wanted ASCII representation of the message digest.
00124 
00125    IMPORTANT: On some systems it is required that RESBUF is correctly
00126    aligned for a 32 bits value.  */
00127 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
00128 
00129 
00130 /* Compute MD5 message digest for bytes read from STREAM.  The
00131    resulting message digest number will be written into the 16 bytes
00132    beginning at RESBLOCK.  */
00133 extern int md5_stream (FILE *stream, void *resblock);
00134 
00135 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
00136    result is always in little endian byte order, so that a byte-wise
00137    output yields to the wanted ASCII representation of the message
00138    digest.  */
00139 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
00140 
00141 #endif