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