1 /* Declaration of functions and data types used for MD5 sum computing
3 Copyright (C) 1995,1996,1997,1999-2001,2004,2005,2008 Red Hat, Inc.
4 This file is part of Red Hat elfutils.
5 Written by Ulrich Drepper <drepper@redhat.com>, 1995.
7 Red Hat elfutils is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by the
9 Free Software Foundation; version 2 of the License.
11 Red Hat elfutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with Red Hat elfutils; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
20 Red Hat elfutils is an included package of the Open Invention Network.
21 An included package of the Open Invention Network is a package for which
22 Open Invention Network licensees cross-license their patents. No patent
23 license is granted, either expressly or impliedly, by designation as an
24 included package. Should you wish to participate in the Open Invention
25 Network licensing program, please visit www.openinventionnetwork.com
26 <http://www.openinventionnetwork.com>. */
35 #define MD5_DIGEST_SIZE 16
36 #define MD5_BLOCK_SIZE 64
38 typedef uint32_t md5_uint32;
39 typedef uintptr_t md5_uintptr;
41 /* Structure to save state of computation between the single steps. */
51 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
55 * The following three functions are build up the low level used in
56 * the functions `md5_stream' and `md5_buffer'.
59 /* Initialize structure containing state of computation.
60 (RFC 1321, 3.3: Step 3) */
61 extern void md5_init_ctx (struct md5_ctx *ctx);
63 /* Starting with the result of former calls of this function (or the
64 initialization function update the context for the next LEN bytes
66 It is necessary that LEN is a multiple of 64!!! */
67 extern void md5_process_block (const void *buffer, size_t len,
70 /* Starting with the result of former calls of this function (or the
71 initialization function update the context for the next LEN bytes
73 It is NOT required that LEN is a multiple of 64. */
74 extern void md5_process_bytes (const void *buffer, size_t len,
77 /* Process the remaining bytes in the buffer and put result from CTX
78 in first 16 bytes following RESBUF. The result is always in little
79 endian byte order, so that a byte-wise output yields to the wanted
80 ASCII representation of the message digest.
82 IMPORTANT: On some systems it is required that RESBUF is correctly
83 aligned for a 32 bits value. */
84 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
87 /* Put result from CTX in first 16 bytes following RESBUF. The result is
88 always in little endian byte order, so that a byte-wise output yields
89 to the wanted ASCII representation of the message digest.
91 IMPORTANT: On some systems it is required that RESBUF is correctly
92 aligned for a 32 bits value. */
93 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
96 /* Compute MD5 message digest for bytes read from STREAM. The
97 resulting message digest number will be written into the 16 bytes
98 beginning at RESBLOCK. */
99 extern int md5_stream (FILE *stream, void *resblock);
101 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
102 result is always in little endian byte order, so that a byte-wise
103 output yields to the wanted ASCII representation of the message
105 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);