]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/md5.h
Daily bump.
[thirdparty/gcc.git] / include / md5.h
CommitLineData
881c6935
JM
1/* md5.h - Declaration of functions and data types used for MD5 sum
2 computing library functions.
01f537ab 3 Copyright 1995, 1996, 2000 Free Software Foundation, Inc.
881c6935
JM
4 NOTE: The canonical source of this file is maintained with the GNU C
5 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
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, write to the Free Software Foundation,
d6d47ea0 19 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
881c6935
JM
20
21#ifndef _MD5_H
22#define _MD5_H 1
23
9bb28c1b
ILT
24#ifdef __cplusplus
25extern "C" {
26#endif
27
881c6935
JM
28#include <stdio.h>
29
30#if defined HAVE_LIMITS_H || _LIBC
31# include <limits.h>
32#endif
33
78e97e7f
DD
34#include "ansidecl.h"
35
881c6935
JM
36/* The following contortions are an attempt to use the C preprocessor
37 to determine an unsigned integral type that is 32 bits wide. An
38 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
39 doing that would require that the configure script compile and *run*
40 the resulting executable. Locally running cross-compiled executables
41 is usually not possible. */
42
43#ifdef _LIBC
44# include <sys/types.h>
45typedef u_int32_t md5_uint32;
3fe725de 46typedef uintptr_t md5_uintptr;
881c6935 47#else
84802b13 48# define INT_MAX_32_BITS 2147483647
881c6935
JM
49
50/* If UINT_MAX isn't defined, assume it's a 32-bit type.
51 This should be valid for all systems GNU cares about because
52 that doesn't include 16-bit systems, and only modern systems
53 (that certainly have <limits.h>) have 64+-bit integral types. */
54
84802b13
JDA
55# ifndef INT_MAX
56# define INT_MAX INT_MAX_32_BITS
881c6935
JM
57# endif
58
84802b13 59# if INT_MAX == INT_MAX_32_BITS
881c6935
JM
60 typedef unsigned int md5_uint32;
61# else
84802b13 62# if SHRT_MAX == INT_MAX_32_BITS
881c6935
JM
63 typedef unsigned short md5_uint32;
64# else
84802b13 65# if LONG_MAX == INT_MAX_32_BITS
881c6935
JM
66 typedef unsigned long md5_uint32;
67# else
68 /* The following line is intended to evoke an error.
69 Using #error is not portable enough. */
70 "Cannot determine unsigned 32-bit data type."
71# endif
72# endif
73# endif
3fe725de
SE
74/* We have to make a guess about the integer type equivalent in size
75 to pointers which should always be correct. */
76typedef unsigned long int md5_uintptr;
881c6935
JM
77#endif
78
881c6935
JM
79/* Structure to save state of computation between the single steps. */
80struct md5_ctx
81{
82 md5_uint32 A;
83 md5_uint32 B;
84 md5_uint32 C;
85 md5_uint32 D;
86
87 md5_uint32 total[2];
88 md5_uint32 buflen;
3fe725de 89 char buffer[128] ATTRIBUTE_ALIGNED_ALIGNOF(md5_uint32);
881c6935
JM
90};
91
92/*
93 * The following three functions are build up the low level used in
94 * the functions `md5_stream' and `md5_buffer'.
95 */
96
97/* Initialize structure containing state of computation.
98 (RFC 1321, 3.3: Step 3) */
6da879de 99extern void md5_init_ctx (struct md5_ctx *ctx);
881c6935
JM
100
101/* Starting with the result of former calls of this function (or the
102 initialization function update the context for the next LEN bytes
103 starting at BUFFER.
104 It is necessary that LEN is a multiple of 64!!! */
6da879de
GDR
105extern void md5_process_block (const void *buffer, size_t len,
106 struct md5_ctx *ctx);
881c6935
JM
107
108/* Starting with the result of former calls of this function (or the
109 initialization function update the context for the next LEN bytes
110 starting at BUFFER.
111 It is NOT required that LEN is a multiple of 64. */
6da879de
GDR
112extern void md5_process_bytes (const void *buffer, size_t len,
113 struct md5_ctx *ctx);
881c6935
JM
114
115/* Process the remaining bytes in the buffer and put result from CTX
116 in first 16 bytes following RESBUF. The result is always in little
117 endian byte order, so that a byte-wise output yields to the wanted
118 ASCII representation of the message digest.
119
120 IMPORTANT: On some systems it is required that RESBUF is correctly
121 aligned for a 32 bits value. */
6da879de 122extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
881c6935
JM
123
124
125/* Put result from CTX in first 16 bytes following RESBUF. The result is
126 always in little endian byte order, so that a byte-wise output yields
127 to the wanted ASCII representation of the message digest.
128
129 IMPORTANT: On some systems it is required that RESBUF is correctly
130 aligned for a 32 bits value. */
6da879de 131extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
881c6935
JM
132
133
134/* Compute MD5 message digest for bytes read from STREAM. The
135 resulting message digest number will be written into the 16 bytes
136 beginning at RESBLOCK. */
6da879de 137extern int md5_stream (FILE *stream, void *resblock);
881c6935
JM
138
139/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
140 result is always in little endian byte order, so that a byte-wise
141 output yields to the wanted ASCII representation of the message
142 digest. */
6da879de 143extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
881c6935 144
9bb28c1b
ILT
145#ifdef __cplusplus
146}
147#endif
148
881c6935 149#endif