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 
34 
35 enum lws_genhash_types {
36  LWS_GENHASH_TYPE_UNKNOWN,
37  LWS_GENHASH_TYPE_MD5,
38  LWS_GENHASH_TYPE_SHA1,
39  LWS_GENHASH_TYPE_SHA256,
40  LWS_GENHASH_TYPE_SHA384,
41  LWS_GENHASH_TYPE_SHA512,
42 };
43 
44 enum lws_genhmac_types {
45  LWS_GENHMAC_TYPE_UNKNOWN,
46  LWS_GENHMAC_TYPE_SHA256,
47  LWS_GENHMAC_TYPE_SHA384,
48  LWS_GENHMAC_TYPE_SHA512,
49 };
50 
51 #define LWS_GENHASH_LARGEST 64
52 
54  uint8_t type;
55 #if defined(LWS_WITH_MBEDTLS)
56  union {
57  mbedtls_md5_context md5;
58  mbedtls_sha1_context sha1;
59  mbedtls_sha256_context sha256;
60  mbedtls_sha512_context sha512; /* 384 also uses this */
61  const mbedtls_md_info_t *hmac;
62  } u;
63 #else
64  const EVP_MD *evp_type;
65  EVP_MD_CTX *mdctx;
66 #endif
67 };
68 
70  uint8_t type;
71 #if defined(LWS_WITH_MBEDTLS)
72  const mbedtls_md_info_t *hmac;
73  mbedtls_md_context_t ctx;
74 #else
75  const EVP_MD *evp_type;
76 #if defined(LWS_HAVE_HMAC_CTX_new)
77  HMAC_CTX *ctx;
78 #else
79  HMAC_CTX ctx;
80 #endif
81 #endif
82 };
83 
90 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
91 lws_genhash_size(enum lws_genhash_types type);
92 
99 LWS_VISIBLE LWS_EXTERN size_t LWS_WARN_UNUSED_RESULT
100 lws_genhmac_size(enum lws_genhmac_types type);
101 
109 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
110 lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type);
111 
120 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
121 lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len);
122 
134 LWS_VISIBLE LWS_EXTERN int
135 lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result);
136 
149 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
150 lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
151  const uint8_t *key, size_t key_len);
152 
163 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
164 lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len);
165 
177 LWS_VISIBLE LWS_EXTERN int
178 lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result);
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)
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)
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:53
Definition: lws-genhash.h:69