Blame include/sha1.h

Packit bbfece
/* Declarations of functions and data types used for SHA1 sum
Packit bbfece
   library functions.
Packit bbfece
   Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit bbfece
Packit bbfece
   This program is free software; you can redistribute it and/or modify it
Packit bbfece
   under the terms of the GNU General Public License as published by the
Packit bbfece
   Free Software Foundation; either version 3, or (at your option) any
Packit bbfece
   later version.
Packit bbfece
Packit bbfece
   This program is distributed in the hope that it will be useful,
Packit bbfece
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bbfece
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit bbfece
   GNU General Public License for more details.
Packit bbfece
Packit bbfece
   You should have received a copy of the GNU General Public License
Packit bbfece
   along with this program; if not, write to the Free Software Foundation,
Packit bbfece
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
Packit bbfece
Packit bbfece
#ifndef SHA1_H
Packit bbfece
# define SHA1_H 1
Packit bbfece
Packit bbfece
#include <stdio.h>
Packit bbfece
Packit bbfece
#if defined HAVE_LIMITS_H || _LIBC
Packit bbfece
# include <limits.h>
Packit bbfece
#endif
Packit bbfece
Packit bbfece
#include "ansidecl.h"
Packit bbfece
Packit bbfece
/* The following contortions are an attempt to use the C preprocessor
Packit bbfece
   to determine an unsigned integral type that is 32 bits wide.  An
Packit bbfece
   alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
Packit bbfece
   doing that would require that the configure script compile and *run*
Packit bbfece
   the resulting executable.  Locally running cross-compiled executables
Packit bbfece
   is usually not possible.  */
Packit bbfece
Packit bbfece
#ifdef _LIBC
Packit bbfece
# include <sys/types.h>
Packit bbfece
typedef u_int32_t sha1_uint32;
Packit bbfece
typedef uintptr_t sha1_uintptr;
Packit bbfece
#elif defined (HAVE_SYS_TYPES_H) && defined (HAVE_STDINT_H)
Packit bbfece
#include <stdint.h>
Packit bbfece
#include <sys/types.h>
Packit bbfece
typedef uint32_t sha1_uint32;
Packit bbfece
typedef uintptr_t sha1_uintptr;
Packit bbfece
#else
Packit bbfece
#  define INT_MAX_32_BITS 2147483647
Packit bbfece
Packit bbfece
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
Packit bbfece
   This should be valid for all systems GNU cares about because
Packit bbfece
   that doesn't include 16-bit systems, and only modern systems
Packit bbfece
   (that certainly have <limits.h>) have 64+-bit integral types.  */
Packit bbfece
Packit bbfece
# ifndef INT_MAX
Packit bbfece
#  define INT_MAX INT_MAX_32_BITS
Packit bbfece
# endif
Packit bbfece
Packit bbfece
# if INT_MAX == INT_MAX_32_BITS
Packit bbfece
   typedef unsigned int sha1_uint32;
Packit bbfece
# else
Packit bbfece
#  if SHRT_MAX == INT_MAX_32_BITS
Packit bbfece
    typedef unsigned short sha1_uint32;
Packit bbfece
#  else
Packit bbfece
#   if LONG_MAX == INT_MAX_32_BITS
Packit bbfece
     typedef unsigned long sha1_uint32;
Packit bbfece
#   else
Packit bbfece
     /* The following line is intended to evoke an error.
Packit bbfece
        Using #error is not portable enough.  */
Packit bbfece
     "Cannot determine unsigned 32-bit data type."
Packit bbfece
#   endif
Packit bbfece
#  endif
Packit bbfece
# endif
Packit bbfece
#endif
Packit bbfece
Packit bbfece
#ifdef __cplusplus
Packit bbfece
extern "C" {
Packit bbfece
#endif
Packit bbfece
Packit bbfece
/* Structure to save state of computation between the single steps.  */
Packit bbfece
struct sha1_ctx
Packit bbfece
{
Packit bbfece
  sha1_uint32 A;
Packit bbfece
  sha1_uint32 B;
Packit bbfece
  sha1_uint32 C;
Packit bbfece
  sha1_uint32 D;
Packit bbfece
  sha1_uint32 E;
Packit bbfece
Packit bbfece
  sha1_uint32 total[2];
Packit bbfece
  sha1_uint32 buflen;
Packit bbfece
  sha1_uint32 buffer[32];
Packit bbfece
};
Packit bbfece
Packit bbfece
Packit bbfece
/* Initialize structure containing state of computation. */
Packit bbfece
extern void sha1_init_ctx (struct sha1_ctx *ctx);
Packit bbfece
Packit bbfece
/* Starting with the result of former calls of this function (or the
Packit bbfece
   initialization function update the context for the next LEN bytes
Packit bbfece
   starting at BUFFER.
Packit bbfece
   It is necessary that LEN is a multiple of 64!!! */
Packit bbfece
extern void sha1_process_block (const void *buffer, size_t len,
Packit bbfece
				struct sha1_ctx *ctx);
Packit bbfece
Packit bbfece
/* Starting with the result of former calls of this function (or the
Packit bbfece
   initialization function update the context for the next LEN bytes
Packit bbfece
   starting at BUFFER.
Packit bbfece
   It is NOT required that LEN is a multiple of 64.  */
Packit bbfece
extern void sha1_process_bytes (const void *buffer, size_t len,
Packit bbfece
				struct sha1_ctx *ctx);
Packit bbfece
Packit bbfece
/* Process the remaining bytes in the buffer and put result from CTX
Packit bbfece
   in first 20 bytes following RESBUF.  The result is always in little
Packit bbfece
   endian byte order, so that a byte-wise output yields to the wanted
Packit bbfece
   ASCII representation of the message digest.
Packit bbfece
Packit bbfece
   IMPORTANT: On some systems it is required that RESBUF be correctly
Packit bbfece
   aligned for a 32 bits value.  */
Packit bbfece
extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
Packit bbfece
Packit bbfece
Packit bbfece
/* Put result from CTX in first 20 bytes following RESBUF.  The result is
Packit bbfece
   always in little endian byte order, so that a byte-wise output yields
Packit bbfece
   to the wanted ASCII representation of the message digest.
Packit bbfece
Packit bbfece
   IMPORTANT: On some systems it is required that RESBUF is correctly
Packit bbfece
   aligned for a 32 bits value.  */
Packit bbfece
extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
Packit bbfece
Packit bbfece
Packit bbfece
/* Compute SHA1 message digest for bytes read from STREAM.  The
Packit bbfece
   resulting message digest number will be written into the 20 bytes
Packit bbfece
   beginning at RESBLOCK.  */
Packit bbfece
extern int sha1_stream (FILE *stream, void *resblock);
Packit bbfece
Packit bbfece
/* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
Packit bbfece
   result is always in little endian byte order, so that a byte-wise
Packit bbfece
   output yields to the wanted ASCII representation of the message
Packit bbfece
   digest.  */
Packit bbfece
extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
Packit bbfece
Packit bbfece
#ifdef __cplusplus
Packit bbfece
}
Packit bbfece
#endif
Packit bbfece
Packit bbfece
#endif