"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.5/littleutils/sha1.h" (29 Oct 2021, 3598 Bytes) of package /linux/privat/littleutils-1.2.5.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sha1.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.4_vs_1.2.5.

    1 /* Declarations of functions and data types used for SHA1 sum
    2    library functions.
    3    Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2018 Free Software
    4    Foundation, Inc.
    5 
    6    This program is free software; you can redistribute it and/or modify it
    7    under the terms of the GNU General Public License as published by the
    8    Free Software Foundation; either version 3, or (at your option) any
    9    later version.
   10 
   11    This program 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 General Public License for more details.
   15 
   16    You should have received a copy of the GNU General Public License
   17    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
   18 
   19 /* Modifications for partial file reads by Brian Lindholm, 2004-2021.  */
   20 
   21 
   22 #ifndef SHA1_H
   23 #define SHA1_H 1
   24 
   25 #include <config.h>
   26 
   27 #if HAVE_INTTYPES_H
   28 # include <inttypes.h>
   29 #endif
   30 #if HAVE_STDINT_H || _LIBC
   31 # include <stdint.h>
   32 #endif
   33 #ifdef HAVE_STDIO_H
   34 # include <stdio.h>
   35 #endif
   36 
   37 #define SHA1_DIGEST_SIZE 20
   38 
   39 /* Structure to save state of computation between the single steps.  */
   40 struct sha1_ctx
   41 {
   42   uint32_t A;
   43   uint32_t B;
   44   uint32_t C;
   45   uint32_t D;
   46   uint32_t E;
   47 
   48   uint32_t total[2];
   49   uint32_t buflen;     /* ≥ 0, ≤ 128 */
   50   uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
   51 };
   52 
   53 /* Initialize structure containing state of computation. */
   54 extern void sha1_init_ctx (struct sha1_ctx *ctx);
   55 
   56 /* Starting with the result of former calls of this function (or the
   57    initialization function update the context for the next LEN bytes
   58    starting at BUFFER.
   59    It is necessary that LEN is a multiple of 64!!! */
   60 extern void sha1_process_block (const void *buffer, size_t len,
   61                                 struct sha1_ctx *ctx);
   62 
   63 /* Starting with the result of former calls of this function (or the
   64    initialization function update the context for the next LEN bytes
   65    starting at BUFFER.
   66    It is NOT required that LEN is a multiple of 64.  */
   67 extern void sha1_process_bytes (const void *buffer, size_t len,
   68                                 struct sha1_ctx *ctx);
   69 
   70 /* Process the remaining bytes in the buffer and put result from CTX
   71    in first 20 bytes following RESBUF.  The result is always in little
   72    endian byte order, so that a byte-wise output yields to the wanted
   73    ASCII representation of the message digest.  */
   74 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
   75 
   76 
   77 /* Put result from CTX in first 20 bytes following RESBUF.  The result is
   78    always in little endian byte order, so that a byte-wise output yields
   79    to the wanted ASCII representation of the message digest.  */
   80 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
   81 
   82 
   83 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
   84    result is always in little endian byte order, so that a byte-wise
   85    output yields to the wanted ASCII representation of the message
   86    digest.  */
   87 extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
   88 
   89 
   90 /* Compute SHA1 message digest for bytes read from STREAM.
   91    STREAM is an open file stream.  Regular files are handled more efficiently.
   92    The contents of STREAM from its current position to its end will be read.
   93    The case that the last operation on STREAM was an 'ungetc' is not supported.
   94    The resulting message digest number will be written into the 20 bytes
   95    beginning at RESBLOCK.  */
   96 extern int sha1_stream (FILE *stream, void *resblock, off_t readbytes);
   97 
   98 
   99 #endif