mhd_sha512_256.h (4703B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2022-2024 Evgeny Grin (Karlson2k) 5 6 GNU libmicrohttpd is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 GNU libmicrohttpd is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 Alternatively, you can redistribute GNU libmicrohttpd and/or 17 modify it under the terms of the GNU General Public License as 18 published by the Free Software Foundation; either version 2 of 19 the License, or (at your option) any later version, together 20 with the eCos exception, as follows: 21 22 As a special exception, if other files instantiate templates or 23 use macros or inline functions from this file, or you compile this 24 file and link it with other works to produce a work based on this 25 file, this file does not by itself cause the resulting work to be 26 covered by the GNU General Public License. However the source code 27 for this file must still be made available in accordance with 28 section (3) of the GNU General Public License v2. 29 30 This exception does not invalidate any other reasons why a work 31 based on this file might be covered by the GNU General Public 32 License. 33 34 You should have received copies of the GNU Lesser General Public 35 License and the GNU General Public License along with this library; 36 if not, see <https://www.gnu.org/licenses/>. 37 */ 38 39 /** 40 * @file src/mhd2/mhd_sha512_256.h 41 * @brief Simple wrapper for selection of built-in/external SHA-512/256 42 * implementation 43 * @author Karlson2k (Evgeny Grin) 44 */ 45 46 #ifndef MHD_SHA512_256_H 47 #define MHD_SHA512_256_H 1 48 49 #include "mhd_sys_options.h" 50 51 #ifndef MHD_SUPPORT_SHA512_256 52 #error This file must be used only when SHA-512/256 is enabled 53 #endif 54 #ifndef MHD_SHA512_256_EXTR 55 # include "sha512_256_int.h" 56 #else /* MHD_SHA512_256_EXTR */ 57 # include "sha512_256_ext.h" 58 #endif /* MHD_SHA512_256_EXTR */ 59 60 #ifndef mhd_SHA512_256_DIGEST_SIZE 61 /** 62 * Size of SHA-512/256 resulting digest in bytes 63 * This is the final digest size, not intermediate hash. 64 */ 65 # define mhd_SHA512_256_DIGEST_SIZE (32) 66 #endif /* ! mhd_SHA512_256_DIGEST_SIZE */ 67 68 #ifndef MHD_SHA512_256_EXTR 69 /** 70 * Universal ctx type mapped for chosen implementation 71 */ 72 # define mhd_Sha512_256Ctx mhd_Sha512_256CtxInt 73 #else /* MHD_SHA512_256_EXTR */ 74 /** 75 * Universal ctx type mapped for chosen implementation 76 */ 77 # define mhd_Sha512_256Ctx mhd_Sha512_256CtxExt 78 #endif /* MHD_SHA512_256_EXTR */ 79 80 #ifndef mhd_SHA512_256_HAS_INIT_ONE_TIME 81 /** 82 * Setup and prepare ctx for hash calculation 83 */ 84 # define mhd_SHA512_256_init_one_time(ctx) mhd_SHA512_256_init (ctx) 85 #endif /* ! mhd_SHA512_256_HAS_INIT_ONE_TIME */ 86 87 #ifndef mhd_SHA512_256_HAS_DEINIT 88 # define mhd_SHA512_256_deinit(ctx) ((void) 0) 89 #endif /* HAVE_SHA512_256_DEINIT */ 90 91 #ifndef mhd_SHA512_256_HAS_FINISH_RESET 92 /** 93 * Re-use the same ctx for the new hashing after digest calculated 94 */ 95 # define mhd_SHA512_256_reset(ctx) mhd_SHA512_256_init (ctx) 96 /** 97 * Finalise hash calculation, return digest, reset hash calculation. 98 */ 99 # define mhd_SHA512_256_finish_reset(ctx,digest) \ 100 (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_reset (ctx)) 101 /** 102 * Finalise hash calculation, return digest, de-initialise hash calculation. 103 */ 104 # define mhd_SHA512_256_finish_deinit(ctx,digest) \ 105 (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_deinit (ctx)) 106 #else /* mhd_SHA512_256_HAS_FINISH_RESET */ 107 # define mhd_SHA512_256_reset(ctx) ((void) 0) 108 /** 109 * Finalise hash calculation, return digest, de-initialise hash calculation. 110 */ 111 # define mhd_SHA512_256_finish_deinit(ctx,digest) \ 112 (mhd_SHA512_256_finish_reset (ctx,digest), mhd_SHA512_256_deinit (ctx)) 113 #endif /* mhd_SHA512_256_HAS_FINISH_RESET */ 114 115 /* Sanity checks */ 116 117 #if ! defined(mhd_SHA512_256_HAS_FINISH_RESET) && \ 118 ! defined(mhd_SHA512_256_HAS_FINISH) 119 #error Required mhd_SHA512_256_finish_reset() or mhd_SHA512_256_finish() 120 #endif /* ! mhd_SHA512_256_HAS_FINISH_RESET && ! mhd_SHA512_256_HAS_FINISH */ 121 122 #ifdef mhd_SHA512_256_HAS_EXT_ERROR 123 #define mhd_SHA512_256_has_err(ctx) (0 != ((ctx)->ext_error)) 124 #else /* ! mhd_SHA512_256_HAS_EXT_ERROR */ 125 #define mhd_SHA512_256_has_err(ctx) (((void) (ctx)), ! ! 0) 126 #endif /* ! mhd_SHA512_256_HAS_EXT_ERROR */ 127 128 #endif /* MHD_SHA512_256_H */