libwebsockets
Lightweight C library for HTML5 websockets
lws-genrsa.h
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 enum enum_genrsa_mode {
39  LGRSAM_PKCS1_1_5,
40  LGRSAM_PKCS1_OAEP_PSS,
41 
42  LGRSAM_COUNT
43 };
44 
46 #if defined(LWS_WITH_MBEDTLS)
47  mbedtls_rsa_context *ctx;
48 #else
49  BIGNUM *bn[LWS_GENCRYPTO_RSA_KEYEL_COUNT];
50  EVP_PKEY_CTX *ctx;
51  RSA *rsa;
52 #endif
53  struct lws_context *context;
54  enum enum_genrsa_mode mode;
55 };
56 
76 LWS_VISIBLE LWS_EXTERN int
78  const struct lws_gencrypto_keyelem *el,
79  struct lws_context *context, enum enum_genrsa_mode mode,
80  enum lws_genhash_types oaep_hashid);
81 
93 LWS_VISIBLE LWS_EXTERN void
95 
114 LWS_VISIBLE LWS_EXTERN int
115 lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx,
116  enum enum_genrsa_mode mode, struct lws_gencrypto_keyelem *el,
117  int bits);
118 
132 LWS_VISIBLE LWS_EXTERN int
133 lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
134  size_t in_len, uint8_t *out);
135 
149 LWS_VISIBLE LWS_EXTERN int
150 lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
151  size_t in_len, uint8_t *out);
152 
167 LWS_VISIBLE LWS_EXTERN int
168 lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
169  size_t in_len, uint8_t *out, size_t out_max);
170 
185 LWS_VISIBLE LWS_EXTERN int
186 lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
187  size_t in_len, uint8_t *out, size_t out_max);
188 
206 LWS_VISIBLE LWS_EXTERN int
207 lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in,
208  enum lws_genhash_types hash_type,
209  const uint8_t *sig, size_t sig_len);
210 
227 LWS_VISIBLE LWS_EXTERN int
228 lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in,
229  enum lws_genhash_types hash_type,
230  uint8_t *sig, size_t sig_len);
231 
240 LWS_VISIBLE LWS_EXTERN void
242 
252 LWS_VISIBLE LWS_EXTERN int
253 lws_genrsa_render_pkey_asn1(struct lws_genrsa_ctx *ctx, int _private,
254  uint8_t *pkey_asn1, size_t pkey_asn1_len);
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)
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)
Definition: lws-gencrypto.h:99
Definition: lws-genrsa.h:45