root/lib/md5.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


     1 /* Declaration of functions and data types used for MD5 sum computing
     2    library functions.
     3    Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2023 Free Software
     4    Foundation, Inc.
     5    This file is part of the GNU C Library.
     6 
     7    This file is free software: you can redistribute it and/or modify
     8    it under the terms of the GNU Lesser General Public License as
     9    published by the Free Software Foundation; either version 2.1 of the
    10    License, or (at your option) any later version.
    11 
    12    This file is distributed in the hope that it will be useful,
    13    but WITHOUT ANY WARRANTY; without even the implied warranty of
    14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15    GNU Lesser General Public License for more details.
    16 
    17    You should have received a copy of the GNU Lesser General Public License
    18    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 #ifndef _MD5_H
    21 #define _MD5_H 1
    22 
    23 /* This file uses HAVE_OPENSSL_MD5.  */
    24 #if !_GL_CONFIG_H_INCLUDED
    25  #error "Please include config.h first."
    26 #endif
    27 
    28 #include <stdio.h>
    29 #include <stdint.h>
    30 
    31 # if HAVE_OPENSSL_MD5
    32 #  ifndef OPENSSL_API_COMPAT
    33 #   define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API.  */
    34 #  endif
    35 #  include <openssl/md5.h>
    36 # endif
    37 
    38 #define MD5_DIGEST_SIZE 16
    39 #define MD5_BLOCK_SIZE 64
    40 
    41 #ifndef __GNUC_PREREQ
    42 # if defined __GNUC__ && defined __GNUC_MINOR__
    43 #  define __GNUC_PREREQ(maj, min)                                       \
    44   ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
    45 # else
    46 #  define __GNUC_PREREQ(maj, min) 0
    47 # endif
    48 #endif
    49 
    50 #ifndef __THROW
    51 # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
    52 #  define __THROW       throw ()
    53 # else
    54 #  define __THROW
    55 # endif
    56 #endif
    57 
    58 #ifndef _LIBC
    59 # define __md5_buffer md5_buffer
    60 # define __md5_finish_ctx md5_finish_ctx
    61 # define __md5_init_ctx md5_init_ctx
    62 # define __md5_process_block md5_process_block
    63 # define __md5_process_bytes md5_process_bytes
    64 # define __md5_read_ctx md5_read_ctx
    65 # define __md5_stream md5_stream
    66 #endif
    67 
    68 # ifdef __cplusplus
    69 extern "C" {
    70 # endif
    71 
    72 # if HAVE_OPENSSL_MD5
    73 #  define GL_OPENSSL_NAME 5
    74 #  include "gl_openssl.h"
    75 # else
    76 /* Structure to save state of computation between the single steps.  */
    77 struct md5_ctx
    78 {
    79   uint32_t A;
    80   uint32_t B;
    81   uint32_t C;
    82   uint32_t D;
    83 
    84   uint32_t total[2];
    85   uint32_t buflen;     /* ≥ 0, ≤ 128 */
    86   uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
    87 };
    88 
    89 /*
    90  * The following three functions are build up the low level used in
    91  * the functions 'md5_stream' and 'md5_buffer'.
    92  */
    93 
    94 /* Initialize structure containing state of computation.
    95    (RFC 1321, 3.3: Step 3)  */
    96 extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW;
    97 
    98 /* Starting with the result of former calls of this function (or the
    99    initialization function update the context for the next LEN bytes
   100    starting at BUFFER.
   101    It is necessary that LEN is a multiple of 64!!! */
   102 extern void __md5_process_block (const void *buffer, size_t len,
   103                                  struct md5_ctx *ctx) __THROW;
   104 
   105 /* Starting with the result of former calls of this function (or the
   106    initialization function update the context for the next LEN bytes
   107    starting at BUFFER.
   108    It is NOT required that LEN is a multiple of 64.  */
   109 extern void __md5_process_bytes (const void *buffer, size_t len,
   110                                  struct md5_ctx *ctx) __THROW;
   111 
   112 /* Process the remaining bytes in the buffer and put result from CTX
   113    in first 16 bytes following RESBUF.  The result is always in little
   114    endian byte order, so that a byte-wise output yields to the wanted
   115    ASCII representation of the message digest.  */
   116 extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *restrict resbuf)
   117      __THROW;
   118 
   119 
   120 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
   121    always in little endian byte order, so that a byte-wise output yields
   122    to the wanted ASCII representation of the message digest.  */
   123 extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *restrict resbuf)
   124      __THROW;
   125 
   126 
   127 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
   128    result is always in little endian byte order, so that a byte-wise
   129    output yields to the wanted ASCII representation of the message
   130    digest.  */
   131 extern void *__md5_buffer (const char *buffer, size_t len,
   132                            void *restrict resblock) __THROW;
   133 
   134 # endif
   135 
   136 /* Compute MD5 message digest for bytes read from STREAM.
   137    STREAM is an open file stream.  Regular files are handled more efficiently.
   138    The contents of STREAM from its current position to its end will be read.
   139    The case that the last operation on STREAM was an 'ungetc' is not supported.
   140    The resulting message digest number will be written into the 16 bytes
   141    beginning at RESBLOCK.  */
   142 extern int __md5_stream (FILE *stream, void *resblock) __THROW;
   143 
   144 
   145 # ifdef __cplusplus
   146 }
   147 # endif
   148 
   149 #endif /* md5.h */
   150 
   151 /*
   152  * Hey Emacs!
   153  * Local Variables:
   154  * coding: utf-8
   155  * End:
   156  */

/* [<][>][^][v][top][bottom][index][help] */