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_SHA1,
37  LWS_GENHASH_TYPE_SHA256,
38  LWS_GENHASH_TYPE_SHA384,
39  LWS_GENHASH_TYPE_SHA512,
40 };
41 
42 enum lws_genhmac_types {
43  LWS_GENHMAC_TYPE_SHA256,
44  LWS_GENHMAC_TYPE_SHA384,
45  LWS_GENHMAC_TYPE_SHA512,
46 };
47 
48 #define LWS_GENHASH_LARGEST 64
49 
51  uint8_t type;
52 #if defined(LWS_WITH_MBEDTLS)
53  union {
54  mbedtls_sha1_context sha1;
55  mbedtls_sha256_context sha256;
56  mbedtls_sha512_context sha512; /* 384 also uses this */
57  const mbedtls_md_info_t *hmac;
58  } u;
59 #else
60  const EVP_MD *evp_type;
61  EVP_MD_CTX *mdctx;
62 #endif
63 };
64 
66  uint8_t type;
67 #if defined(LWS_WITH_MBEDTLS)
68  const mbedtls_md_info_t *hmac;
69  mbedtls_md_context_t ctx;
70 #else
71  const EVP_MD *evp_type;
72  EVP_MD_CTX *ctx;
73 #endif
74 };
75 
82 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
83 lws_genhash_size(enum lws_genhash_types type);
84 
91 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
92 lws_genhmac_size(enum lws_genhmac_types type);
93 
101 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
102 lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type);
103 
112 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
113 lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len);
114 
126 LWS_VISIBLE LWS_EXTERN int
127 lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result);
128 
141 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
142 lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
143  const uint8_t *key, size_t key_len);
144 
155 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
156 lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len);
157 
169 LWS_VISIBLE LWS_EXTERN int
170 lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result);
lws_genhash_init
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type)
lws_genhmac_update
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len)
lws_genhmac_size
LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhmac_size(enum lws_genhmac_types type)
lws_genhmac_init
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_genhash_size
LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT lws_genhash_size(enum lws_genhash_types type)
lws_genhash_ctx
Definition: lws-genhash.h:50
lws_genhash_update
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len)
lws_genhmac_destroy
LWS_VISIBLE LWS_EXTERN int lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result)
lws_genhash_destroy
LWS_VISIBLE LWS_EXTERN int lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result)
lws_genhmac_ctx
Definition: lws-genhash.h:65