1 /* md5.h - Declaration of functions and data types used for MD5 sum
2 computing library functions.
3 Copyright (C) 1995, 1996, 1999, 2000, 2003 Free Software Foundation, Inc.
4 NOTE: The canonical source of this file is maintained with the GNU C
5 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Boston, MA 02110-1301, USA. */
27 /* The following contortions are an attempt to use the C preprocessor
28 to determine an unsigned integral type that is 32 bits wide. An
29 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
30 doing that would require that the configure script compile and *run*
31 the resulting executable. Locally running cross-compiled executables
32 is usually not possible. */
36 typedef uint32_t md5_uint32;
37 typedef uintptr_t md5_uintptr;
39 # define UINT_MAX_32_BITS 4294967295U
41 # if UINT_MAX == UINT_MAX_32_BITS
42 typedef unsigned int md5_uint32;
44 # if USHRT_MAX == UINT_MAX_32_BITS
45 typedef unsigned short md5_uint32;
47 # if ULONG_MAX == UINT_MAX_32_BITS
48 typedef unsigned long md5_uint32;
50 /* The following line is intended to evoke an error.
51 Using #error is not portable enough. */
52 "Cannot determine unsigned 32-bit data type."
56 /* We have to make a guess about the integer type equivalent in size
57 to pointers which should always be correct. */
58 typedef unsigned long int md5_uintptr;
61 /* Structure to save state of computation between the single steps. */
75 * The following three functions are build up the low level used in
76 * the functions `md5_stream' and `md5_buffer'.
79 /* Initialize structure containing state of computation.
80 (RFC 1321, 3.3: Step 3) */
81 extern void md5_init_ctx (struct md5_ctx *ctx);
83 /* Starting with the result of former calls of this function (or the
84 initialization function update the context for the next LEN bytes
86 It is necessary that LEN is a multiple of 64!!! */
87 extern void md5_process_block (const void *buffer, size_t len,
90 /* Starting with the result of former calls of this function (or the
91 initialization function update the context for the next LEN bytes
93 It is NOT required that LEN is a multiple of 64. */
94 extern void md5_process_bytes (const void *buffer, size_t len,
97 /* Process the remaining bytes in the buffer and put result from CTX
98 in first 16 bytes following RESBUF. The result is always in little
99 endian byte order, so that a byte-wise output yields to the wanted
100 ASCII representation of the message digest.
102 IMPORTANT: On some systems it is required that RESBUF be correctly
103 aligned for a 32 bits value. */
104 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
107 /* Put result from CTX in first 16 bytes following RESBUF. The result is
108 always in little endian byte order, so that a byte-wise output yields
109 to the wanted ASCII representation of the message digest.
111 IMPORTANT: On some systems it is required that RESBUF is correctly
112 aligned for a 32 bits value. */
113 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
116 /* Compute MD5 message digest for bytes read from STREAM. The
117 resulting message digest number will be written into the 16 bytes
118 beginning at RESBLOCK. */
119 extern int md5_stream (FILE *stream, void *resblock);
121 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
122 result is always in little endian byte order, so that a byte-wise
123 output yields to the wanted ASCII representation of the message
125 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
127 #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )