Blame common/md5.h

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