root/lib/sha1.h

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

INCLUDED FROM


     1 /* Declarations of functions and data types used for SHA1 sum
     2    library functions.
     3    Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2023 Free Software
     4    Foundation, Inc.
     5 
     6    This file is free software: you can redistribute it and/or modify
     7    it under the terms of the GNU Lesser General Public License as
     8    published by the Free Software Foundation; either version 2.1 of the
     9    License, or (at your option) any later version.
    10 
    11    This file is distributed in the hope that it will be useful,
    12    but WITHOUT ANY WARRANTY; without even the implied warranty of
    13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14    GNU Lesser General Public License for more details.
    15 
    16    You should have received a copy of the GNU Lesser General Public License
    17    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
    18 
    19 #ifndef SHA1_H
    20 # define SHA1_H 1
    21 
    22 /* This file uses HAVE_OPENSSL_SHA1.  */
    23 # if !_GL_CONFIG_H_INCLUDED
    24 #  error "Please include config.h first."
    25 # endif
    26 
    27 # include <stdio.h>
    28 # include <stdint.h>
    29 
    30 # if HAVE_OPENSSL_SHA1
    31 #  ifndef OPENSSL_API_COMPAT
    32 #   define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API.  */
    33 #  endif
    34 #  include <openssl/sha.h>
    35 # endif
    36 
    37 # ifdef __cplusplus
    38 extern "C" {
    39 # endif
    40 
    41 # define SHA1_DIGEST_SIZE 20
    42 
    43 # if HAVE_OPENSSL_SHA1
    44 #  define GL_OPENSSL_NAME 1
    45 #  include "gl_openssl.h"
    46 # else
    47 /* Structure to save state of computation between the single steps.  */
    48 struct sha1_ctx
    49 {
    50   uint32_t A;
    51   uint32_t B;
    52   uint32_t C;
    53   uint32_t D;
    54   uint32_t E;
    55 
    56   uint32_t total[2];
    57   uint32_t buflen;     /* ≥ 0, ≤ 128 */
    58   uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
    59 };
    60 
    61 /* Initialize structure containing state of computation. */
    62 extern void sha1_init_ctx (struct sha1_ctx *ctx);
    63 
    64 /* Starting with the result of former calls of this function (or the
    65    initialization function update the context for the next LEN bytes
    66    starting at BUFFER.
    67    It is necessary that LEN is a multiple of 64!!! */
    68 extern void sha1_process_block (const void *buffer, size_t len,
    69                                 struct sha1_ctx *ctx);
    70 
    71 /* Starting with the result of former calls of this function (or the
    72    initialization function update the context for the next LEN bytes
    73    starting at BUFFER.
    74    It is NOT required that LEN is a multiple of 64.  */
    75 extern void sha1_process_bytes (const void *buffer, size_t len,
    76                                 struct sha1_ctx *ctx);
    77 
    78 /* Process the remaining bytes in the buffer and put result from CTX
    79    in first 20 bytes following RESBUF.  The result is always in little
    80    endian byte order, so that a byte-wise output yields to the wanted
    81    ASCII representation of the message digest.  */
    82 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf);
    83 
    84 
    85 /* Put result from CTX in first 20 bytes following RESBUF.  The result is
    86    always in little endian byte order, so that a byte-wise output yields
    87    to the wanted ASCII representation of the message digest.  */
    88 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf);
    89 
    90 
    91 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
    92    result is always in little endian byte order, so that a byte-wise
    93    output yields to the wanted ASCII representation of the message
    94    digest.  */
    95 extern void *sha1_buffer (const char *buffer, size_t len,
    96                           void *restrict resblock);
    97 
    98 # endif
    99 
   100 /* Compute SHA1 message digest for bytes read from STREAM.
   101    STREAM is an open file stream.  Regular files are handled more efficiently.
   102    The contents of STREAM from its current position to its end will be read.
   103    The case that the last operation on STREAM was an 'ungetc' is not supported.
   104    The resulting message digest number will be written into the 20 bytes
   105    beginning at RESBLOCK.  */
   106 extern int sha1_stream (FILE *stream, void *resblock);
   107 
   108 
   109 # ifdef __cplusplus
   110 }
   111 # endif
   112 
   113 #endif
   114 
   115 /*
   116  * Hey Emacs!
   117  * Local Variables:
   118  * coding: utf-8
   119  * End:
   120  */

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