Debian Codegraph @

src/microhttpd/mhd_md5_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_md5_wrap.h
22 * @brief Simple wrapper for selection of built-in/external MD5 implementation
23 * @author Karlson2k (Evgeny Grin)
24 */
25
26 #ifndef MHD_MD5_WRAP_H
27 #define MHD_MD5_WRAP_H 1
28
29 #include "mhd_options.h"
30 #ifndef MHD_MD5_SUPPORT
31 #error This file must be used only when MD5 is enabled
32 #endif
33 #ifndef MHD_MD5_TLSLIB
34 #include "md5.h"
35 #else /* MHD_MD5_TLSLIB */
36 #include "md5_ext.h"
37 #endif /* MHD_MD5_TLSLIB */
38
39 #ifndef MD5_DIGEST_SIZE
40 /**
41 * Size of MD5 resulting digest in bytes
42 * This is the final digest size, not intermediate hash.
43 */
44 #define MD5_DIGEST_SIZE (16)
45 #endif /* ! MD5_DIGEST_SIZE */
46
47 #ifndef MD5_DIGEST_STRING_SIZE
48 /**
49 * Size of MD5 digest string in chars including termination NUL.
50 */
51 #define MD5_DIGEST_STRING_SIZE ((MD5_DIGEST_SIZE) * 2 + 1)
52 #endif /* ! MD5_DIGEST_STRING_SIZE */
53
54 #ifndef MHD_MD5_TLSLIB
55 /**
56 * Universal ctx type mapped for chosen implementation
57 */
58 #define Md5CtxWr Md5Ctx
59 #else /* MHD_MD5_TLSLIB */
60 /**
61 * Universal ctx type mapped for chosen implementation
62 */
63 #define Md5CtxWr Md5CtxExt
64 #endif /* MHD_MD5_TLSLIB */
65
66 #ifndef MHD_MD5_HAS_INIT_ONE_TIME
67 /**
68 * Setup and prepare ctx for hash calculation
69 */
70 #define MHD_MD5_init_one_time(ctx) MHD_MD5_init(ctx)
71 #endif /* ! MHD_MD5_HAS_INIT_ONE_TIME */
72
73 #ifndef MHD_MD5_HAS_FINISH_RESET
74 /**
75 * Re-use the same ctx for the new hashing after digest calculated
76 */
77 #define MHD_MD5_reset(ctx) MHD_MD5_init(ctx)
78 /**
79 * Finalise MD5 calculation, return digest, reset hash calculation.
80 */
81 #define MHD_MD5_finish_reset(ctx,digest) MHD_MD5_finish(ctx,digest), \
82 MHD_MD5_reset(ctx)
83
84 #else /* MHD_MD5_HAS_FINISH_RESET */
85 #define MHD_MD5_reset(ctx) (void)0
86 #endif /* MHD_MD5_HAS_FINISH_RESET */
87
88 #ifndef MHD_MD5_HAS_DEINIT
89 #define MHD_MD5_deinit(ignore) (void)0
90 #endif /* HAVE_MD5_DEINIT */
91
92 /* Sanity checks */
93
94 #if ! defined(MHD_MD5_HAS_FINISH_RESET) && ! defined(MHD_MD5_HAS_FINISH)
95 #error Required at least one of MHD_MD5_finish_reset(), MHD_MD5_finish_reset()
96 #endif /* ! MHD_MD5_HAS_FINISH_RESET && ! MHD_MD5_HAS_FINISH */
97
98 #endif /* MHD_MD5_WRAP_H */