libwebsockets
Lightweight C library for HTML5 websockets
lws-genec.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 
27 
30 };
31 
32 struct lws_genec_ctx {
33 #if defined(LWS_WITH_MBEDTLS)
34  union {
35  mbedtls_ecdh_context *ctx_ecdh;
36  mbedtls_ecdsa_context *ctx_ecdsa;
37  } u;
38 #else
39  EVP_PKEY_CTX *ctx[2];
40 #endif
41  struct lws_context *context;
42  const struct lws_ec_curves *curve_table;
44 
46 };
47 
48 #if defined(LWS_WITH_MBEDTLS)
49 enum enum_lws_dh_side {
50  LDHS_OURS = MBEDTLS_ECDH_OURS,
51  LDHS_THEIRS = MBEDTLS_ECDH_THEIRS
52 };
53 #else
57 };
58 #endif
59 
60 struct lws_ec_curves {
61  const char *name;
64 };
65 
66 
67 /* ECDH-specific apis */
68 
79 LWS_VISIBLE int
80 lws_genecdh_create(struct lws_genec_ctx *ctx, struct lws_context *context,
81  const struct lws_ec_curves *curve_table);
82 
93  enum enum_lws_dh_side side);
94 
106  const char *curve_name, struct lws_gencrypto_keyelem *el);
107 
110  int *ss_len);
111 
112 
113 /* ECDSA-specific apis */
114 
125 LWS_VISIBLE int
126 lws_genecdsa_create(struct lws_genec_ctx *ctx, struct lws_context *context,
127  const struct lws_ec_curves *curve_table);
128 
138 lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name,
139  struct lws_gencrypto_keyelem *el);
140 
150  const struct lws_gencrypto_keyelem *el);
151 
175  enum lws_genhash_types hash_type, int keybits,
176  const uint8_t *sig, size_t sig_len);
177 
198  enum lws_genhash_types hash_type, int keybits,
199  uint8_t *sig, size_t sig_len);
200 
201 
202 /* Apis that apply to both ECDH and ECDSA */
203 
206 
209 
lws_genhash_types
Definition: lws-genhash.h:36
unsigned short uint16_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
const struct lws_ec_curves * curve_table
Definition: lws-genec.h:42
LWS_VISIBLE int lws_genecdsa_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table)
LWS_VISIBLE LWS_EXTERN int lws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, const char *curve_name, struct lws_gencrypto_keyelem *el)
LWS_VISIBLE LWS_EXTERN int lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name, struct lws_gencrypto_keyelem *el)
LWS_VISIBLE LWS_EXTERN int lws_genecdh_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el, enum enum_lws_dh_side side)
enum_genec_alg
Definition: lws-genec.h:25
@ LEGENEC_ECDH
Definition: lws-genec.h:28
@ LEGENEC_ECDSA
Definition: lws-genec.h:29
@ LEGENEC_UNKNOWN
Definition: lws-genec.h:26
LWS_VISIBLE LWS_EXTERN int lws_genecdsa_set_key(struct lws_genec_ctx *ctx, const struct lws_gencrypto_keyelem *el)
LWS_VISIBLE LWS_EXTERN int lws_genec_dump(struct lws_gencrypto_keyelem *el)
LWS_VISIBLE LWS_EXTERN void lws_genec_destroy_elements(struct lws_gencrypto_keyelem *el)
LWS_VISIBLE LWS_EXTERN int lws_genecdh_compute_shared_secret(struct lws_genec_ctx *ctx, uint8_t *ss, int *ss_len)
LWS_VISIBLE LWS_EXTERN int lws_genecdsa_hash_sign_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, uint8_t *sig, size_t sig_len)
LWS_VISIBLE LWS_EXTERN int lws_genecdsa_hash_sig_verify_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, const uint8_t *sig, size_t sig_len)
enum_lws_dh_side
Definition: lws-genec.h:54
@ LDHS_OURS
Definition: lws-genec.h:55
@ LDHS_THEIRS
Definition: lws-genec.h:56
enum enum_genec_alg genec_alg
Definition: lws-genec.h:43
const char * name
Definition: lws-genec.h:61
EVP_PKEY_CTX * ctx[2]
Definition: lws-genec.h:39
int tls_lib_nid
Definition: lws-genec.h:62
uint16_t key_bytes
Definition: lws-genec.h:63
LWS_VISIBLE int lws_genecdh_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table)
struct lws_context * context
Definition: lws-genec.h:41
LWS_VISIBLE LWS_EXTERN void lws_genec_destroy(struct lws_genec_ctx *ctx)
char has_private
Definition: lws-genec.h:45