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 elfutils.
5 Written by Ulrich Drepper <drepper@redhat.com>, 1995.
7 This file is free software; you can redistribute it and/or modify
8 it under the terms of either
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at
12 your option) any later version
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at
18 your option) any later version
20 or both in parallel, as here.
22 elfutils is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see <http://www.gnu.org/licenses/>. */
38 #define MD5_DIGEST_SIZE 16
39 #define MD5_BLOCK_SIZE 64
41 typedef uint32_t md5_uint32;
42 typedef uintptr_t md5_uintptr;
44 /* Structure to save state of computation between the single steps. */
54 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
58 * The following three functions are build up the low level used in
59 * the functions `md5_stream' and `md5_buffer'.
62 /* Initialize structure containing state of computation.
63 (RFC 1321, 3.3: Step 3) */
64 extern void md5_init_ctx (struct md5_ctx *ctx);
66 /* Starting with the result of former calls of this function (or the
67 initialization function update the context for the next LEN bytes
69 It is necessary that LEN is a multiple of 64!!! */
70 extern void md5_process_block (const void *buffer, size_t len,
73 /* Starting with the result of former calls of this function (or the
74 initialization function update the context for the next LEN bytes
76 It is NOT required that LEN is a multiple of 64. */
77 extern void md5_process_bytes (const void *buffer, size_t len,
80 /* Process the remaining bytes in the buffer and put result from CTX
81 in first 16 bytes following RESBUF. The result is always in little
82 endian byte order, so that a byte-wise output yields to the wanted
83 ASCII representation of the message digest.
85 IMPORTANT: On some systems it is required that RESBUF is correctly
86 aligned for a 32 bits value. */
87 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
90 /* Put result from CTX in first 16 bytes following RESBUF. The result is
91 always in little endian byte order, so that a byte-wise output yields
92 to the wanted ASCII representation of the message digest.
94 IMPORTANT: On some systems it is required that RESBUF is correctly
95 aligned for a 32 bits value. */
96 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
99 /* Compute MD5 message digest for bytes read from STREAM. The
100 resulting message digest number will be written into the 16 bytes
101 beginning at RESBLOCK. */
102 extern int md5_stream (FILE *stream, void *resblock);
104 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
105 result is always in little endian byte order, so that a byte-wise
106 output yields to the wanted ASCII representation of the message
108 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);