1 /* Declaration of functions and data types used for MD5 sum computing
3 Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2024 Free Software
5 This file is part of the GNU C Library.
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 This file 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 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>. */
23 /* This file uses HAVE_OPENSSL_MD5. */
24 #if !_GL_CONFIG_H_INCLUDED
25 #error "Please include config.h first."
32 # ifndef OPENSSL_API_COMPAT
33 # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */
35 /* If <openssl/macros.h> would give a compile-time error, don't use OpenSSL. */
36 # include <openssl/opensslv.h>
37 # if OPENSSL_VERSION_MAJOR >= 3
38 # include <openssl/configuration.h>
39 # if (OPENSSL_CONFIGURED_API \
40 < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \
41 ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \
42 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
43 + ((OPENSSL_API_COMPAT >> 12) & 0xFF)))
44 # undef HAVE_OPENSSL_MD5
48 # include <openssl/md5.h>
52 #define MD5_DIGEST_SIZE 16
53 #define MD5_BLOCK_SIZE 64
56 # if defined __GNUC__ && defined __GNUC_MINOR__
57 # define __GNUC_PREREQ(maj, min) \
58 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
60 # define __GNUC_PREREQ(maj, min) 0
65 # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
66 # if __cplusplus >= 201103L
67 # define __THROW noexcept (true)
69 # define __THROW throw ()
77 # define __md5_buffer md5_buffer
78 # define __md5_finish_ctx md5_finish_ctx
79 # define __md5_init_ctx md5_init_ctx
80 # define __md5_process_block md5_process_block
81 # define __md5_process_bytes md5_process_bytes
82 # define __md5_read_ctx md5_read_ctx
83 # define __md5_stream md5_stream
91 # define GL_OPENSSL_NAME 5
92 # include "gl_openssl.h"
94 /* Structure to save state of computation between the single steps. */
103 uint32_t buflen
; /* ≥ 0, ≤ 128 */
104 uint32_t buffer
[32]; /* 128 bytes; the first buflen bytes are in use */
108 * The following three functions are build up the low level used in
109 * the functions 'md5_stream' and 'md5_buffer'.
112 /* Initialize structure containing state of computation.
113 (RFC 1321, 3.3: Step 3) */
114 extern void __md5_init_ctx (struct md5_ctx
*ctx
) __THROW
;
116 /* Starting with the result of former calls of this function (or the
117 initialization function update the context for the next LEN bytes
119 It is necessary that LEN is a multiple of 64!!! */
120 extern void __md5_process_block (const void *buffer
, size_t len
,
121 struct md5_ctx
*ctx
) __THROW
;
123 /* Starting with the result of former calls of this function (or the
124 initialization function update the context for the next LEN bytes
126 It is NOT required that LEN is a multiple of 64. */
127 extern void __md5_process_bytes (const void *buffer
, size_t len
,
128 struct md5_ctx
*ctx
) __THROW
;
130 /* Process the remaining bytes in the buffer and put result from CTX
131 in first 16 bytes following RESBUF. The result is always in little
132 endian byte order, so that a byte-wise output yields to the wanted
133 ASCII representation of the message digest. */
134 extern void *__md5_finish_ctx (struct md5_ctx
*ctx
, void *restrict resbuf
)
138 /* Put result from CTX in first 16 bytes following RESBUF. The result is
139 always in little endian byte order, so that a byte-wise output yields
140 to the wanted ASCII representation of the message digest. */
141 extern void *__md5_read_ctx (const struct md5_ctx
*ctx
, void *restrict resbuf
)
145 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
146 result is always in little endian byte order, so that a byte-wise
147 output yields to the wanted ASCII representation of the message
149 extern void *__md5_buffer (const char *buffer
, size_t len
,
150 void *restrict resblock
) __THROW
;
154 /* Compute MD5 message digest for bytes read from STREAM.
155 STREAM is an open file stream. Regular files are handled more efficiently.
156 The contents of STREAM from its current position to its end will be read.
157 The case that the last operation on STREAM was an 'ungetc' is not supported.
158 The resulting message digest number will be written into the 16 bytes
159 beginning at RESBLOCK. */
160 extern int __md5_stream (FILE *stream
, void *resblock
) __THROW
;