libmicrohttpd2

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

sha512_256_ext.h (8278B)


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