Better comment for chdir_verify_path()
[dragonfly.git] / contrib / cvs-1.12.11 / lib / md5.h
1 /* md5.h - Declaration of functions and data types used for MD5 sum
2    computing library functions.
3
4    Copyright (C) 1995, 1996, 1999, 2000, 2003, 2004 Free Software
5    Foundation, Inc.
6
7    NOTE: The canonical source of this file is maintained with the GNU C
8    Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
9
10    This program is free software; you can redistribute it and/or modify it
11    under the terms of the GNU General Public License as published by the
12    Free Software Foundation; either version 2, or (at your option) any
13    later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software Foundation,
22    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
23
24 #ifndef _MD5_H
25 #define _MD5_H 1
26
27 #include <stdio.h>
28
29 #if HAVE_INTTYPES_H
30 # include <inttypes.h>
31 #endif
32 #if HAVE_STDINT_H || _LIBC
33 # include <stdint.h>
34 #endif
35
36 typedef uint32_t md5_uint32;
37
38 /* Structure to save state of computation between the single steps.  */
39 struct md5_ctx
40 {
41   md5_uint32 A;
42   md5_uint32 B;
43   md5_uint32 C;
44   md5_uint32 D;
45
46   md5_uint32 total[2];
47   md5_uint32 buflen;
48   char buffer[128];
49 };
50
51 /*
52  * The following three functions are build up the low level used in
53  * the functions `md5_stream' and `md5_buffer'.
54  */
55
56 /* Initialize structure containing state of computation.
57    (RFC 1321, 3.3: Step 3)  */
58 extern void md5_init_ctx (struct md5_ctx *ctx);
59
60 /* Starting with the result of former calls of this function (or the
61    initialization function update the context for the next LEN bytes
62    starting at BUFFER.
63    It is necessary that LEN is a multiple of 64!!! */
64 extern void md5_process_block (const void *buffer, size_t len,
65                                struct md5_ctx *ctx);
66
67 /* Starting with the result of former calls of this function (or the
68    initialization function update the context for the next LEN bytes
69    starting at BUFFER.
70    It is NOT required that LEN is a multiple of 64.  */
71 extern void md5_process_bytes (const void *buffer, size_t len,
72                                struct md5_ctx *ctx);
73
74 /* Process the remaining bytes in the buffer and put result from CTX
75    in first 16 bytes following RESBUF.  The result is always in little
76    endian byte order, so that a byte-wise output yields to the wanted
77    ASCII representation of the message digest.
78
79    IMPORTANT: On some systems it is required that RESBUF be correctly
80    aligned for a 32 bits value.  */
81 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
82
83
84 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
85    always in little endian byte order, so that a byte-wise output yields
86    to the wanted ASCII representation of the message digest.
87
88    IMPORTANT: On some systems it is required that RESBUF is correctly
89    aligned for a 32 bits value.  */
90 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
91
92
93 /* Compute MD5 message digest for bytes read from STREAM.  The
94    resulting message digest number will be written into the 16 bytes
95    beginning at RESBLOCK.  */
96 extern int md5_stream (FILE *stream, void *resblock);
97
98 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
99    result is always in little endian byte order, so that a byte-wise
100    output yields to the wanted ASCII representation of the message
101    digest.  */
102 extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
103
104 #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
105
106 #endif