acst

Tracks changes and corruption in files using xattr-based checksums.
git clone https://noxz.tech/git/acst.git
Log | Files | Tags | LICENSE

sha256.h
1/* Declarations of functions and data types used for SHA256 and SHA224 sum
2   library functions.
3   Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
4
5   This file is free software: you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2.1 of the
8   License, or (at your option) any later version.
9
10   This file 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 Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17
18#ifndef SHA256_H
19# define SHA256_H 1
20
21# include <stdio.h>
22# include <stdint.h>
23
24/* Structure to save state of computation between the single steps.  */
25struct SHA256_ctx
26{
27	uint32_t state[8];
28
29	uint32_t total[2];
30	size_t buflen;       /* ≥ 0, ≤ 128 */
31	uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
32};
33
34/*
35  Takes a pointer to a 256 bit block of data (eight 32 bit ints) and
36  initializes it to the start constants of the SHA256 algorithm.  This
37  must be called before using hash in the call to sha256_hash
38*/
39extern void SHA256_init (struct SHA256_ctx *ctx);
40
41/* Starting with the result of former calls of this function (or the
42   initialization function update the context for the next LEN bytes
43   starting at BUFFER.
44   It is necessary that LEN is a multiple of 64!!! */
45extern void SHA256_process_block (const void *buffer, size_t len, struct SHA256_ctx *ctx);
46
47/* Starting with the result of former calls of this function (or the
48   initialization function update the context for the next LEN bytes
49   starting at BUFFER.
50   It is NOT required that LEN is a multiple of 64.  */
51extern void SHA256_update (const void *buffer, size_t len, struct SHA256_ctx *ctx);
52
53/* Process the remaining bytes in the buffer and put result from CTX
54   in first 32 (28) bytes following RESBUF.  The result is always in little
55   endian byte order, so that a byte-wise output yields to the wanted
56   ASCII representation of the message digest.  */
57extern void *SHA256_final (struct SHA256_ctx *ctx, void *restrict resbuf);
58
59
60/* Put result from CTX in first 32 (28) bytes following RESBUF.  The result is
61   always in little endian byte order, so that a byte-wise output yields
62   to the wanted ASCII representation of the message digest.  */
63extern void *SHA256_read_ctx (const struct SHA256_ctx *ctx, void *restrict resbuf);
64
65#endif