GNU Radio 3.4.2 C++ API
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 (C) 1995, 1996, 1999, 2000, 2003 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 3, 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, Boston, MA 02110-1301, USA.  */
00020 
00021 #ifndef _MD5_H
00022 #define _MD5_H 1
00023 
00024 #include <stdio.h>
00025 #include <limits.h>
00026 
00027 /* The following contortions are an attempt to use the C preprocessor
00028    to determine an unsigned integral type that is 32 bits wide.  An
00029    alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
00030    doing that would require that the configure script compile and *run*
00031    the resulting executable.  Locally running cross-compiled executables
00032    is usually not possible.  */
00033 
00034 #ifdef _LIBC
00035 # include <stdint.h>
00036 typedef uint32_t md5_uint32;
00037 typedef uintptr_t md5_uintptr;
00038 #else
00039 # define UINT_MAX_32_BITS 4294967295U
00040 
00041 # if UINT_MAX == UINT_MAX_32_BITS
00042    typedef unsigned int md5_uint32;
00043 # else
00044 #  if USHRT_MAX == UINT_MAX_32_BITS
00045     typedef unsigned short md5_uint32;
00046 #  else
00047 #   if ULONG_MAX == UINT_MAX_32_BITS
00048      typedef unsigned long md5_uint32;
00049 #   else
00050      /* The following line is intended to evoke an error.
00051         Using #error is not portable enough.  */
00052      "Cannot determine unsigned 32-bit data type."
00053 #   endif
00054 #  endif
00055 # endif
00056 /* We have to make a guess about the integer type equivalent in size
00057    to pointers which should always be correct.  */
00058 typedef unsigned long int md5_uintptr;
00059 #endif
00060 
00061 /* Structure to save state of computation between the single steps.  */
00062 struct md5_ctx
00063 {
00064   md5_uint32 A;
00065   md5_uint32 B;
00066   md5_uint32 C;
00067   md5_uint32 D;
00068 
00069   md5_uint32 total[2];
00070   md5_uint32 buflen;
00071   char buffer[128];
00072 };
00073 
00074 /*
00075  * The following three functions are build up the low level used in
00076  * the functions `md5_stream' and `md5_buffer'.
00077  */
00078 
00079 /* Initialize structure containing state of computation.
00080    (RFC 1321, 3.3: Step 3)  */
00081 extern void md5_init_ctx (struct md5_ctx *ctx);
00082 
00083 /* Starting with the result of former calls of this function (or the
00084    initialization function update the context for the next LEN bytes
00085    starting at BUFFER.
00086    It is necessary that LEN is a multiple of 64!!! */
00087 extern void md5_process_block (const void *buffer, size_t len,
00088                                struct md5_ctx *ctx);
00089 
00090 /* Starting with the result of former calls of this function (or the
00091    initialization function update the context for the next LEN bytes
00092    starting at BUFFER.
00093    It is NOT required that LEN is a multiple of 64.  */
00094 extern void md5_process_bytes (const void *buffer, size_t len,
00095                                struct md5_ctx *ctx);
00096 
00097 /* Process the remaining bytes in the buffer and put result from CTX
00098    in first 16 bytes following RESBUF.  The result is always in little
00099    endian byte order, so that a byte-wise output yields to the wanted
00100    ASCII representation of the message digest.
00101 
00102    IMPORTANT: On some systems it is required that RESBUF be correctly
00103    aligned for a 32 bits value.  */
00104 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
00105 
00106 
00107 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
00108    always in little endian byte order, so that a byte-wise output yields
00109    to the wanted ASCII representation of the message digest.
00110 
00111    IMPORTANT: On some systems it is required that RESBUF is correctly
00112    aligned for a 32 bits value.  */
00113 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
00114 
00115 
00116 /* Compute MD5 message digest for bytes read from STREAM.  The
00117    resulting message digest number will be written into the 16 bytes
00118    beginning at RESBLOCK.  */
00119 extern int md5_stream (FILE *stream, void *resblock);
00120 
00121 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
00122    result is always in little endian byte order, so that a byte-wise
00123    output yields to the wanted ASCII representation of the message
00124    digest.  */
00125 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
00126 
00127 #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
00128 
00129 #endif