"Fossies" - the Fresh Open Source Software Archive

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