.
[gnulib.git] / lib / md5.h
1 /* md5.h - Declaration of functions and data types used for MD5 sum
2    computing library functions.
3    Copyright (C) 1995 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 #ifndef _MD5_H
20 #define _MD5_H
21
22 #include <stdio.h>
23
24 #if defined HAVE_LIMITS_H || _LIBC
25 # include <limits.h>
26 #endif
27
28 /* The following contortions are an attempt to use the C preprocessor
29    to determine an unsigned integral type that is 32 bits wide.  An
30    alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
31    doing that would require that the configure script compile and *run*
32    the resulting executable.  Locally running cross-compiled executables
33    is usually not possible.  */
34
35 #if defined __STDC__ && __STDC__
36 # define UINT_MAX_32_BITS 4294967295U
37 #else
38 # define UINT_MAX_32_BITS 0xFFFFFFFF
39 #endif
40
41 /* If UINT_MAX isn't defined, assume it's a 32-bit type.
42    This should be valid for all systems GNU cares about because
43    that doesn't include 16-bit systems, and only modern systems
44    (that certainly have <limits.h>) have 64+-bit integral types.  */
45
46 #ifndef UINT_MAX
47 # define UINT_MAX UINT_MAX_32_BITS
48 #endif
49
50 #if UINT_MAX == UINT_MAX_32_BITS
51   typedef unsigned int md5_uint32;
52 #else
53 # if USHRT_MAX == UINT_MAX_32_BITS
54    typedef unsigned short md5_uint32;
55 # else
56 #  if ULONG_MAX == UINT_MAX_32_BITS
57     typedef unsigned long md5_uint32;
58 #  else
59     /* The following line is intended to evoke an error.
60        Using #error is not portable enough.  */
61     "Cannot determine unsigned 32-bit data type."
62 #  endif
63 # endif
64 #endif
65
66 /* Structure to save state of computation between the single steps.  */
67 struct md5_ctx
68 {
69   md5_uint32 A;
70   md5_uint32 B;
71   md5_uint32 C;
72   md5_uint32 D;
73 };
74
75 /*
76  * The following three functions are build up the low level used in
77  * the functions `md5_stream' and `md5_buffer'.
78  */
79
80 /* Initialize structure containing state of computation.
81    (RFC 1321, 3.3: Step 3)  */
82 void md5_init_ctx __P ((struct md5_ctx *ctx));
83
84 /* Starting with the result of former calls of this function (or the
85    initialzation function update the context for the next LEN bytes
86    starting at BUFFER.
87    It is necessary that LEN is a multiple of 64!!! */
88 void md5_process_block __P ((const void *buffer, size_t len,
89                              struct md5_ctx *ctx));
90
91 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
92    always in little endian byte order, so that a byte-wise output yields
93    to the wanted ASCII representation of the message digest.  */
94 void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
95
96
97 /* Compute MD5 message digest for bytes read from STREAM.  The
98    resulting message digest number will be written into the 16 bytes
99    beginning at RESBLOCK.  */
100 void *
101 md5_stream __P ((FILE *stream, void *resblock));
102
103 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
104    result is always in little endian byte order, so that a byte-wise
105    output yields to the wanted ASCII representation of the message
106    digest.  */
107 void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
108
109 #endif