libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 92f63e8bf9987e2089b7a2ecc7a403d8f37d63c4
parent f6cd1b743c4a2aed9c236eb2b3f27cc7c5e41626
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 23 Nov 2025 12:02:01 +0100

address FIXMEs

Diffstat:
Msrc/mhd2/sha256_ext.h | 135++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/mhd2/sha256_ext_gnutls.c | 6+-----
Msrc/mhd2/sha256_ext_mbedtls.c | 3+--
Msrc/mhd2/sha256_ext_openssl.c | 3+--
Msrc/mhd2/sha512_256_int.h | 2+-
5 files changed, 138 insertions(+), 11 deletions(-)

diff --git a/src/mhd2/sha256_ext.h b/src/mhd2/sha256_ext.h @@ -93,7 +93,140 @@ mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx); * SHA-256 process portion of bytes. * * @param ctx the calculation context - * @param size number of bytes in @a data + * @param size number of bytes in @a data, must not be 0 + * @param data bytes to add to hash + */ +void +mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, + size_t size, + const uint8_t *data); + + +/** + * Indicates that mhd_SHA256_finish_reset() function is available + */ +#define mhd_SHA256_HAS_FINISH_RESET 1 + +/** + * Finalise SHA-256 calculation, return digest, reset hash calculation. + * + * @param ctx the calculation context + * @param[out] digest set to the hash, must be #mhd_SHA256_DIGEST_SIZE bytes + */ +void +mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, + uint8_t digest[mhd_SHA256_DIGEST_SIZE]); + +/** + * Indicates that mhd_SHA256_deinit() function is present + */ +#define mhd_SHA256_HAS_DEINIT 1 + +/** + * Free allocated resources. + * + * @param ctx the calculation context + */ +void +mhd_SHA256_deinit (struct mhd_Sha256CtxExt *ctx); + +#endif /* MHD_SHA256_EXT_H */ +/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ +/* + This file is part of GNU libmicrohttpd. + Copyright (C) 2022 Evgeny Grin (Karlson2k) + + GNU libmicrohttpd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + GNU libmicrohttpd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + Alternatively, you can redistribute GNU libmicrohttpd and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version, together + with the eCos exception, as follows: + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile this + file and link it with other works to produce a work based on this + file, this file does not by itself cause the resulting work to be + covered by the GNU General Public License. However the source code + for this file must still be made available in accordance with + section (3) of the GNU General Public License v2. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + + You should have received copies of the GNU Lesser General Public + License and the GNU General Public License along with this library; + if not, see <https://www.gnu.org/licenses/>. +*/ + +/** + * @file microhttpd/sha256_ext.h + * @brief Wrapper declarations for SHA-256 calculation performed by TLS library + * @author Karlson2k (Evgeny Grin) + */ + +#ifndef MHD_SHA256_EXT_H +#define MHD_SHA256_EXT_H 1 + +#include "mhd_sys_options.h" +#include <stdint.h> +#include "sys_sizet_type.h" + +/** + * Size of SHA-256 resulting digest in bytes + * This is the final digest size, not intermediate hash. + */ +#define mhd_SHA256_DIGEST_SIZE (32) + +#ifndef MHD_SHA256_Context +#define MHD_SHA256_Context void +#endif + +/** + * Indicates that struct mhd_Sha256CtxExt has 'ext_error' + */ +#define mhd_SHA256_HAS_EXT_ERROR 1 + +/** + * SHA-256 calculation context + */ +struct mhd_Sha256CtxExt +{ + MHD_SHA256_Context *handle; /**< Hash calculation handle */ + int ext_error; /**< Non-zero if external error occurs during init or hashing */ +}; + +/** + * Indicates that mhd_SHA256_init_one_time() function is present. + */ +#define mhd_SHA256_HAS_INIT_ONE_TIME 1 + +/** + * Initialise structure for SHA-256 calculation, allocate resources. + * + * This function must not be called more than one time for @a ctx. + * + * @param ctx the calculation context + */ +void +mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx); + + +/** + * SHA-256 process portion of bytes. + * + * @param ctx the calculation context + * @param size number of bytes in @a data, must not be 0 * @param data bytes to add to hash */ void diff --git a/src/mhd2/sha256_ext_gnutls.c b/src/mhd2/sha256_ext_gnutls.c @@ -81,15 +81,14 @@ mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx) * Process portion of bytes. * * @param ctx the calculation context + * @param size number of bytes in @a data, must not be 0 * @param data bytes to add to hash - * @param length number of bytes in @a data */ void mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, size_t size, const uint8_t *data) { - // FIXME-EG: I think that size == 0 should be allowed here. -CG mhd_assert (0 != size); if (0 == ctx->ext_error) @@ -109,9 +108,6 @@ void mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, uint8_t digest[mhd_SHA256_DIGEST_SIZE]) { - // FIXME-EG: do we need the 'reset' part of the logic? - // Not all implementations include reset, may result in extra - // work, see OpenSSL & mbedTLS! -CG if (0 == ctx->ext_error) gnutls_hash_output (ctx->handle, digest); diff --git a/src/mhd2/sha256_ext_mbedtls.c b/src/mhd2/sha256_ext_mbedtls.c @@ -86,15 +86,14 @@ mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx) * Process portion of bytes. * * @param ctx the calculation context + * @param size number of bytes in @a data, must not be 0 * @param data bytes to add to hash - * @param length number of bytes in @a data */ void mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, size_t size, const uint8_t *data) { - // FIXME-EG: I think that size == 0 should be allowed here. -CG mhd_assert (0 != size); if (0 == ctx->ext_error) diff --git a/src/mhd2/sha256_ext_openssl.c b/src/mhd2/sha256_ext_openssl.c @@ -84,15 +84,14 @@ mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx) * Process portion of bytes. * * @param ctx the calculation context + * @param size number of bytes in @a data, must not be 0 * @param data bytes to add to hash - * @param length number of bytes in @a data */ void mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, size_t size, const uint8_t *data) { - // FIXME-EG: I think that size == 0 should be allowed here. -CG mhd_assert (0 != size); if (0 == ctx->ext_error) diff --git a/src/mhd2/sha512_256_int.h b/src/mhd2/sha512_256_int.h @@ -128,7 +128,7 @@ MHD_FN_PAR_NONNULL_ALL_; * Process portion of bytes. * * @param ctx the calculation context - * @param size number of bytes in @a data + * @param size number of bytes in @a data, must not be 0 * @param data bytes to add to hash */ MHD_INTERNAL void