Blame crypt/md5.h

Packit 6c4009
/* Declaration of functions and data types used for MD5 sum computing
Packit 6c4009
   library functions.
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _MD5_H
Packit 6c4009
#define _MD5_H 1
Packit 6c4009
Packit 6c4009
#include <stdio.h>
Packit 6c4009
Packit 6c4009
#if defined HAVE_LIMITS_H || defined _LIBC
Packit 6c4009
# include <limits.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#define MD5_DIGEST_SIZE 16
Packit 6c4009
#define MD5_BLOCK_SIZE 64
Packit 6c4009
Packit 6c4009
/* The following contortions are an attempt to use the C preprocessor
Packit 6c4009
   to determine an unsigned integral type that is 32 bits wide.  An
Packit 6c4009
   alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
Packit 6c4009
   doing that would require that the configure script compile and *run*
Packit 6c4009
   the resulting executable.  Locally running cross-compiled executables
Packit 6c4009
   is usually not possible.  */
Packit 6c4009
Packit 6c4009
#ifdef _LIBC
Packit 6c4009
# include <stdint.h>
Packit 6c4009
typedef uint32_t md5_uint32;
Packit 6c4009
typedef uintptr_t md5_uintptr;
Packit 6c4009
#else
Packit 6c4009
# define UINT_MAX_32_BITS 4294967295U
Packit 6c4009
Packit 6c4009
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
Packit 6c4009
   This should be valid for all systems GNU cares about because
Packit 6c4009
   that doesn't include 16-bit systems, and only modern systems
Packit 6c4009
   (that certainly have <limits.h>) have 64+-bit integral types.  */
Packit 6c4009
Packit 6c4009
# ifndef UINT_MAX
Packit 6c4009
#  define UINT_MAX UINT_MAX_32_BITS
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# if UINT_MAX == UINT_MAX_32_BITS
Packit 6c4009
   typedef unsigned int md5_uint32;
Packit 6c4009
# else
Packit 6c4009
#  if USHRT_MAX == UINT_MAX_32_BITS
Packit 6c4009
    typedef unsigned short md5_uint32;
Packit 6c4009
#  else
Packit 6c4009
#   if ULONG_MAX == UINT_MAX_32_BITS
Packit 6c4009
     typedef unsigned long md5_uint32;
Packit 6c4009
#   else
Packit 6c4009
     /* The following line is intended to evoke an error.
Packit 6c4009
	Using #error is not portable enough.  */
Packit 6c4009
     "Cannot determine unsigned 32-bit data type."
Packit 6c4009
#   endif
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
/* We have to make a guess about the integer type equivalent in size
Packit 6c4009
   to pointers which should always be correct.  */
Packit 6c4009
typedef unsigned long int md5_uintptr;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Structure to save state of computation between the single steps.  */
Packit 6c4009
struct md5_ctx
Packit 6c4009
{
Packit 6c4009
  md5_uint32 A;
Packit 6c4009
  md5_uint32 B;
Packit 6c4009
  md5_uint32 C;
Packit 6c4009
  md5_uint32 D;
Packit 6c4009
Packit 6c4009
  md5_uint32 total[2];
Packit 6c4009
  md5_uint32 buflen;
Packit 6c4009
  union
Packit 6c4009
  {
Packit 6c4009
    char buffer[128];
Packit 6c4009
    md5_uint32 buffer32[32];
Packit 6c4009
  };
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * The following three functions are build up the low level used in
Packit 6c4009
 * the functions `md5_stream' and `md5_buffer'.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/* Initialize structure containing state of computation.
Packit 6c4009
   (RFC 1321, 3.3: Step 3)  */
Packit 6c4009
extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW;
Packit 6c4009
Packit 6c4009
/* Starting with the result of former calls of this function (or the
Packit 6c4009
   initialization function update the context for the next LEN bytes
Packit 6c4009
   starting at BUFFER.
Packit 6c4009
   It is necessary that LEN is a multiple of 64!!! */
Packit 6c4009
extern void __md5_process_block (const void *buffer, size_t len,
Packit 6c4009
				 struct md5_ctx *ctx) __THROW;
Packit 6c4009
Packit 6c4009
/* Starting with the result of former calls of this function (or the
Packit 6c4009
   initialization function update the context for the next LEN bytes
Packit 6c4009
   starting at BUFFER.
Packit 6c4009
   It is NOT required that LEN is a multiple of 64.  */
Packit 6c4009
extern void __md5_process_bytes (const void *buffer, size_t len,
Packit 6c4009
				 struct md5_ctx *ctx) __THROW;
Packit 6c4009
Packit 6c4009
/* Process the remaining bytes in the buffer and put result from CTX
Packit 6c4009
   in first 16 bytes following RESBUF.  The result is always in little
Packit 6c4009
   endian byte order, so that a byte-wise output yields to the wanted
Packit 6c4009
   ASCII representation of the message digest.
Packit 6c4009
Packit 6c4009
   IMPORTANT: On some systems it is required that RESBUF is correctly
Packit 6c4009
   aligned for a 32 bits value.  */
Packit 6c4009
extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Put result from CTX in first 16 bytes following RESBUF.  The result is
Packit 6c4009
   always in little endian byte order, so that a byte-wise output yields
Packit 6c4009
   to the wanted ASCII representation of the message digest.
Packit 6c4009
Packit 6c4009
   IMPORTANT: On some systems it is required that RESBUF is correctly
Packit 6c4009
   aligned for a 32 bits value.  */
Packit 6c4009
extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Compute MD5 message digest for bytes read from STREAM.  The
Packit 6c4009
   resulting message digest number will be written into the 16 bytes
Packit 6c4009
   beginning at RESBLOCK.  */
Packit 6c4009
extern int __md5_stream (FILE *stream, void *resblock) __THROW;
Packit 6c4009
Packit 6c4009
/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
Packit 6c4009
   result is always in little endian byte order, so that a byte-wise
Packit 6c4009
   output yields to the wanted ASCII representation of the message
Packit 6c4009
   digest.  */
Packit 6c4009
extern void *__md5_buffer (const char *buffer, size_t len,
Packit 6c4009
			   void *resblock) __THROW;
Packit 6c4009
Packit 6c4009
#endif /* md5.h */