1 | /* Declaration of functions and data types used for MD5 sum computing |
2 | library functions. |
3 | Copyright (C) 1995-2024 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #ifndef _MD5_H |
21 | #define _MD5_H 1 |
22 | |
23 | #define MD5_DIGEST_SIZE 16 |
24 | #define MD5_BLOCK_SIZE 64 |
25 | |
26 | /* The following contortions are an attempt to use the C preprocessor |
27 | to determine an unsigned integral type that is 32 bits wide. An |
28 | alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but |
29 | doing that would require that the configure script compile and *run* |
30 | the resulting executable. Locally running cross-compiled executables |
31 | is usually not possible. */ |
32 | |
33 | #include <stdint.h> |
34 | typedef uint32_t md5_uint32; |
35 | typedef uintptr_t md5_uintptr; |
36 | |
37 | /* Structure to save state of computation between the single steps. */ |
38 | struct md5_ctx |
39 | { |
40 | md5_uint32 A; |
41 | md5_uint32 B; |
42 | md5_uint32 C; |
43 | md5_uint32 D; |
44 | |
45 | md5_uint32 total[2]; |
46 | md5_uint32 buflen; |
47 | union |
48 | { |
49 | char buffer[128]; |
50 | md5_uint32 buffer32[32]; |
51 | }; |
52 | }; |
53 | |
54 | /* |
55 | * The following three functions are build up the low level used in |
56 | * the functions `md5_stream' and `md5_buffer'. |
57 | */ |
58 | |
59 | /* Initialize structure containing state of computation. |
60 | (RFC 1321, 3.3: Step 3) */ |
61 | extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; |
62 | |
63 | /* Starting with the result of former calls of this function (or the |
64 | initialization function update the context for the next LEN bytes |
65 | starting at BUFFER. |
66 | It is necessary that LEN is a multiple of 64!!! */ |
67 | extern void __md5_process_block (const void *buffer, size_t len, |
68 | struct md5_ctx *ctx) __THROW; |
69 | |
70 | /* Starting with the result of former calls of this function (or the |
71 | initialization function update the context for the next LEN bytes |
72 | starting at BUFFER. |
73 | It is NOT required that LEN is a multiple of 64. */ |
74 | extern void __md5_process_bytes (const void *buffer, size_t len, |
75 | struct md5_ctx *ctx) __THROW; |
76 | |
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. |
81 | |
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) __THROW; |
85 | |
86 | |
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. |
90 | |
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) __THROW; |
94 | |
95 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The |
96 | result is always in little endian byte order, so that a byte-wise |
97 | output yields to the wanted ASCII representation of the message |
98 | digest. */ |
99 | extern void *__md5_buffer (const char *buffer, size_t len, |
100 | void *resblock) __THROW; |
101 | |
102 | #endif /* md5.h */ |
103 | |