]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/md5.h
Fix division by zero in loop splitting
[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.
83ffe9cd 3 Copyright (C) 1995-2023 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
44d9d55c
GP
24#ifdef USE_SYSTEM_MD5
25#include_next <md5.h>
26#else
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;
162b4e41
KT
47#elif defined (HAVE_SYS_TYPES_H) && defined (HAVE_STDINT_H)
48#include <stdint.h>
49#include <sys/types.h>
50typedef uint32_t md5_uint32;
51typedef uintptr_t md5_uintptr;
881c6935 52#else
84802b13 53# define INT_MAX_32_BITS 2147483647
881c6935
JM
54
55/* If UINT_MAX isn't defined, assume it's a 32-bit type.
56 This should be valid for all systems GNU cares about because
57 that doesn't include 16-bit systems, and only modern systems
58 (that certainly have <limits.h>) have 64+-bit integral types. */
59
84802b13
JDA
60# ifndef INT_MAX
61# define INT_MAX INT_MAX_32_BITS
881c6935
JM
62# endif
63
84802b13 64# if INT_MAX == INT_MAX_32_BITS
881c6935
JM
65 typedef unsigned int md5_uint32;
66# else
84802b13 67# if SHRT_MAX == INT_MAX_32_BITS
881c6935
JM
68 typedef unsigned short md5_uint32;
69# else
84802b13 70# if LONG_MAX == INT_MAX_32_BITS
881c6935
JM
71 typedef unsigned long md5_uint32;
72# else
73 /* The following line is intended to evoke an error.
74 Using #error is not portable enough. */
75 "Cannot determine unsigned 32-bit data type."
76# endif
77# endif
78# endif
3fe725de
SE
79/* We have to make a guess about the integer type equivalent in size
80 to pointers which should always be correct. */
81typedef unsigned long int md5_uintptr;
881c6935
JM
82#endif
83
8e291ddf
ILT
84#ifdef __cplusplus
85extern "C" {
86#endif
87
881c6935
JM
88/* Structure to save state of computation between the single steps. */
89struct md5_ctx
90{
91 md5_uint32 A;
92 md5_uint32 B;
93 md5_uint32 C;
94 md5_uint32 D;
95
96 md5_uint32 total[2];
97 md5_uint32 buflen;
3fe725de 98 char buffer[128] ATTRIBUTE_ALIGNED_ALIGNOF(md5_uint32);
881c6935
JM
99};
100
101/*
102 * The following three functions are build up the low level used in
103 * the functions `md5_stream' and `md5_buffer'.
104 */
105
106/* Initialize structure containing state of computation.
107 (RFC 1321, 3.3: Step 3) */
6da879de 108extern void md5_init_ctx (struct md5_ctx *ctx);
881c6935
JM
109
110/* Starting with the result of former calls of this function (or the
111 initialization function update the context for the next LEN bytes
112 starting at BUFFER.
113 It is necessary that LEN is a multiple of 64!!! */
6da879de
GDR
114extern void md5_process_block (const void *buffer, size_t len,
115 struct md5_ctx *ctx);
881c6935
JM
116
117/* Starting with the result of former calls of this function (or the
118 initialization function update the context for the next LEN bytes
119 starting at BUFFER.
120 It is NOT required that LEN is a multiple of 64. */
6da879de
GDR
121extern void md5_process_bytes (const void *buffer, size_t len,
122 struct md5_ctx *ctx);
881c6935
JM
123
124/* Process the remaining bytes in the buffer and put result from CTX
125 in first 16 bytes following RESBUF. The result is always in little
126 endian byte order, so that a byte-wise output yields to the wanted
127 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_finish_ctx (struct md5_ctx *ctx, void *resbuf);
881c6935
JM
132
133
134/* Put result from CTX in first 16 bytes following RESBUF. The result is
135 always in little endian byte order, so that a byte-wise output yields
136 to the wanted ASCII representation of the message digest.
137
138 IMPORTANT: On some systems it is required that RESBUF is correctly
139 aligned for a 32 bits value. */
6da879de 140extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
881c6935
JM
141
142
143/* Compute MD5 message digest for bytes read from STREAM. The
144 resulting message digest number will be written into the 16 bytes
145 beginning at RESBLOCK. */
6da879de 146extern int md5_stream (FILE *stream, void *resblock);
881c6935
JM
147
148/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
149 result is always in little endian byte order, so that a byte-wise
150 output yields to the wanted ASCII representation of the message
151 digest. */
6da879de 152extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
881c6935 153
9bb28c1b
ILT
154#ifdef __cplusplus
155}
156#endif
157
44d9d55c
GP
158#endif // USE_SYSTEM_MD5
159
881c6935 160#endif