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