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