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
48
enum
lws_genhash_types
{
49
LWS_GENHASH_TYPE_UNKNOWN
,
50
LWS_GENHASH_TYPE_MD5
,
51
LWS_GENHASH_TYPE_SHA1
,
52
LWS_GENHASH_TYPE_SHA256
,
53
LWS_GENHASH_TYPE_SHA384
,
54
LWS_GENHASH_TYPE_SHA512
,
55
};
56
57
enum
lws_genhmac_types
{
58
LWS_GENHMAC_TYPE_UNKNOWN
,
59
LWS_GENHMAC_TYPE_SHA1
,
60
LWS_GENHMAC_TYPE_SHA256
,
61
LWS_GENHMAC_TYPE_SHA384
,
62
LWS_GENHMAC_TYPE_SHA512
,
63
};
64
65
#define LWS_GENHASH_LARGEST 64
66
67
#if defined(LWS_WITH_TLS) && defined(LWS_WITH_GENCRYPTO)
68
69
struct
lws_genhash_ctx {
70
uint8_t
type;
71
#if defined(LWS_WITH_MBEDTLS)
72
#if defined(LWS_HAVE_MBEDTLS_V4)
73
psa_hash_operation_t hash_ctx;
74
#else
75
union
{
76
mbedtls_md5_context md5;
77
mbedtls_sha1_context sha1;
78
mbedtls_sha256_context sha256;
79
mbedtls_sha512_context sha512;
/* 384 also uses this */
80
const
mbedtls_md_info_t *hmac;
81
} u;
82
#endif
83
#elif defined(LWS_WITH_SCHANNEL)
84
struct
{
85
void
*hAlg;
86
void
*hHash;
87
} u;
88
#elif defined(LWS_WITH_GNUTLS)
89
union
{
90
void
*hash;
/* gnutls_hash_hd_t */
91
} u;
92
#elif defined(LWS_WITH_BEARSSL)
93
union
{
94
br_md5_context md5;
95
br_sha1_context sha1;
96
br_sha256_context sha256;
97
br_sha384_context sha384;
98
br_sha512_context sha512;
99
} u;
100
#else
101
const
EVP_MD *evp_type;
102
EVP_MD_CTX *mdctx;
103
#endif
104
};
105
106
struct
lws_genhmac_ctx {
107
uint8_t
type;
108
#if defined(LWS_WITH_MBEDTLS)
109
#if defined(LWS_HAVE_MBEDTLS_V4)
110
psa_mac_operation_t mac_ctx;
111
psa_key_id_t key_id;
112
#else
113
const
mbedtls_md_info_t *hmac;
114
mbedtls_md_context_t ctx;
115
#endif
116
#elif defined(LWS_WITH_SCHANNEL)
117
struct
{
118
void
*hAlg;
119
void
*hHash;
120
} u;
121
#elif defined(LWS_WITH_GNUTLS)
122
union
{
123
void
*hash;
/* gnutls_hash_hd_t */
124
} u;
125
#elif defined(LWS_WITH_BEARSSL)
126
br_hmac_key_context hmac_key;
127
br_hmac_context ctx;
128
#else
129
const
EVP_MD *evp_type;
130
131
#if defined(LWS_HAVE_EVP_PKEY_new_raw_private_key) && !defined(LWS_WITH_BORINGSSL) && !defined(LWS_WITH_AWSLC)
132
EVP_MD_CTX *ctx;
133
EVP_PKEY *key;
134
#else
135
#if defined(LWS_HAVE_HMAC_CTX_new) || defined(LWS_WITH_BORINGSSL) || defined(LWS_WITH_AWSLC)
136
HMAC_CTX *ctx;
137
#else
138
HMAC_CTX ctx;
139
#endif
140
#endif
141
142
#endif
143
};
144
152
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
153
lws_genhash_size(
enum
lws_genhash_types
type);
154
162
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
163
lws_genhmac_size(
enum
lws_genhmac_types
type);
164
172
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
173
lws_genhash_init(
struct
lws_genhash_ctx *ctx,
enum
lws_genhash_types
type);
174
183
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
184
lws_genhash_update(
struct
lws_genhash_ctx *ctx,
const
void
*in,
size_t
len);
185
197
LWS_VISIBLE
LWS_EXTERN
int
198
lws_genhash_destroy(
struct
lws_genhash_ctx *ctx,
void
*result);
199
212
LWS_VISIBLE
LWS_EXTERN
int
213
lws_genhash_render(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
214
226
LWS_VISIBLE
LWS_EXTERN
int
227
lws_genhash_render_prefixed(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
228
241
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
242
lws_genhmac_init(
struct
lws_genhmac_ctx *ctx,
enum
lws_genhmac_types
type,
243
const
uint8_t
*key,
size_t
key_len);
244
255
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
256
lws_genhmac_update(
struct
lws_genhmac_ctx *ctx,
const
void
*in,
size_t
len);
257
269
LWS_VISIBLE
LWS_EXTERN
int
270
lws_genhmac_destroy(
struct
lws_genhmac_ctx *ctx,
void
*result);
271
284
LWS_VISIBLE
LWS_EXTERN
int
285
lws_genhkdf_extract(
enum
lws_genhmac_types
type,
const
uint8_t
*salt,
286
size_t
salt_len,
const
uint8_t
*ikm,
size_t
ikm_len,
287
uint8_t
*prk);
288
302
LWS_VISIBLE
LWS_EXTERN
int
303
lws_genhkdf_expand(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
304
size_t
prk_len,
const
uint8_t
*info,
size_t
info_len,
305
uint8_t
*okm,
size_t
okm_len);
306
325
LWS_VISIBLE
LWS_EXTERN
int
326
lws_genhkdf_expand_label(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
327
size_t
prk_len,
const
char
*label,
328
const
uint8_t
*context,
size_t
context_len,
329
uint8_t
*okm,
size_t
okm_len);
330
331
#endif
333
334
#endif
/* __LWS_GENHASH_H__ */
lws_genhash_types
lws_genhash_types
Definition
lws-genhash.h:48
lws_genhmac_types
lws_genhmac_types
Definition
lws-genhash.h:57
LWS_GENHASH_TYPE_SHA384
@ LWS_GENHASH_TYPE_SHA384
Definition
lws-genhash.h:53
LWS_GENHASH_TYPE_UNKNOWN
@ LWS_GENHASH_TYPE_UNKNOWN
Definition
lws-genhash.h:49
LWS_GENHASH_TYPE_MD5
@ LWS_GENHASH_TYPE_MD5
Definition
lws-genhash.h:50
LWS_GENHASH_TYPE_SHA1
@ LWS_GENHASH_TYPE_SHA1
Definition
lws-genhash.h:51
LWS_GENHASH_TYPE_SHA512
@ LWS_GENHASH_TYPE_SHA512
Definition
lws-genhash.h:54
LWS_GENHASH_TYPE_SHA256
@ LWS_GENHASH_TYPE_SHA256
Definition
lws-genhash.h:52
LWS_GENHMAC_TYPE_SHA384
@ LWS_GENHMAC_TYPE_SHA384
Definition
lws-genhash.h:61
LWS_GENHMAC_TYPE_SHA1
@ LWS_GENHMAC_TYPE_SHA1
Definition
lws-genhash.h:59
LWS_GENHMAC_TYPE_SHA512
@ LWS_GENHMAC_TYPE_SHA512
Definition
lws-genhash.h:62
LWS_GENHMAC_TYPE_UNKNOWN
@ LWS_GENHMAC_TYPE_UNKNOWN
Definition
lws-genhash.h:58
LWS_GENHMAC_TYPE_SHA256
@ LWS_GENHMAC_TYPE_SHA256
Definition
lws-genhash.h:60
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:706
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