GNU libmicrohttpd
1.0.6
Toggle main menu visibility
Loading...
Searching...
No Matches
sha256_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
26
#include <gnutls/crypto.h>
27
#include "
sha256_ext.h
"
28
#include "
mhd_assert.h
"
29
30
38
void
39
MHD_SHA256_init_one_time
(
struct
Sha256CtxExt
*ctx)
40
{
41
ctx->
handle
=
NULL
;
42
ctx->
ext_error
= gnutls_hash_init (&ctx->
handle
, GNUTLS_DIG_SHA256);
43
if
((0 != ctx->
ext_error
) && (
NULL
!= ctx->
handle
))
44
{
45
/* GnuTLS may return initialisation error and set the handle at the
46
same time. Such handle cannot be used for calculations.
47
Note: GnuTLS may also return an error and NOT set the handle. */
48
gnutls_free (ctx->
handle
);
49
ctx->
handle
=
NULL
;
50
}
51
52
/* If handle is NULL, the error must be set */
53
mhd_assert
((
NULL
!= ctx->
handle
) || (0 != ctx->
ext_error
));
54
/* If error is set, the handle must be NULL */
55
mhd_assert
((0 == ctx->
ext_error
) || (
NULL
== ctx->
handle
));
56
}
57
58
66
void
67
MHD_SHA256_update
(
struct
Sha256CtxExt
*ctx,
68
const
uint8_t *
data
,
69
size_t
length)
70
{
71
if
(0 == ctx->
ext_error
)
72
ctx->
ext_error
= gnutls_hash (ctx->
handle
,
data
, length);
73
}
74
75
82
void
83
MHD_SHA256_finish_reset
(
struct
Sha256CtxExt
*ctx,
84
uint8_t digest[
SHA256_DIGEST_SIZE
])
85
{
86
if
(0 == ctx->
ext_error
)
87
gnutls_hash_output (ctx->
handle
, digest);
88
}
89
90
96
void
97
MHD_SHA256_deinit
(
struct
Sha256CtxExt
*ctx)
98
{
99
if
(
NULL
!= ctx->
handle
)
100
gnutls_hash_deinit (ctx->
handle
,
NULL
);
101
}
mhd_assert.h
macros for mhd_assert()
mhd_assert
#define mhd_assert(ignore)
Definition
mhd_assert.h:45
NULL
#define NULL
Definition
mhd_mono_clock.c:66
MHD_SHA256_deinit
#define MHD_SHA256_deinit(ignore)
Definition
mhd_sha256_wrap.h:90
MHD_SHA256_init_one_time
#define MHD_SHA256_init_one_time(ctx)
Definition
mhd_sha256_wrap.h:71
MHD_SHA256_finish_reset
#define MHD_SHA256_finish_reset(ctx, digest)
Definition
mhd_sha256_wrap.h:82
data
void * data
Definition
microhttpd.h:4030
SHA256_DIGEST_SIZE
#define SHA256_DIGEST_SIZE
Definition
sha256.h:55
MHD_SHA256_update
void MHD_SHA256_update(struct Sha256CtxExt *ctx, const uint8_t *data, size_t length)
Definition
sha256_ext.c:67
sha256_ext.h
Wrapper declarations for SHA-256 calculation performed by TLS library.
Sha256CtxExt
Definition
sha256_ext.h:53
Sha256CtxExt::handle
struct hash_hd_st * handle
Definition
sha256_ext.h:54
Sha256CtxExt::ext_error
int ext_error
Definition
sha256_ext.h:55
src
microhttpd
sha256_ext.c
Generated by
1.17.0