sha256_ext.h (8067B)
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 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 microhttpd/sha256_ext.h 41 * @brief Wrapper declarations for SHA-256 calculation performed by TLS library 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_SHA256_EXT_H 46 #define MHD_SHA256_EXT_H 1 47 48 #include "mhd_sys_options.h" 49 #include <stdint.h> 50 #include "sys_sizet_type.h" 51 52 /** 53 * Size of SHA-256 resulting digest in bytes 54 * This is the final digest size, not intermediate hash. 55 */ 56 #define mhd_SHA256_DIGEST_SIZE (32) 57 58 #ifndef MHD_SHA256_Context 59 #define MHD_SHA256_Context void 60 #endif 61 62 /** 63 * Indicates that struct mhd_Sha256CtxExt has 'ext_error' 64 */ 65 #define mhd_SHA256_HAS_EXT_ERROR 1 66 67 #ifndef MHD_SHA256_Context 68 #define MHD_SHA256_Context void 69 #endif 70 71 /** 72 * SHA-256 calculation context 73 */ 74 struct mhd_Sha256CtxExt 75 { 76 MHD_SHA256_Context *handle; /**< Hash calculation handle */ 77 int ext_error; /**< Non-zero if external error occurs during init or hashing */ 78 }; 79 80 /** 81 * Indicates that mhd_SHA256_init_one_time() function is present. 82 */ 83 #define mhd_SHA256_HAS_INIT_ONE_TIME 1 84 85 /** 86 * Initialise structure for SHA-256 calculation, allocate resources. 87 * 88 * This function must not be called more than one time for @a ctx. 89 * 90 * @param ctx the calculation context 91 */ 92 void 93 mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx); 94 95 96 /** 97 * SHA-256 process portion of bytes. 98 * 99 * @param ctx the calculation context 100 * @param size number of bytes in @a data, must not be 0 101 * @param data bytes to add to hash 102 */ 103 void 104 mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, 105 size_t size, 106 const uint8_t *data); 107 108 109 /** 110 * Indicates that mhd_SHA256_finish_reset() function is available 111 */ 112 #define mhd_SHA256_HAS_FINISH_RESET 1 113 114 /** 115 * Finalise SHA-256 calculation, return digest, reset hash calculation. 116 * 117 * @param ctx the calculation context 118 * @param[out] digest set to the hash, must be #mhd_SHA256_DIGEST_SIZE bytes 119 */ 120 void 121 mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, 122 uint8_t digest[mhd_SHA256_DIGEST_SIZE]); 123 124 /** 125 * Indicates that mhd_SHA256_deinit() function is present 126 */ 127 #define mhd_SHA256_HAS_DEINIT 1 128 129 /** 130 * Free allocated resources. 131 * 132 * @param ctx the calculation context 133 */ 134 void 135 mhd_SHA256_deinit (struct mhd_Sha256CtxExt *ctx); 136 137 #endif /* MHD_SHA256_EXT_H */ 138 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 139 /* 140 This file is part of GNU libmicrohttpd. 141 Copyright (C) 2022 Evgeny Grin (Karlson2k) 142 143 GNU libmicrohttpd is free software; you can redistribute it and/or 144 modify it under the terms of the GNU Lesser General Public 145 License as published by the Free Software Foundation; either 146 version 2.1 of the License, or (at your option) any later version. 147 148 GNU libmicrohttpd is distributed in the hope that it will be useful, 149 but WITHOUT ANY WARRANTY; without even the implied warranty of 150 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 151 Lesser General Public License for more details. 152 153 Alternatively, you can redistribute GNU libmicrohttpd and/or 154 modify it under the terms of the GNU General Public License as 155 published by the Free Software Foundation; either version 2 of 156 the License, or (at your option) any later version, together 157 with the eCos exception, as follows: 158 159 As a special exception, if other files instantiate templates or 160 use macros or inline functions from this file, or you compile this 161 file and link it with other works to produce a work based on this 162 file, this file does not by itself cause the resulting work to be 163 covered by the GNU General Public License. However the source code 164 for this file must still be made available in accordance with 165 section (3) of the GNU General Public License v2. 166 167 This exception does not invalidate any other reasons why a work 168 based on this file might be covered by the GNU General Public 169 License. 170 171 You should have received copies of the GNU Lesser General Public 172 License and the GNU General Public License along with this library; 173 if not, see <https://www.gnu.org/licenses/>. 174 */ 175 176 /** 177 * @file microhttpd/sha256_ext.h 178 * @brief Wrapper declarations for SHA-256 calculation performed by TLS library 179 * @author Karlson2k (Evgeny Grin) 180 */ 181 182 #ifndef MHD_SHA256_EXT_H 183 #define MHD_SHA256_EXT_H 1 184 185 #include "mhd_sys_options.h" 186 #include <stdint.h> 187 #include "sys_sizet_type.h" 188 189 /** 190 * Size of SHA-256 resulting digest in bytes 191 * This is the final digest size, not intermediate hash. 192 */ 193 #define mhd_SHA256_DIGEST_SIZE (32) 194 195 #ifndef MHD_SHA256_Context 196 #define MHD_SHA256_Context void 197 #endif 198 199 /** 200 * Indicates that struct mhd_Sha256CtxExt has 'ext_error' 201 */ 202 #define mhd_SHA256_HAS_EXT_ERROR 1 203 204 /** 205 * SHA-256 calculation context 206 */ 207 struct mhd_Sha256CtxExt 208 { 209 MHD_SHA256_Context *handle; /**< Hash calculation handle */ 210 int ext_error; /**< Non-zero if external error occurs during init or hashing */ 211 }; 212 213 /** 214 * Indicates that mhd_SHA256_init_one_time() function is present. 215 */ 216 #define mhd_SHA256_HAS_INIT_ONE_TIME 1 217 218 /** 219 * Initialise structure for SHA-256 calculation, allocate resources. 220 * 221 * This function must not be called more than one time for @a ctx. 222 * 223 * @param ctx the calculation context 224 */ 225 void 226 mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx); 227 228 229 /** 230 * SHA-256 process portion of bytes. 231 * 232 * @param ctx the calculation context 233 * @param size number of bytes in @a data, must not be 0 234 * @param data bytes to add to hash 235 */ 236 void 237 mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, 238 size_t size, 239 const uint8_t *data); 240 241 242 /** 243 * Indicates that mhd_SHA256_finish_reset() function is available 244 */ 245 #define mhd_SHA256_HAS_FINISH_RESET 1 246 247 /** 248 * Finalise SHA-256 calculation, return digest, reset hash calculation. 249 * 250 * @param ctx the calculation context 251 * @param[out] digest set to the hash, must be #mhd_SHA256_DIGEST_SIZE bytes 252 */ 253 void 254 mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, 255 uint8_t digest[mhd_SHA256_DIGEST_SIZE]); 256 257 /** 258 * Indicates that mhd_SHA256_deinit() function is present 259 */ 260 #define mhd_SHA256_HAS_DEINIT 1 261 262 /** 263 * Free allocated resources. 264 * 265 * @param ctx the calculation context 266 */ 267 void 268 mhd_SHA256_deinit (struct mhd_Sha256CtxExt *ctx); 269 270 #endif /* MHD_SHA256_EXT_H */