libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-genhash.h
Go to the documentation of this file.
1
/*
2
* libwebsockets - small server side websockets and web server implementation
3
*
4
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
* IN THE SOFTWARE.
23
*/
24
25
#ifndef __LWS_GENHASH_H__
26
#define __LWS_GENHASH_H__
27
38
39
#if defined(LWS_WITH_AWSLC) || defined(LWS_WITH_BORINGSSL)
40
#include <openssl/hmac.h>
41
#endif
42
43
#if defined(LWS_HAVE_MBEDTLS_V4)
44
#include <psa/crypto.h>
45
#endif
46
47
#if defined(LWS_WITH_OPENHITLS)
48
#include <crypt_eal_md.h>
49
#include <crypt_eal_mac.h>
50
#endif
51
52
53
enum
lws_genhash_types
{
54
LWS_GENHASH_TYPE_UNKNOWN
,
55
LWS_GENHASH_TYPE_MD5
,
56
LWS_GENHASH_TYPE_SHA1
,
57
LWS_GENHASH_TYPE_SHA256
,
58
LWS_GENHASH_TYPE_SHA384
,
59
LWS_GENHASH_TYPE_SHA512
,
60
};
61
62
enum
lws_genhmac_types
{
63
LWS_GENHMAC_TYPE_UNKNOWN
,
64
LWS_GENHMAC_TYPE_SHA1
,
65
LWS_GENHMAC_TYPE_SHA256
,
66
LWS_GENHMAC_TYPE_SHA384
,
67
LWS_GENHMAC_TYPE_SHA512
,
68
};
69
70
#define LWS_GENHASH_LARGEST 64
71
72
#if defined(LWS_WITH_TLS) && defined(LWS_WITH_GENCRYPTO)
73
74
struct
lws_genhash_ctx {
75
uint8_t
type;
76
#if defined(LWS_WITH_MBEDTLS)
77
#if defined(LWS_HAVE_MBEDTLS_V4)
78
psa_hash_operation_t hash_ctx;
79
#else
80
union
{
81
mbedtls_md5_context md5;
82
mbedtls_sha1_context sha1;
83
mbedtls_sha256_context sha256;
84
mbedtls_sha512_context sha512;
/* 384 also uses this */
85
const
mbedtls_md_info_t *hmac;
86
} u;
87
#endif
88
#elif defined(LWS_WITH_SCHANNEL)
89
struct
{
90
void
*hAlg;
91
void
*hHash;
92
} u;
93
#elif defined(LWS_WITH_GNUTLS)
94
union
{
95
void
*hash;
/* gnutls_hash_hd_t */
96
} u;
97
#elif defined(LWS_WITH_BEARSSL)
98
union
{
99
br_md5_context md5;
100
br_sha1_context sha1;
101
br_sha256_context sha256;
102
br_sha384_context sha384;
103
br_sha512_context sha512;
104
} u;
105
#elif defined(LWS_WITH_OPENHITLS)
106
CRYPT_EAL_MdCTX *ctx;
107
#else
108
const
EVP_MD *evp_type;
109
EVP_MD_CTX *mdctx;
110
#endif
111
};
112
113
struct
lws_genhmac_ctx {
114
uint8_t
type;
115
#if defined(LWS_WITH_MBEDTLS)
116
#if defined(LWS_HAVE_MBEDTLS_V4)
117
psa_mac_operation_t mac_ctx;
118
psa_key_id_t key_id;
119
#else
120
const
mbedtls_md_info_t *hmac;
121
mbedtls_md_context_t ctx;
122
#endif
123
#elif defined(LWS_WITH_SCHANNEL)
124
struct
{
125
void
*hAlg;
126
void
*hHash;
127
} u;
128
#elif defined(LWS_WITH_GNUTLS)
129
union
{
130
void
*hash;
/* gnutls_hash_hd_t */
131
} u;
132
#elif defined(LWS_WITH_BEARSSL)
133
br_hmac_key_context hmac_key;
134
br_hmac_context ctx;
135
#elif defined(LWS_WITH_OPENHITLS)
136
CRYPT_EAL_MacCtx *ctx;
137
#else
138
const
EVP_MD *evp_type;
139
140
#if defined(LWS_HAVE_EVP_PKEY_new_raw_private_key) && !defined(LWS_WITH_BORINGSSL) && !defined(LWS_WITH_AWSLC)
141
EVP_MD_CTX *ctx;
142
EVP_PKEY *key;
143
#else
144
#if defined(LWS_HAVE_HMAC_CTX_new) || defined(LWS_WITH_BORINGSSL) || defined(LWS_WITH_AWSLC)
145
HMAC_CTX *ctx;
146
#else
147
HMAC_CTX ctx;
148
#endif
149
#endif
150
151
#endif
152
};
153
161
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
162
lws_genhash_size(
enum
lws_genhash_types
type);
163
171
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
172
lws_genhmac_size(
enum
lws_genhmac_types
type);
173
181
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
182
lws_genhash_init(
struct
lws_genhash_ctx *ctx,
enum
lws_genhash_types
type);
183
192
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
193
lws_genhash_update(
struct
lws_genhash_ctx *ctx,
const
void
*in,
size_t
len);
194
206
LWS_VISIBLE
LWS_EXTERN
int
207
lws_genhash_destroy(
struct
lws_genhash_ctx *ctx,
void
*result);
208
221
LWS_VISIBLE
LWS_EXTERN
int
222
lws_genhash_render(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
223
235
LWS_VISIBLE
LWS_EXTERN
int
236
lws_genhash_render_prefixed(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
237
250
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
251
lws_genhmac_init(
struct
lws_genhmac_ctx *ctx,
enum
lws_genhmac_types
type,
252
const
uint8_t
*key,
size_t
key_len);
253
264
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
265
lws_genhmac_update(
struct
lws_genhmac_ctx *ctx,
const
void
*in,
size_t
len);
266
278
LWS_VISIBLE
LWS_EXTERN
int
279
lws_genhmac_destroy(
struct
lws_genhmac_ctx *ctx,
void
*result);
280
293
LWS_VISIBLE
LWS_EXTERN
int
294
lws_genhkdf_extract(
enum
lws_genhmac_types
type,
const
uint8_t
*salt,
295
size_t
salt_len,
const
uint8_t
*ikm,
size_t
ikm_len,
296
uint8_t
*prk);
297
311
LWS_VISIBLE
LWS_EXTERN
int
312
lws_genhkdf_expand(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
313
size_t
prk_len,
const
uint8_t
*info,
size_t
info_len,
314
uint8_t
*okm,
size_t
okm_len);
315
334
LWS_VISIBLE
LWS_EXTERN
int
335
lws_genhkdf_expand_label(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
336
size_t
prk_len,
const
char
*label,
337
const
uint8_t
*context,
size_t
context_len,
338
uint8_t
*okm,
size_t
okm_len);
339
340
#endif
342
343
#endif
/* __LWS_GENHASH_H__ */
lws_genhash_types
lws_genhash_types
Definition
lws-genhash.h:53
lws_genhmac_types
lws_genhmac_types
Definition
lws-genhash.h:62
LWS_GENHASH_TYPE_SHA384
@ LWS_GENHASH_TYPE_SHA384
Definition
lws-genhash.h:58
LWS_GENHASH_TYPE_UNKNOWN
@ LWS_GENHASH_TYPE_UNKNOWN
Definition
lws-genhash.h:54
LWS_GENHASH_TYPE_MD5
@ LWS_GENHASH_TYPE_MD5
Definition
lws-genhash.h:55
LWS_GENHASH_TYPE_SHA1
@ LWS_GENHASH_TYPE_SHA1
Definition
lws-genhash.h:56
LWS_GENHASH_TYPE_SHA512
@ LWS_GENHASH_TYPE_SHA512
Definition
lws-genhash.h:59
LWS_GENHASH_TYPE_SHA256
@ LWS_GENHASH_TYPE_SHA256
Definition
lws-genhash.h:57
LWS_GENHMAC_TYPE_SHA384
@ LWS_GENHMAC_TYPE_SHA384
Definition
lws-genhash.h:66
LWS_GENHMAC_TYPE_SHA1
@ LWS_GENHMAC_TYPE_SHA1
Definition
lws-genhash.h:64
LWS_GENHMAC_TYPE_SHA512
@ LWS_GENHMAC_TYPE_SHA512
Definition
lws-genhash.h:67
LWS_GENHMAC_TYPE_UNKNOWN
@ LWS_GENHMAC_TYPE_UNKNOWN
Definition
lws-genhash.h:63
LWS_GENHMAC_TYPE_SHA256
@ LWS_GENHMAC_TYPE_SHA256
Definition
lws-genhash.h:65
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:715
LWS_WARN_UNUSED_RESULT
#define LWS_WARN_UNUSED_RESULT
Definition
libwebsockets.h:292
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:291
include
libwebsockets
lws-genhash.h
Generated on
for libwebsockets by
1.18.0