xref: /netbsd-src/external/gpl3/gcc.old/dist/include/md5.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
11debfc3dSmrg /* md5.h - Declaration of functions and data types used for MD5 sum
21debfc3dSmrg    computing library functions.
3*8feb0f0bSmrg    Copyright (C) 1995-2020 Free Software Foundation, Inc.
41debfc3dSmrg    NOTE: The canonical source of this file is maintained with the GNU C
51debfc3dSmrg    Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
61debfc3dSmrg 
71debfc3dSmrg    This program is free software; you can redistribute it and/or modify it
81debfc3dSmrg    under the terms of the GNU General Public License as published by the
91debfc3dSmrg    Free Software Foundation; either version 2, or (at your option) any
101debfc3dSmrg    later version.
111debfc3dSmrg 
121debfc3dSmrg    This program is distributed in the hope that it will be useful,
131debfc3dSmrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
141debfc3dSmrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151debfc3dSmrg    GNU General Public License for more details.
161debfc3dSmrg 
171debfc3dSmrg    You should have received a copy of the GNU General Public License
181debfc3dSmrg    along with this program; if not, write to the Free Software Foundation,
191debfc3dSmrg    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
201debfc3dSmrg 
211debfc3dSmrg #ifndef _MD5_H
221debfc3dSmrg #define _MD5_H 1
231debfc3dSmrg 
241debfc3dSmrg #include <stdio.h>
251debfc3dSmrg 
261debfc3dSmrg #if defined HAVE_LIMITS_H || _LIBC
271debfc3dSmrg # include <limits.h>
281debfc3dSmrg #endif
291debfc3dSmrg 
301debfc3dSmrg #include "ansidecl.h"
311debfc3dSmrg 
321debfc3dSmrg /* The following contortions are an attempt to use the C preprocessor
331debfc3dSmrg    to determine an unsigned integral type that is 32 bits wide.  An
341debfc3dSmrg    alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
351debfc3dSmrg    doing that would require that the configure script compile and *run*
361debfc3dSmrg    the resulting executable.  Locally running cross-compiled executables
371debfc3dSmrg    is usually not possible.  */
381debfc3dSmrg 
391debfc3dSmrg #ifdef _LIBC
401debfc3dSmrg # include <sys/types.h>
411debfc3dSmrg typedef u_int32_t md5_uint32;
421debfc3dSmrg typedef uintptr_t md5_uintptr;
431debfc3dSmrg #elif defined (HAVE_SYS_TYPES_H) && defined (HAVE_STDINT_H)
441debfc3dSmrg #include <stdint.h>
451debfc3dSmrg #include <sys/types.h>
461debfc3dSmrg typedef uint32_t md5_uint32;
471debfc3dSmrg typedef uintptr_t md5_uintptr;
481debfc3dSmrg #else
491debfc3dSmrg #  define INT_MAX_32_BITS 2147483647
501debfc3dSmrg 
511debfc3dSmrg /* If UINT_MAX isn't defined, assume it's a 32-bit type.
521debfc3dSmrg    This should be valid for all systems GNU cares about because
531debfc3dSmrg    that doesn't include 16-bit systems, and only modern systems
541debfc3dSmrg    (that certainly have <limits.h>) have 64+-bit integral types.  */
551debfc3dSmrg 
561debfc3dSmrg # ifndef INT_MAX
571debfc3dSmrg #  define INT_MAX INT_MAX_32_BITS
581debfc3dSmrg # endif
591debfc3dSmrg 
601debfc3dSmrg # if INT_MAX == INT_MAX_32_BITS
611debfc3dSmrg    typedef unsigned int md5_uint32;
621debfc3dSmrg # else
631debfc3dSmrg #  if SHRT_MAX == INT_MAX_32_BITS
641debfc3dSmrg     typedef unsigned short md5_uint32;
651debfc3dSmrg #  else
661debfc3dSmrg #   if LONG_MAX == INT_MAX_32_BITS
671debfc3dSmrg      typedef unsigned long md5_uint32;
681debfc3dSmrg #   else
691debfc3dSmrg      /* The following line is intended to evoke an error.
701debfc3dSmrg         Using #error is not portable enough.  */
711debfc3dSmrg      "Cannot determine unsigned 32-bit data type."
721debfc3dSmrg #   endif
731debfc3dSmrg #  endif
741debfc3dSmrg # endif
751debfc3dSmrg /* We have to make a guess about the integer type equivalent in size
761debfc3dSmrg    to pointers which should always be correct.  */
771debfc3dSmrg typedef unsigned long int md5_uintptr;
781debfc3dSmrg #endif
791debfc3dSmrg 
801debfc3dSmrg #ifdef __cplusplus
811debfc3dSmrg extern "C" {
821debfc3dSmrg #endif
831debfc3dSmrg 
841debfc3dSmrg /* Structure to save state of computation between the single steps.  */
851debfc3dSmrg struct md5_ctx
861debfc3dSmrg {
871debfc3dSmrg   md5_uint32 A;
881debfc3dSmrg   md5_uint32 B;
891debfc3dSmrg   md5_uint32 C;
901debfc3dSmrg   md5_uint32 D;
911debfc3dSmrg 
921debfc3dSmrg   md5_uint32 total[2];
931debfc3dSmrg   md5_uint32 buflen;
941debfc3dSmrg   char buffer[128] ATTRIBUTE_ALIGNED_ALIGNOF(md5_uint32);
951debfc3dSmrg };
961debfc3dSmrg 
971debfc3dSmrg /*
981debfc3dSmrg  * The following three functions are build up the low level used in
991debfc3dSmrg  * the functions `md5_stream' and `md5_buffer'.
1001debfc3dSmrg  */
1011debfc3dSmrg 
1021debfc3dSmrg /* Initialize structure containing state of computation.
1031debfc3dSmrg    (RFC 1321, 3.3: Step 3)  */
1041debfc3dSmrg extern void md5_init_ctx (struct md5_ctx *ctx);
1051debfc3dSmrg 
1061debfc3dSmrg /* Starting with the result of former calls of this function (or the
1071debfc3dSmrg    initialization function update the context for the next LEN bytes
1081debfc3dSmrg    starting at BUFFER.
1091debfc3dSmrg    It is necessary that LEN is a multiple of 64!!! */
1101debfc3dSmrg extern void md5_process_block (const void *buffer, size_t len,
1111debfc3dSmrg                                struct md5_ctx *ctx);
1121debfc3dSmrg 
1131debfc3dSmrg /* Starting with the result of former calls of this function (or the
1141debfc3dSmrg    initialization function update the context for the next LEN bytes
1151debfc3dSmrg    starting at BUFFER.
1161debfc3dSmrg    It is NOT required that LEN is a multiple of 64.  */
1171debfc3dSmrg extern void md5_process_bytes (const void *buffer, size_t len,
1181debfc3dSmrg                                struct md5_ctx *ctx);
1191debfc3dSmrg 
1201debfc3dSmrg /* Process the remaining bytes in the buffer and put result from CTX
1211debfc3dSmrg    in first 16 bytes following RESBUF.  The result is always in little
1221debfc3dSmrg    endian byte order, so that a byte-wise output yields to the wanted
1231debfc3dSmrg    ASCII representation of the message digest.
1241debfc3dSmrg 
1251debfc3dSmrg    IMPORTANT: On some systems it is required that RESBUF is correctly
1261debfc3dSmrg    aligned for a 32 bits value.  */
1271debfc3dSmrg extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
1281debfc3dSmrg 
1291debfc3dSmrg 
1301debfc3dSmrg /* Put result from CTX in first 16 bytes following RESBUF.  The result is
1311debfc3dSmrg    always in little endian byte order, so that a byte-wise output yields
1321debfc3dSmrg    to the wanted ASCII representation of the message digest.
1331debfc3dSmrg 
1341debfc3dSmrg    IMPORTANT: On some systems it is required that RESBUF is correctly
1351debfc3dSmrg    aligned for a 32 bits value.  */
1361debfc3dSmrg extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
1371debfc3dSmrg 
1381debfc3dSmrg 
1391debfc3dSmrg /* Compute MD5 message digest for bytes read from STREAM.  The
1401debfc3dSmrg    resulting message digest number will be written into the 16 bytes
1411debfc3dSmrg    beginning at RESBLOCK.  */
1421debfc3dSmrg extern int md5_stream (FILE *stream, void *resblock);
1431debfc3dSmrg 
1441debfc3dSmrg /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
1451debfc3dSmrg    result is always in little endian byte order, so that a byte-wise
1461debfc3dSmrg    output yields to the wanted ASCII representation of the message
1471debfc3dSmrg    digest.  */
1481debfc3dSmrg extern void *md5_buffer (const char *buffer, size_t len, void *resblock);
1491debfc3dSmrg 
1501debfc3dSmrg #ifdef __cplusplus
1511debfc3dSmrg }
1521debfc3dSmrg #endif
1531debfc3dSmrg 
1541debfc3dSmrg #endif
155