Back to index

avfs  1.0.1
neon_md5.h
Go to the documentation of this file.
00001 /* Declaration of functions and data types used for MD5 sum computing
00002    library functions.
00003    Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public License as
00008    published by the Free Software Foundation; either version 2 of the
00009    License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public
00017    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00018    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
00020 
00021 #ifndef NEON_MD5_H
00022 #define NEON_MD5_H 1
00023 
00024 #include "neonconf.h"
00025 
00026 #include <stdio.h>
00027 
00028 #if defined HAVE_LIMITS_H || _LIBC
00029 # include <limits.h>
00030 #endif
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 #else
00043 # if defined __STDC__ && __STDC__
00044 #  define UINT_MAX_32_BITS 4294967295U
00045 # else
00046 #  define UINT_MAX_32_BITS 0xFFFFFFFF
00047 # endif
00048 
00049 /* If UINT_MAX isn't defined, assume it's a 32-bit type.
00050    This should be valid for all systems GNU cares about because
00051    that doesn't include 16-bit systems, and only modern systems
00052    (that certainly have <limits.h>) have 64+-bit integral types.  */
00053 
00054 # ifndef UINT_MAX
00055 #  define UINT_MAX UINT_MAX_32_BITS
00056 # endif
00057 
00058 # if UINT_MAX == UINT_MAX_32_BITS
00059    typedef unsigned int md5_uint32;
00060 # else
00061 #  if USHRT_MAX == UINT_MAX_32_BITS
00062     typedef unsigned short md5_uint32;
00063 #  else
00064 #   if ULONG_MAX == UINT_MAX_32_BITS
00065      typedef unsigned long md5_uint32;
00066 #   else
00067      /* The following line is intended to evoke an error.
00068         Using #error is not portable enough.  */
00069      "Cannot determine unsigned 32-bit data type."
00070 #   endif
00071 #  endif
00072 # endif
00073 #endif
00074 
00075 #undef __P
00076 #if defined (__STDC__) && __STDC__
00077 # define __P(x) x
00078 #else
00079 # define __P(x) ()
00080 #endif
00081 
00082 /* Structure to save state of computation between the single steps.  */
00083 struct md5_ctx
00084 {
00085   md5_uint32 A;
00086   md5_uint32 B;
00087   md5_uint32 C;
00088   md5_uint32 D;
00089 
00090   md5_uint32 total[2];
00091   md5_uint32 buflen;
00092   char buffer[128];
00093 };
00094 
00095 /*
00096  * The following three functions are build up the low level used in
00097  * the functions `md5_stream' and `md5_buffer'.
00098  */
00099 
00100 /* Initialize structure containing state of computation.
00101    (RFC 1321, 3.3: Step 3)  */
00102 extern void __md5_init_ctx __P ((struct md5_ctx *ctx));
00103 extern void md5_init_ctx __P ((struct md5_ctx *ctx));
00104 
00105 /* Starting with the result of former calls of this function (or the
00106    initialization function update the context for the next LEN bytes
00107    starting at BUFFER.
00108    It is necessary that LEN is a multiple of 64!!! */
00109 extern void __md5_process_block __P ((const void *buffer, size_t len,
00110                                   struct md5_ctx *ctx));
00111 extern void md5_process_block __P ((const void *buffer, size_t len,
00112                                 struct md5_ctx *ctx));
00113 
00114 /* Starting with the result of former calls of this function (or the
00115    initialization function update the context for the next LEN bytes
00116    starting at BUFFER.
00117    It is NOT required that LEN is a multiple of 64.  */
00118 extern void __md5_process_bytes __P ((const void *buffer, size_t len,
00119                                   struct md5_ctx *ctx));
00120 extern void md5_process_bytes __P ((const void *buffer, size_t len,
00121                                 struct md5_ctx *ctx));
00122 
00123 /* Process the remaining bytes in the buffer and put result from CTX
00124    in first 16 bytes following RESBUF.  The result is always in little
00125    endian byte order, so that a byte-wise output yields to the wanted
00126    ASCII representation of the message digest.
00127 
00128    IMPORTANT: On some systems it is required that RESBUF is correctly
00129    aligned for a 32 bits value.  */
00130 extern void *__md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
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 is correctly
00139    aligned for a 32 bits value.  */
00140 extern void *__md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
00141 extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
00142 
00143 
00144 /* Compute MD5 message digest for bytes read from STREAM.  The
00145    resulting message digest number will be written into the 16 bytes
00146    beginning at RESBLOCK.  */
00147 extern int __md5_stream __P ((FILE *stream, void *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,
00155                             void *resblock));
00156 extern void *md5_buffer __P ((const char *buffer, size_t len,
00157                            void *resblock));
00158 
00159 #endif /* NEON_MD5_H */