libwebsockets
Lightweight C library for HTML5 websockets
lws-genhash.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
33 
35 enum lws_genhash_types {
36  LWS_GENHASH_TYPE_UNKNOWN,
37  LWS_GENHASH_TYPE_SHA1,
38  LWS_GENHASH_TYPE_SHA256,
39  LWS_GENHASH_TYPE_SHA384,
40  LWS_GENHASH_TYPE_SHA512,
41 };
42 
43 enum lws_genhmac_types {
44  LWS_GENHMAC_TYPE_UNKNOWN,
45  LWS_GENHMAC_TYPE_SHA256,
46  LWS_GENHMAC_TYPE_SHA384,
47  LWS_GENHMAC_TYPE_SHA512,
48 };
49 
50 #define LWS_GENHASH_LARGEST 64
51 
53  uint8_t type;
54 #if defined(LWS_WITH_MBEDTLS)
55  union {
56  mbedtls_sha1_context sha1;
57  mbedtls_sha256_context sha256;
58  mbedtls_sha512_context sha512; /* 384 also uses this */
59  const mbedtls_md_info_t *hmac;
60  } u;
61 #else
62  const EVP_MD *evp_type;
63  EVP_MD_CTX *mdctx;
64 #endif
65 };
66 
68  uint8_t type;
69 #if defined(LWS_WITH_MBEDTLS)
70  const mbedtls_md_info_t *hmac;
71  mbedtls_md_context_t ctx;
72 #else
73  const EVP_MD *evp_type;
74  EVP_MD_CTX *ctx;
75 #endif
76 };
77 
84 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
85 lws_genhash_size(enum lws_genhash_types type);
86 
93 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
94 lws_genhmac_size(enum lws_genhmac_types type);
95 
103 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
104 lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type);
105 
114 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
115 lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len);
116 
128 LWS_VISIBLE LWS_EXTERN int
129 lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result);
130 
143 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
144 lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
145  const uint8_t *key, size_t key_len);
146 
157 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
158 lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len);
159 
171 LWS_VISIBLE LWS_EXTERN int
172 lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result);
LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhmac_size(enum lws_genhmac_types type)
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, const uint8_t *key, size_t key_len)
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len)
Definition: lws-genhash.h:67
LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhash_size(enum lws_genhash_types type)
LWS_VISIBLE LWS_EXTERN int lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result)
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len)
Definition: lws-genhash.h:52
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type)
LWS_VISIBLE LWS_EXTERN int lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result)