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