Back to index

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