Commit | Line | Data |
---|---|---|
693c4692 GM |
1 | /* Declaration of functions and data types used for MD5 sum computing |
2 | library functions. | |
ab422c4d | 3 | Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2013 Free Software |
942f733f PE |
4 | Foundation, Inc. |
5 | This file is part of the GNU C Library. | |
693c4692 | 6 | |
942f733f PE |
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 | |
10 | later version. | |
693c4692 | 11 | |
942f733f | 12 | This program is distributed in the hope that it will be useful, |
693c4692 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
942f733f PE |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | |
693c4692 | 16 | |
942f733f | 17 | You should have received a copy of the GNU General Public License |
caf8a9b2 | 18 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
693c4692 GM |
19 | |
20 | #ifndef _MD5_H | |
21 | #define _MD5_H 1 | |
22 | ||
23 | #include <stdio.h> | |
5f90be1b | 24 | #include <stdint.h> |
693c4692 | 25 | |
942f733f PE |
26 | #define MD5_DIGEST_SIZE 16 |
27 | #define MD5_BLOCK_SIZE 64 | |
28 | ||
29 | #ifndef __GNUC_PREREQ | |
30 | # if defined __GNUC__ && defined __GNUC_MINOR__ | |
31 | # define __GNUC_PREREQ(maj, min) \ | |
32 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | |
33 | # else | |
34 | # define __GNUC_PREREQ(maj, min) 0 | |
35 | # endif | |
36 | #endif | |
37 | ||
38 | #ifndef __THROW | |
39 | # if defined __cplusplus && __GNUC_PREREQ (2,8) | |
40 | # define __THROW throw () | |
41 | # else | |
42 | # define __THROW | |
43 | # endif | |
44 | #endif | |
45 | ||
46 | #ifndef _LIBC | |
47 | # define __md5_buffer md5_buffer | |
48 | # define __md5_finish_ctx md5_finish_ctx | |
49 | # define __md5_init_ctx md5_init_ctx | |
50 | # define __md5_process_block md5_process_block | |
51 | # define __md5_process_bytes md5_process_bytes | |
52 | # define __md5_read_ctx md5_read_ctx | |
53 | # define __md5_stream md5_stream | |
693c4692 GM |
54 | #endif |
55 | ||
942f733f PE |
56 | # ifdef __cplusplus |
57 | extern "C" { | |
58 | # endif | |
59 | ||
693c4692 GM |
60 | /* Structure to save state of computation between the single steps. */ |
61 | struct md5_ctx | |
62 | { | |
5f90be1b PE |
63 | uint32_t A; |
64 | uint32_t B; | |
65 | uint32_t C; | |
66 | uint32_t D; | |
67 | ||
68 | uint32_t total[2]; | |
69 | uint32_t buflen; | |
70 | uint32_t buffer[32]; | |
693c4692 GM |
71 | }; |
72 | ||
73 | /* | |
74 | * The following three functions are build up the low level used in | |
caf8a9b2 | 75 | * the functions 'md5_stream' and 'md5_buffer'. |
693c4692 GM |
76 | */ |
77 | ||
78 | /* Initialize structure containing state of computation. | |
79 | (RFC 1321, 3.3: Step 3) */ | |
942f733f | 80 | extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; |
693c4692 GM |
81 | |
82 | /* Starting with the result of former calls of this function (or the | |
83 | initialization function update the context for the next LEN bytes | |
84 | starting at BUFFER. | |
85 | It is necessary that LEN is a multiple of 64!!! */ | |
942f733f PE |
86 | extern void __md5_process_block (const void *buffer, size_t len, |
87 | struct md5_ctx *ctx) __THROW; | |
693c4692 GM |
88 | |
89 | /* Starting with the result of former calls of this function (or the | |
90 | initialization function update the context for the next LEN bytes | |
91 | starting at BUFFER. | |
92 | It is NOT required that LEN is a multiple of 64. */ | |
942f733f PE |
93 | extern void __md5_process_bytes (const void *buffer, size_t len, |
94 | struct md5_ctx *ctx) __THROW; | |
693c4692 GM |
95 | |
96 | /* Process the remaining bytes in the buffer and put result from CTX | |
97 | in first 16 bytes following RESBUF. The result is always in little | |
98 | endian byte order, so that a byte-wise output yields to the wanted | |
942f733f PE |
99 | ASCII representation of the message digest. */ |
100 | extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW; | |
693c4692 GM |
101 | |
102 | ||
103 | /* Put result from CTX in first 16 bytes following RESBUF. The result is | |
104 | always in little endian byte order, so that a byte-wise output yields | |
942f733f PE |
105 | to the wanted ASCII representation of the message digest. */ |
106 | extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; | |
693c4692 GM |
107 | |
108 | ||
109 | /* Compute MD5 message digest for bytes read from STREAM. The | |
110 | resulting message digest number will be written into the 16 bytes | |
111 | beginning at RESBLOCK. */ | |
942f733f | 112 | extern int __md5_stream (FILE *stream, void *resblock) __THROW; |
693c4692 GM |
113 | |
114 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The | |
115 | result is always in little endian byte order, so that a byte-wise | |
116 | output yields to the wanted ASCII representation of the message | |
117 | digest. */ | |
942f733f PE |
118 | extern void *__md5_buffer (const char *buffer, size_t len, |
119 | void *resblock) __THROW; | |
120 | ||
121 | # ifdef __cplusplus | |
122 | } | |
123 | # endif | |
693c4692 GM |
124 | |
125 | #endif /* md5.h */ |