libwebsockets
Lightweight C library for HTML5 websockets
lws-gencrypto.h
Go to the documentation of this file.
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2020 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 
25 /*
26  * These are gencrypto-level constants... they are used by both JOSE and direct
27  * gencrypto code. However while JWK relies on these, using gencrypto apis has
28  * no dependency at all on any JOSE type.
29  */
30 
33 
37 };
38 
39 /*
40  * Keytypes where the same element name is reused must all agree to put the
41  * same-named element at the same e[] index. It's because when used with jwk,
42  * we parse and store in incoming key data, but we may not be informed of the
43  * definitive keytype until the end.
44  */
45 
47  LWS_GENCRYPTO_OCT_KEYEL_K, /* note... same offset as AES K */
48 
50 };
51 
55  LWS_GENCRYPTO_RSA_KEYEL_D, /* note... same offset as EC D */
61 
62  /* we don't actively use these if given, but may come from COSE */
63 
68 
70 };
71 
75  /* note... same offset as RSA D */
78 
80 };
81 
83  /* note... same offset as OCT K */
85 
87 };
88 
89 /* largest number of key elements for any algorithm */
90 #define LWS_GENCRYPTO_MAX_KEYEL_COUNT LWS_GENCRYPTO_RSA_KEYEL_COUNT
91 
92 /* this "stretchy" type holds individual key element data in binary form.
93  * It's typcially used in an array with the layout mapping the element index to
94  * the key element meaning defined by the enums above. An array of these of
95  * length LWS_GENCRYPTO_MAX_KEYEL_COUNT can define key elements for any key
96  * type.
97  */
98 
99 typedef struct lws_gencrypto_keyelem {
103 
104 
115 
125 lws_base64_size(int bytes);
126 
136 LWS_VISIBLE LWS_EXTERN size_t
137 lws_gencrypto_padded_length(size_t block_size, size_t len);
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
lws_gencrypto_ec_tok
Definition: lws-gencrypto.h:72
@ LWS_GENCRYPTO_EC_KEYEL_X
Definition: lws-gencrypto.h:74
@ LWS_GENCRYPTO_EC_KEYEL_COUNT
Definition: lws-gencrypto.h:79
@ LWS_GENCRYPTO_EC_KEYEL_D
Definition: lws-gencrypto.h:76
@ LWS_GENCRYPTO_EC_KEYEL_CRV
Definition: lws-gencrypto.h:73
@ LWS_GENCRYPTO_EC_KEYEL_Y
Definition: lws-gencrypto.h:77
LWS_VISIBLE LWS_EXTERN int lws_base64_size(int bytes)
lws_gencrypto_oct_tok
Definition: lws-gencrypto.h:46
@ LWS_GENCRYPTO_OCT_KEYEL_COUNT
Definition: lws-gencrypto.h:49
@ LWS_GENCRYPTO_OCT_KEYEL_K
Definition: lws-gencrypto.h:47
lws_gencrypto_rsa_tok
Definition: lws-gencrypto.h:52
@ LWS_GENCRYPTO_RSA_KEYEL_D
Definition: lws-gencrypto.h:55
@ LWS_GENCRYPTO_RSA_KEYEL_DP
Definition: lws-gencrypto.h:58
@ LWS_GENCRYPTO_RSA_KEYEL_QI
Definition: lws-gencrypto.h:60
@ LWS_GENCRYPTO_RSA_KEYEL_COUNT
Definition: lws-gencrypto.h:69
@ LWS_GENCRYPTO_RSA_KEYEL_OTHER
Definition: lws-gencrypto.h:64
@ LWS_GENCRYPTO_RSA_KEYEL_RI
Definition: lws-gencrypto.h:65
@ LWS_GENCRYPTO_RSA_KEYEL_TI
Definition: lws-gencrypto.h:67
@ LWS_GENCRYPTO_RSA_KEYEL_E
Definition: lws-gencrypto.h:53
@ LWS_GENCRYPTO_RSA_KEYEL_DQ
Definition: lws-gencrypto.h:59
@ LWS_GENCRYPTO_RSA_KEYEL_N
Definition: lws-gencrypto.h:54
@ LWS_GENCRYPTO_RSA_KEYEL_Q
Definition: lws-gencrypto.h:57
@ LWS_GENCRYPTO_RSA_KEYEL_P
Definition: lws-gencrypto.h:56
@ LWS_GENCRYPTO_RSA_KEYEL_DI
Definition: lws-gencrypto.h:66
lws_gencrypto_kty
Definition: lws-gencrypto.h:31
@ LWS_GENCRYPTO_KTY_EC
Definition: lws-gencrypto.h:36
@ LWS_GENCRYPTO_KTY_RSA
Definition: lws-gencrypto.h:35
@ LWS_GENCRYPTO_KTY_UNKNOWN
Definition: lws-gencrypto.h:32
@ LWS_GENCRYPTO_KTY_OCT
Definition: lws-gencrypto.h:34
struct lws_gencrypto_keyelem lws_gc_elem_t
LWS_VISIBLE LWS_EXTERN int lws_gencrypto_bits_to_bytes(int bits)
lws_gencrypto_aes_tok
Definition: lws-gencrypto.h:82
@ LWS_GENCRYPTO_AES_KEYEL_K
Definition: lws-gencrypto.h:84
@ LWS_GENCRYPTO_AES_KEYEL_COUNT
Definition: lws-gencrypto.h:86
LWS_VISIBLE LWS_EXTERN size_t lws_gencrypto_padded_length(size_t block_size, size_t len)