summaryrefslogtreecommitdiffstats
path: root/gl/sha256.h
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-03-27 10:34:19 (GMT)
committerGitHub <noreply@github.com>2023-03-27 10:34:19 (GMT)
commitbbc97d57f7f9e0a49fea78c02861c444fe95d46a (patch)
treec8956bbbe9b73e37d261735699a82cccaacea0db /gl/sha256.h
parent917dba07fded8ef04967183a4c0443b5cce2db82 (diff)
parent482aa6c7fe86d7a899e4888d14149f1ccd5401fd (diff)
downloadmonitoring-plugins-bbc97d57f7f9e0a49fea78c02861c444fe95d46a.tar.gz
Merge branch 'master' into dev/check_ssh-patches
Diffstat (limited to 'gl/sha256.h')
-rw-r--r--gl/sha256.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/gl/sha256.h b/gl/sha256.h
new file mode 100644
index 0000000..2879477
--- /dev/null
+++ b/gl/sha256.h
@@ -0,0 +1,121 @@
1/* Declarations of functions and data types used for SHA256 and SHA224 sum
2 library functions.
3 Copyright (C) 2005-2006, 2008-2023 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# if HAVE_OPENSSL_SHA256
25# ifndef OPENSSL_API_COMPAT
26# define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */
27# endif
28# include <openssl/sha.h>
29# endif
30
31# ifdef __cplusplus
32extern "C" {
33# endif
34
35enum { SHA224_DIGEST_SIZE = 224 / 8 };
36enum { SHA256_DIGEST_SIZE = 256 / 8 };
37
38# if HAVE_OPENSSL_SHA256
39# define GL_OPENSSL_NAME 224
40# include "gl_openssl.h"
41# define GL_OPENSSL_NAME 256
42# include "gl_openssl.h"
43# else
44/* Structure to save state of computation between the single steps. */
45struct sha256_ctx
46{
47 uint32_t state[8];
48
49 uint32_t total[2];
50 size_t buflen; /* ≥ 0, ≤ 128 */
51 uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
52};
53
54/* Initialize structure containing state of computation. */
55extern void sha256_init_ctx (struct sha256_ctx *ctx);
56extern void sha224_init_ctx (struct sha256_ctx *ctx);
57
58/* Starting with the result of former calls of this function (or the
59 initialization function update the context for the next LEN bytes
60 starting at BUFFER.
61 It is necessary that LEN is a multiple of 64!!! */
62extern void sha256_process_block (const void *buffer, size_t len,
63 struct sha256_ctx *ctx);
64
65/* Starting with the result of former calls of this function (or the
66 initialization function update the context for the next LEN bytes
67 starting at BUFFER.
68 It is NOT required that LEN is a multiple of 64. */
69extern void sha256_process_bytes (const void *buffer, size_t len,
70 struct sha256_ctx *ctx);
71
72/* Process the remaining bytes in the buffer and put result from CTX
73 in first 32 (28) bytes following RESBUF. The result is always in little
74 endian byte order, so that a byte-wise output yields to the wanted
75 ASCII representation of the message digest. */
76extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
77extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
78
79
80/* Put result from CTX in first 32 (28) bytes following RESBUF. The result is
81 always in little endian byte order, so that a byte-wise output yields
82 to the wanted ASCII representation of the message digest. */
83extern void *sha256_read_ctx (const struct sha256_ctx *ctx,
84 void *restrict resbuf);
85extern void *sha224_read_ctx (const struct sha256_ctx *ctx,
86 void *restrict resbuf);
87
88
89/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER.
90 The result is always in little endian byte order, so that a byte-wise
91 output yields to the wanted ASCII representation of the message
92 digest. */
93extern void *sha256_buffer (const char *buffer, size_t len,
94 void *restrict resblock);
95extern void *sha224_buffer (const char *buffer, size_t len,
96 void *restrict resblock);
97
98# endif
99
100/* Compute SHA256 (SHA224) message digest for bytes read from STREAM.
101 STREAM is an open file stream. Regular files are handled more efficiently.
102 The contents of STREAM from its current position to its end will be read.
103 The case that the last operation on STREAM was an 'ungetc' is not supported.
104 The resulting message digest number will be written into the 32 (28) bytes
105 beginning at RESBLOCK. */
106extern int sha256_stream (FILE *stream, void *resblock);
107extern int sha224_stream (FILE *stream, void *resblock);
108
109
110# ifdef __cplusplus
111}
112# endif
113
114#endif
115
116/*
117 * Hey Emacs!
118 * Local Variables:
119 * coding: utf-8
120 * End:
121 */