libwebsockets
Lightweight C library for HTML5 websockets
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
52
60
61#define LWS_GENHASH_LARGEST 64
62
63#if defined(LWS_WITH_TLS) && defined(LWS_WITH_GENCRYPTO)
64
65struct 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#else
85 const EVP_MD *evp_type;
86 EVP_MD_CTX *mdctx;
87#endif
88};
89
90struct lws_genhmac_ctx {
91 uint8_t type;
92#if defined(LWS_WITH_MBEDTLS)
93 const mbedtls_md_info_t *hmac;
94 mbedtls_md_context_t ctx;
95#elif defined(LWS_WITH_SCHANNEL)
96 struct {
97 void *hAlg;
98 void *hHash;
99 } u;
100#elif defined(LWS_WITH_GNUTLS)
101 union {
102 void *hash; /* gnutls_hash_hd_t */
103 } u;
104#else
105 const EVP_MD *evp_type;
106
107#if !defined(LWS_WITH_BORINGSSL) &&\
108 defined(LWS_HAVE_EVP_PKEY_new_raw_private_key)
109 EVP_MD_CTX *ctx;
110 EVP_PKEY *key;
111#else
112#if defined(LWS_HAVE_HMAC_CTX_new)
113 HMAC_CTX *ctx;
114#else
115 HMAC_CTX ctx;
116#endif
117#endif
118
119#endif
120};
121
130lws_genhash_size(enum lws_genhash_types type);
131
140lws_genhmac_size(enum lws_genhmac_types type);
141
150lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type);
151
161lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len);
162
175lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result);
176
190lws_genhash_render(enum lws_genhash_types type, const uint8_t *hash, char *out, size_t out_len);
191
204lws_genhash_render_prefixed(enum lws_genhash_types type, const uint8_t *hash, char *out, size_t out_len);
205
219lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
220 const uint8_t *key, size_t key_len);
221
233lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len);
234
247lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result);
248
249#endif
251
252#endif /* __LWS_GENHASH_H__ */
lws_genhash_types
Definition lws-genhash.h:44
lws_genhmac_types
Definition lws-genhash.h:53
@ LWS_GENHASH_TYPE_SHA384
Definition lws-genhash.h:49
@ LWS_GENHASH_TYPE_UNKNOWN
Definition lws-genhash.h:45
@ LWS_GENHASH_TYPE_MD5
Definition lws-genhash.h:46
@ LWS_GENHASH_TYPE_SHA1
Definition lws-genhash.h:47
@ LWS_GENHASH_TYPE_SHA512
Definition lws-genhash.h:50
@ LWS_GENHASH_TYPE_SHA256
Definition lws-genhash.h:48
@ LWS_GENHMAC_TYPE_SHA384
Definition lws-genhash.h:57
@ LWS_GENHMAC_TYPE_SHA1
Definition lws-genhash.h:55
@ LWS_GENHMAC_TYPE_SHA512
Definition lws-genhash.h:58
@ LWS_GENHMAC_TYPE_UNKNOWN
Definition lws-genhash.h:54
@ LWS_GENHMAC_TYPE_SHA256
Definition lws-genhash.h:56
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_WARN_UNUSED_RESULT
#define LWS_VISIBLE