Debian Codegraph @

src/microhttpd/mhd_sha256_wrap.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/mhd_sha256_wrap.h
22 * @brief Simple wrapper for selection of built-in/external SHA-256
23 * implementation
24 * @author Karlson2k (Evgeny Grin)
25 */
26
27 #ifndef MHD_SHA256_WRAP_H
28 #define MHD_SHA256_WRAP_H 1
29
30 #include "mhd_options.h"
31 #include "mhd_options.h"
32 #ifndef MHD_SHA256_SUPPORT
33 #error This file must be used only when SHA-256 is enabled
34 #endif
35 #ifndef MHD_SHA256_TLSLIB
36 #include "sha256.h"
37 #else /* MHD_SHA256_TLSLIB */
38 #include "sha256_ext.h"
39 #endif /* MHD_SHA256_TLSLIB */
40
41 #ifndef SHA256_DIGEST_SIZE
42 /**
43 * Size of SHA-256 resulting digest in bytes
44 * This is the final digest size, not intermediate hash.
45 */
46 #define SHA256_DIGEST_SIZE (32)
47 #endif /* ! SHA256_DIGEST_SIZE */
48
49 #ifndef SHA256_DIGEST_STRING_SIZE
50 /**
51 * Size of MD5 digest string in chars including termination NUL.
52 */
53 #define SHA256_DIGEST_STRING_SIZE ((SHA256_DIGEST_SIZE) * 2 + 1)
54 #endif /* ! SHA256_DIGEST_STRING_SIZE */
55
56 #ifndef MHD_SHA256_TLSLIB
57 /**
58 * Universal ctx type mapped for chosen implementation
59 */
60 #define Sha256CtxWr Sha256Ctx
61 #else /* MHD_SHA256_TLSLIB */
62 /**
63 * Universal ctx type mapped for chosen implementation
64 */
65 #define Sha256CtxWr Sha256CtxExt
66 #endif /* MHD_SHA256_TLSLIB */
67
68 #ifndef MHD_SHA256_HAS_INIT_ONE_TIME
69 /**
70 * Setup and prepare ctx for hash calculation
71 */
72 #define MHD_SHA256_init_one_time(ctx) MHD_SHA256_init(ctx)
73 #endif /* ! MHD_SHA256_HAS_INIT_ONE_TIME */
74
75 #ifndef MHD_SHA256_HAS_FINISH_RESET
76 /**
77 * Re-use the same ctx for the new hashing after digest calculated
78 */
79 #define MHD_SHA256_reset(ctx) MHD_SHA256_init(ctx)
80 /**
81 * Finalise MD5 calculation, return digest, reset hash calculation.
82 */
83 #define MHD_SHA256_finish_reset(ctx,digest) MHD_SHA256_finish(ctx,digest), \
84 MHD_SHA256_reset(ctx)
85
86 #else /* MHD_SHA256_HAS_FINISH_RESET */
87 #define MHD_SHA256_reset(ctx) (void)0
88 #endif /* MHD_SHA256_HAS_FINISH_RESET */
89
90 #ifndef MHD_SHA256_HAS_DEINIT
91 #define MHD_SHA256_deinit(ignore) (void)0
92 #endif /* HAVE_SHA256_DEINIT */
93
94 /* Sanity checks */
95
96 #if ! defined(MHD_SHA256_HAS_FINISH_RESET) && ! defined(MHD_SHA256_HAS_FINISH)
97 #error Required MHD_SHA256_finish_reset() or MHD_SHA256_finish_reset()
98 #endif /* ! MHD_SHA256_HAS_FINISH_RESET && ! MHD_SHA256_HAS_FINISH */
99
100 #endif /* MHD_SHA256_WRAP_H */