libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-genrsa.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
35
36/* include/libwebsockets/lws-jwk.h must be included before this */
37
38#if defined(LWS_WITH_OPENHITLS)
39#include <crypt_eal_pkey.h>
40#endif
41
48
49/*
50 * The ctx is user-allocated storage, and may be uninitialized when first
51 * passed to a create() api. create() marks the ctx once it has brought it
52 * to a known state, so it can distinguish a ctx that may hold live backend
53 * key handles (and must release them before re-initializing) from
54 * uninitialized storage; lws_genrsa_destroy() clears the mark.
55 */
56
57#define LWS_GENRSA_CTX_CREATED_MARK 0x4c574752u /* "LWGR" */
58
60#if defined(LWS_WITH_MBEDTLS)
61#if !defined(LWS_HAVE_MBEDTLS_V4)
62 mbedtls_rsa_context *ctx;
63#else
64 psa_key_id_t key_id;
65#endif
66#elif defined(LWS_WITH_SCHANNEL)
67 struct {
68 void *hAlg;
69 void *hKey;
70 } u;
71#elif defined(LWS_WITH_GNUTLS)
72 gnutls_privkey_t priv;
73 gnutls_pubkey_t pub;
74#elif defined(LWS_WITH_BEARSSL)
75 br_rsa_public_key pub;
76 br_rsa_private_key priv;
77 void *kbuf_priv;
78 void *kbuf_pub;
79#elif defined(LWS_WITH_OPENHITLS)
80 CRYPT_EAL_PkeyCtx *ctx;
81 CRYPT_EAL_PkeyPub pub;
82 CRYPT_EAL_PkeyPrv prv;
83#else
85 EVP_PKEY_CTX *ctx;
86 RSA *rsa;
87#endif
88 struct lws_context *context;
91
93};
94
121 const struct lws_gencrypto_keyelem *el,
122 struct lws_context *context, enum enum_genrsa_mode mode,
123 enum lws_genhash_types oaep_hashid);
124
138
162lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx,
163 enum enum_genrsa_mode mode, struct lws_gencrypto_keyelem *el,
164 int bits);
165
181 size_t in_len, uint8_t *out);
182
198 size_t in_len, uint8_t *out);
199
216 size_t in_len, uint8_t *out, size_t out_max);
217
234 size_t in_len, uint8_t *out, size_t out_max);
235
255 enum lws_genhash_types hash_type,
256 const uint8_t *sig, size_t sig_len);
257
276 enum lws_genhash_types hash_type,
277 uint8_t *sig, size_t sig_len);
278
289
301 uint8_t *pkey_asn1, size_t pkey_asn1_len);
enum lws_genhash_types oaep_hashid
Definition lws-genrsa.h:90
struct lws_context * context
Definition lws-genrsa.h:88
enum enum_genrsa_mode mode
Definition lws-genrsa.h:89
EVP_PKEY_CTX * ctx
Definition lws-genrsa.h:85
BIGNUM * bn[LWS_GENCRYPTO_RSA_KEYEL_COUNT]
Definition lws-genrsa.h:84
uint32_t created_mark
Definition lws-genrsa.h:92
LWS_VISIBLE LWS_EXTERN int lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_create(struct lws_genrsa_ctx *ctx, const struct lws_gencrypto_keyelem *el, struct lws_context *context, enum enum_genrsa_mode mode, enum lws_genhash_types oaep_hashid)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, enum enum_genrsa_mode mode, struct lws_gencrypto_keyelem *el, int bits)
LWS_VISIBLE LWS_EXTERN void lws_genrsa_destroy_elements(struct lws_gencrypto_keyelem *el)
enum_genrsa_mode
Definition lws-genrsa.h:42
LWS_VISIBLE LWS_EXTERN int lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_render_pkey_asn1(struct lws_genrsa_ctx *ctx, int _private, uint8_t *pkey_asn1, size_t pkey_asn1_len)
LWS_VISIBLE LWS_EXTERN void lws_genrsa_destroy(struct lws_genrsa_ctx *ctx)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, const uint8_t *sig, size_t sig_len)
LWS_VISIBLE LWS_EXTERN int lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, uint8_t *sig, size_t sig_len)
@ LGRSAM_PKCS1_OAEP_PSS
Definition lws-genrsa.h:44
@ LGRSAM_PKCS1_1_5
Definition lws-genrsa.h:43
@ LGRSAM_COUNT
Definition lws-genrsa.h:46
lws_genhash_types
Definition lws-genhash.h:53
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
@ LWS_GENCRYPTO_RSA_KEYEL_COUNT