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