GNU libmicrohttpd 1.0.0
Loading...
Searching...
No Matches
md5_ext.c
Go to the documentation of this file.
1/*
2 This file is part of GNU libmicrohttpd
3 Copyright (C) 2022-2023 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
25#include "md5_ext.h"
26#include "mhd_assert.h"
27
28
36void
38{
39 ctx->handle = NULL;
40 ctx->ext_error = gnutls_hash_init (&ctx->handle,
41 GNUTLS_DIG_MD5);
42 if ((0 != ctx->ext_error) && (NULL != ctx->handle))
43 {
44 /* GnuTLS may return initialisation error and set the handle at the
45 same time. Such handle cannot be used for calculations.
46 Note: GnuTLS may also return an error and NOT set the handle. */
47 gnutls_free (ctx->handle);
48 ctx->handle = NULL;
49 }
50
51 /* If handle is NULL, the error must be set */
52 mhd_assert ((NULL != ctx->handle) || (0 != ctx->ext_error));
53 /* If error is set, the handle must be NULL */
54 mhd_assert ((0 == ctx->ext_error) || (NULL == ctx->handle));
55}
56
57
65void
67 const uint8_t *data,
68 size_t length)
69{
70 if (0 == ctx->ext_error)
71 ctx->ext_error = gnutls_hash (ctx->handle, data, length);
72}
73
74
81void
83 uint8_t digest[MD5_DIGEST_SIZE])
84{
85 if (0 == ctx->ext_error)
86 gnutls_hash_output (ctx->handle, digest);
87}
88
89
95void
97{
98 if (NULL != ctx->handle)
99 gnutls_hash_deinit (ctx->handle, NULL);
100}
#define mhd_assert(CHK)
Definition mhd_assert.h:39
#define NULL
#define MD5_DIGEST_SIZE
Definition md5.h:61
void MHD_MD5_update(struct Md5CtxExt *ctx, const uint8_t *data, size_t length)
Definition md5_ext.c:66
Wrapper declarations for MD5 calculation performed by TLS library.
#define MHD_MD5_finish_reset(ctx, digest)
#define MHD_MD5_deinit(ignore)
#define MHD_MD5_init_one_time(ctx)
macros for mhd_assert()
void * data
int ext_error
Definition md5_ext.h:53
struct hash_hd_st * handle
Definition md5_ext.h:52