libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
class="ui-resizable-handle">
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
44
enum
lws_genhash_types
{
45
LWS_GENHASH_TYPE_UNKNOWN
,
46
LWS_GENHASH_TYPE_MD5
,
47
LWS_GENHASH_TYPE_SHA1
,
48
LWS_GENHASH_TYPE_SHA256
,
49
LWS_GENHASH_TYPE_SHA384
,
50
LWS_GENHASH_TYPE_SHA512
,
51
};
52
53
enum
lws_genhmac_types
{
54
LWS_GENHMAC_TYPE_UNKNOWN
,
55
LWS_GENHMAC_TYPE_SHA1
,
56
LWS_GENHMAC_TYPE_SHA256
,
57
LWS_GENHMAC_TYPE_SHA384
,
58
LWS_GENHMAC_TYPE_SHA512
,
59
};
60
61
#define LWS_GENHASH_LARGEST 64
62
63
#if defined(LWS_WITH_TLS) && defined(LWS_WITH_GENCRYPTO)
64
65
struct
lws_genhash_ctx {
66
uint8_t
type;
67
#if defined(LWS_WITH_MBEDTLS)
68
union
{
69
mbedtls_md5_context md5;
70
mbedtls_sha1_context sha1;
71
mbedtls_sha256_context sha256;
72
mbedtls_sha512_context sha512;
/* 384 also uses this */
73
const
mbedtls_md_info_t *hmac;
74
} u;
75
#elif defined(LWS_WITH_SCHANNEL)
76
struct
{
77
void
*hAlg;
78
void
*hHash;
79
} u;
80
#elif defined(LWS_WITH_GNUTLS)
81
union
{
82
void
*hash;
/* gnutls_hash_hd_t */
83
} u;
84
#elif defined(LWS_WITH_BEARSSL)
85
union
{
86
br_md5_context md5;
87
br_sha1_context sha1;
88
br_sha256_context sha256;
89
br_sha384_context sha384;
90
br_sha512_context sha512;
91
} u;
92
#else
93
const
EVP_MD *evp_type;
94
EVP_MD_CTX *mdctx;
95
#endif
96
};
97
98
struct
lws_genhmac_ctx {
99
uint8_t
type;
100
#if defined(LWS_WITH_MBEDTLS)
101
const
mbedtls_md_info_t *hmac;
102
mbedtls_md_context_t ctx;
103
#elif defined(LWS_WITH_SCHANNEL)
104
struct
{
105
void
*hAlg;
106
void
*hHash;
107
} u;
108
#elif defined(LWS_WITH_GNUTLS)
109
union
{
110
void
*hash;
/* gnutls_hash_hd_t */
111
} u;
112
#elif defined(LWS_WITH_BEARSSL)
113
br_hmac_key_context hmac_key;
114
br_hmac_context ctx;
115
#else
116
const
EVP_MD *evp_type;
117
118
#if defined(LWS_HAVE_EVP_PKEY_new_raw_private_key) && !defined(LWS_WITH_BORINGSSL) && !defined(LWS_WITH_AWSLC)
119
EVP_MD_CTX *ctx;
120
EVP_PKEY *key;
121
#else
122
#if defined(LWS_HAVE_HMAC_CTX_new)
123
HMAC_CTX *ctx;
124
#else
125
HMAC_CTX ctx;
126
#endif
127
#endif
128
129
#endif
130
};
131
139
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
140
lws_genhash_size(
enum
lws_genhash_types
type);
141
149
LWS_VISIBLE
LWS_EXTERN
size_t
LWS_WARN_UNUSED_RESULT
150
lws_genhmac_size(
enum
lws_genhmac_types
type);
151
159
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
160
lws_genhash_init(
struct
lws_genhash_ctx *ctx,
enum
lws_genhash_types
type);
161
170
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
171
lws_genhash_update(
struct
lws_genhash_ctx *ctx,
const
void
*in,
size_t
len);
172
184
LWS_VISIBLE
LWS_EXTERN
int
185
lws_genhash_destroy(
struct
lws_genhash_ctx *ctx,
void
*result);
186
199
LWS_VISIBLE
LWS_EXTERN
int
200
lws_genhash_render(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
201
213
LWS_VISIBLE
LWS_EXTERN
int
214
lws_genhash_render_prefixed(
enum
lws_genhash_types
type,
const
uint8_t
*hash,
char
*out,
size_t
out_len);
215
228
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
229
lws_genhmac_init(
struct
lws_genhmac_ctx *ctx,
enum
lws_genhmac_types
type,
230
const
uint8_t
*key,
size_t
key_len);
231
242
LWS_VISIBLE
LWS_EXTERN
int
LWS_WARN_UNUSED_RESULT
243
lws_genhmac_update(
struct
lws_genhmac_ctx *ctx,
const
void
*in,
size_t
len);
244
256
LWS_VISIBLE
LWS_EXTERN
int
257
lws_genhmac_destroy(
struct
lws_genhmac_ctx *ctx,
void
*result);
258
271
LWS_VISIBLE
LWS_EXTERN
int
272
lws_genhkdf_extract(
enum
lws_genhmac_types
type,
const
uint8_t
*salt,
273
size_t
salt_len,
const
uint8_t
*ikm,
size_t
ikm_len,
274
uint8_t
*prk);
275
289
LWS_VISIBLE
LWS_EXTERN
int
290
lws_genhkdf_expand(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
291
size_t
prk_len,
const
uint8_t
*info,
size_t
info_len,
292
uint8_t
*okm,
size_t
okm_len);
293
312
LWS_VISIBLE
LWS_EXTERN
int
313
lws_genhkdf_expand_label(
enum
lws_genhmac_types
type,
const
uint8_t
*prk,
314
size_t
prk_len,
const
char
*label,
315
const
uint8_t
*context,
size_t
context_len,
316
uint8_t
*okm,
size_t
okm_len);
317
318
#endif
320
321
#endif
/* __LWS_GENHASH_H__ */
lws_genhash_types
lws_genhash_types
Definition
lws-genhash.h:44
lws_genhmac_types
lws_genhmac_types
Definition
lws-genhash.h:53
LWS_GENHASH_TYPE_SHA384
@ LWS_GENHASH_TYPE_SHA384
Definition
lws-genhash.h:49
LWS_GENHASH_TYPE_UNKNOWN
@ LWS_GENHASH_TYPE_UNKNOWN
Definition
lws-genhash.h:45
LWS_GENHASH_TYPE_MD5
@ LWS_GENHASH_TYPE_MD5
Definition
lws-genhash.h:46
LWS_GENHASH_TYPE_SHA1
@ LWS_GENHASH_TYPE_SHA1
Definition
lws-genhash.h:47
LWS_GENHASH_TYPE_SHA512
@ LWS_GENHASH_TYPE_SHA512
Definition
lws-genhash.h:50
LWS_GENHASH_TYPE_SHA256
@ LWS_GENHASH_TYPE_SHA256
Definition
lws-genhash.h:48
LWS_GENHMAC_TYPE_SHA384
@ LWS_GENHMAC_TYPE_SHA384
Definition
lws-genhash.h:57
LWS_GENHMAC_TYPE_SHA1
@ LWS_GENHMAC_TYPE_SHA1
Definition
lws-genhash.h:55
LWS_GENHMAC_TYPE_SHA512
@ LWS_GENHMAC_TYPE_SHA512
Definition
lws-genhash.h:58
LWS_GENHMAC_TYPE_UNKNOWN
@ LWS_GENHMAC_TYPE_UNKNOWN
Definition
lws-genhash.h:54
LWS_GENHMAC_TYPE_SHA256
@ LWS_GENHMAC_TYPE_SHA256
Definition
lws-genhash.h:56
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:697
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