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