"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.5/littleutils/sha512.h" (29 Oct 2021, 4133 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 "sha512.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 SHA512 and SHA384 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 SHA512_H
   21 #define SHA512_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 # include "u64.h"
   36 
   37 enum { SHA384_DIGEST_SIZE = 384 / 8 };
   38 enum { SHA512_DIGEST_SIZE = 512 / 8 };
   39 
   40 /* Structure to save state of computation between the single steps.  */
   41 struct sha512_ctx
   42 {
   43   u64 state[8];
   44 
   45   u64 total[2];
   46   size_t buflen;  /* ≥ 0, ≤ 256 */
   47   u64 buffer[32]; /* 256 bytes; the first buflen bytes are in use */
   48 };
   49 
   50 /* Initialize structure containing state of computation. */
   51 extern void sha512_init_ctx (struct sha512_ctx *ctx);
   52 extern void sha384_init_ctx (struct sha512_ctx *ctx);
   53 
   54 /* Starting with the result of former calls of this function (or the
   55    initialization function update the context for the next LEN bytes
   56    starting at BUFFER.
   57    It is necessary that LEN is a multiple of 128!!! */
   58 extern void sha512_process_block (const void *buffer, size_t len,
   59                                   struct sha512_ctx *ctx);
   60 
   61 /* Starting with the result of former calls of this function (or the
   62    initialization function update the context for the next LEN bytes
   63    starting at BUFFER.
   64    It is NOT required that LEN is a multiple of 128.  */
   65 extern void sha512_process_bytes (const void *buffer, size_t len,
   66                                   struct sha512_ctx *ctx);
   67 
   68 /* Process the remaining bytes in the buffer and put result from CTX
   69    in first 64 (48) bytes following RESBUF.  The result is always in little
   70    endian byte order, so that a byte-wise output yields to the wanted
   71    ASCII representation of the message digest.  */
   72 extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
   73 extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
   74 
   75 
   76 /* Put result from CTX in first 64 (48) bytes following RESBUF.  The result is
   77    always in little endian byte order, so that a byte-wise output yields
   78    to the wanted ASCII representation of the message digest.
   79 
   80    IMPORTANT: On some systems it is required that RESBUF is correctly
   81    aligned for a 32 bits value.  */
   82 extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
   83 extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
   84 
   85 
   86 /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER.  The
   87    result is always in little endian byte order, so that a byte-wise
   88    output yields to the wanted ASCII representation of the message
   89    digest.  */
   90 extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
   91 extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
   92 
   93 
   94 /* Compute SHA512 (SHA384) message digest for bytes read from STREAM.
   95    STREAM is an open file stream.  Regular files are handled more efficiently.
   96    The contents of STREAM from its current position to its end will be read.
   97    The case that the last operation on STREAM was an 'ungetc' is not supported.
   98    The resulting message digest number will be written into the 64 (48) bytes
   99    beginning at RESBLOCK.  */
  100 extern int sha512_stream (FILE *stream, void *resblock, off_t readbytes);
  101 extern int sha384_stream (FILE *stream, void *resblock, off_t readbytes);
  102 
  103 
  104 #endif