| 1 |
/* |
| 2 |
* Declarations of functions and data types used for SHA1 sum |
| 3 |
* library functions. |
| 4 |
* |
| 5 |
* Copyright (C) 2015-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 6 |
* Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2014 Free Software |
| 7 |
* Foundation, Inc. |
| 8 |
* |
| 9 |
* This file is part of Gregorio. |
| 10 |
* This file has been adapted from GNU coreutils to fit Gregorio. |
| 11 |
* |
| 12 |
* Gregorio is free software: you can redistribute it and/or modify |
| 13 |
* it under the terms of the GNU General Public License as published by |
| 14 |
* the Free Software Foundation, either version 3 of the License, or |
| 15 |
* (at your option) any later version. |
| 16 |
* |
| 17 |
* Gregorio is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
* GNU General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU General Public License |
| 23 |
* along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef SHA1_H |
| 27 |
#define SHA1_H 1 |
| 28 |
|
| 29 |
#include <stddef.h> |
| 30 |
#ifdef HAVE_STDINT_H |
| 31 |
#include <stdint.h> |
| 32 |
#else |
| 33 |
#include <inttypes.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
#define SHA1_DIGEST_SIZE 20 |
| 37 |
|
| 38 |
/* Structure to save state of computation between the single steps. */ |
| 39 |
struct sha1_ctx { |
| 40 |
uint32_t A; |
| 41 |
uint32_t B; |
| 42 |
uint32_t C; |
| 43 |
uint32_t D; |
| 44 |
uint32_t E; |
| 45 |
|
| 46 |
uint32_t total[2]; |
| 47 |
uint32_t buflen; |
| 48 |
uint32_t buffer[32]; |
| 49 |
}; |
| 50 |
|
| 51 |
/* Initialize structure containing state of computation. */ |
| 52 |
extern void sha1_init_ctx(struct sha1_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 64!!! */ |
| 58 |
extern void sha1_process_block(const void *buffer, size_t len, |
| 59 |
struct sha1_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 64. */ |
| 65 |
extern void sha1_process_bytes(const void *buffer, size_t len, |
| 66 |
struct sha1_ctx *ctx); |
| 67 |
|
| 68 |
/* Process the remaining bytes in the buffer and put result from CTX |
| 69 |
in first 20 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 *sha1_finish_ctx(struct sha1_ctx *ctx, void *resbuf); |
| 73 |
|
| 74 |
/* Put result from CTX in first 20 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 *sha1_read_ctx(const struct sha1_ctx *ctx, void *resbuf); |
| 78 |
|
| 79 |
/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
| 80 |
result is always in little endian byte order, so that a byte-wise |
| 81 |
output yields to the wanted ASCII representation of the message |
| 82 |
digest. */ |
| 83 |
extern void *sha1_buffer(const char *buffer, size_t len, void *resblock); |
| 84 |
|
| 85 |
#endif |