Debian Codegraph @

src/microhttpd/sha256_ext.h

raw
1 /*
2 This file is part of GNU libmicrohttpd
3 Copyright (C) 2022 Evgeny Grin (Karlson2k)
4
5 GNU libmicrohttpd is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with GNU libmicrohttpd.
17 If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /**
21 * @file microhttpd/sha256_ext.h
22 * @brief Wrapper declarations for SHA-256 calculation performed by TLS library
23 * @author Karlson2k (Evgeny Grin)
24 */
25
26 #ifndef MHD_SHA256_EXT_H
27 #define MHD_SHA256_EXT_H 1
28
29 #include "mhd_options.h"
30 #include <stdint.h>
31 #ifdef HAVE_STDDEF_H
32 #include <stddef.h> /* for size_t */
33 #endif /* HAVE_STDDEF_H */
34
35 /**
36 * Size of SHA-256 resulting digest in bytes
37 * This is the final digest size, not intermediate hash.
38 */
39 #define SHA256_DIGEST_SIZE (32)
40
41 /* Actual declaration is in GnuTLS lib header */
42 struct hash_hd_st;
43
44 /**
45 * Indicates that struct Sha256CtxExt has 'ext_error'
46 */
47 #define MHD_SHA256_HAS_EXT_ERROR 1
48
49 /**
50 * SHA-256 calculation context
51 */
52 struct Sha256CtxExt
53 {
54 struct hash_hd_st *handle; /**< Hash calculation handle */
55 int ext_error; /**< Non-zero if external error occurs during init or hashing */
56 };
57
58 /**
59 * Indicates that MHD_SHA256_init_one_time() function is present.
60 */
61 #define MHD_SHA256_HAS_INIT_ONE_TIME 1
62
63 /**
64 * Initialise structure for SHA-256 calculation, allocate resources.
65 *
66 * This function must not be called more than one time for @a ctx.
67 *
68 * @param ctx the calculation context
69 */
70 void
71 MHD_SHA256_init_one_time (struct Sha256CtxExt *ctx);
72
73
74 /**
75 * SHA-256 process portion of bytes.
76 *
77 * @param ctx the calculation context
78 * @param data bytes to add to hash
79 * @param length number of bytes in @a data
80 */
81 void
82 MHD_SHA256_update (struct Sha256CtxExt *ctx,
83 const uint8_t *data,
84 size_t length);
85
86
87 /**
88 * Indicates that MHD_SHA256_finish_reset() function is available
89 */
90 #define MHD_SHA256_HAS_FINISH_RESET 1
91
92 /**
93 * Finalise SHA-256 calculation, return digest, reset hash calculation.
94 *
95 * @param ctx the calculation context
96 * @param[out] digest set to the hash, must be #SHA256_DIGEST_SIZE bytes
97 */
98 void
99 MHD_SHA256_finish_reset (struct Sha256CtxExt *ctx,
100 uint8_t digest[SHA256_DIGEST_SIZE]);
101
102 /**
103 * Indicates that MHD_SHA256_deinit() function is present
104 */
105 #define MHD_SHA256_HAS_DEINIT 1
106
107 /**
108 * Free allocated resources.
109 *
110 * @param ctx the calculation context
111 */
112 void
113 MHD_SHA256_deinit (struct Sha256CtxExt *ctx);
114
115 #endif /* MHD_SHA256_EXT_H */