libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-genaes.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
35
36
#if defined(LWS_WITH_MBEDTLS)
37
#if !defined(LWS_HAVE_MBEDTLS_V4)
38
#include <mbedtls/aes.h>
39
#include <mbedtls/gcm.h>
40
#else
41
#include <psa/crypto.h>
42
#endif
43
#endif
44
45
enum
enum_aes_modes
{
46
LWS_GAESM_CBC
,
47
LWS_GAESM_CFB128
,
48
LWS_GAESM_CFB8
,
49
LWS_GAESM_CTR
,
50
LWS_GAESM_ECB
,
51
LWS_GAESM_OFB
,
52
LWS_GAESM_XTS
,
/* care... requires double-length key */
53
LWS_GAESM_GCM
,
54
LWS_GAESM_KW
,
55
};
56
57
enum
enum_aes_operation
{
58
LWS_GAESO_ENC
,
59
LWS_GAESO_DEC
60
};
61
62
enum
enum_aes_padding
{
63
LWS_GAESP_NO_PADDING
,
64
LWS_GAESP_WITH_PADDING
65
};
66
67
/* include/libwebsockets/lws-jwk.h must be included before this */
68
69
#define LWS_AES_BLOCKSIZE 128
70
#define LWS_AES_CBC_BLOCKLEN 16
71
72
struct
lws_genaes_ctx
{
73
#if defined(LWS_WITH_MBEDTLS)
74
#if !defined(LWS_HAVE_MBEDTLS_V4)
75
union
{
76
mbedtls_aes_context
ctx
;
77
#if defined(MBEDTLS_CIPHER_MODE_XTS)
78
mbedtls_aes_xts_context ctx_xts;
79
#endif
80
mbedtls_gcm_context ctx_gcm;
81
} u;
82
#else
83
psa_key_id_t key_id;
84
psa_algorithm_t alg;
85
psa_cipher_operation_t cipher_ctx;
86
psa_aead_operation_t aead_ctx;
87
#endif
88
#elif defined(LWS_WITH_SCHANNEL)
89
struct
{
90
void
*hAlg;
91
void
*hKey;
92
void
*pbMacContext;
93
size_t
cbMacContext;
94
void
*pbNonce;
95
size_t
cbNonce;
96
void
*pbTag;
97
size_t
cbTag;
98
void
*pbAuthData;
99
size_t
cbAuthData;
100
unsigned
char
iv[
LWS_AES_CBC_BLOCKLEN
];
/* Internal IV buffer for chaining */
101
} u;
102
#elif defined(LWS_WITH_GNUTLS)
103
gnutls_cipher_hd_t
ctx
;
104
int
gnutls_gcm_initialized;
105
#elif defined(LWS_WITH_BEARSSL)
106
union
{
107
br_aes_ct_cbcenc_keys cbcenc;
108
br_aes_ct_cbcdec_keys cbcdec;
109
br_aes_ct_ctr_keys ctr;
110
} u;
111
br_gcm_context gcm;
112
const
br_block_cbcenc_class *cbcenc_vtable;
113
const
br_block_cbcdec_class *cbcdec_vtable;
114
const
br_block_ctr_class *ctr_vtable;
115
#else
116
EVP_CIPHER_CTX *
ctx
;
117
const
EVP_CIPHER *
cipher
;
118
ENGINE *
engine
;
119
char
init
;
120
#endif
121
unsigned
char
tag
[16];
122
struct
lws_gencrypto_keyelem
*
k
;
123
enum
enum_aes_operation
op
;
124
enum
enum_aes_modes
mode
;
125
enum
enum_aes_padding
padding
;
126
int
taglen
;
127
char
underway
;
128
#if !defined(LWS_WITH_MBEDTLS) && !defined(LWS_WITH_OPENSSL)
129
unsigned
char
buf
[16];
/* partial block */
130
int
buf_len
;
/* length of partial block */
131
#endif
132
};
133
150
LWS_VISIBLE
LWS_EXTERN
int
151
lws_genaes_create
(
struct
lws_genaes_ctx
*ctx,
enum
enum_aes_operation
op,
152
enum
enum_aes_modes
mode,
struct
lws_gencrypto_keyelem
*el,
153
enum
enum_aes_padding
padding,
void
*engine);
154
167
LWS_VISIBLE
LWS_EXTERN
int
168
lws_genaes_destroy
(
struct
lws_genaes_ctx
*ctx,
unsigned
char
*tag,
size_t
tlen);
169
205
LWS_VISIBLE
LWS_EXTERN
int
206
lws_genaes_crypt
(
struct
lws_genaes_ctx
*ctx,
const
uint8_t
*in,
size_t
len
,
207
uint8_t
*out,
208
uint8_t
*iv_or_nonce_ctr_or_data_unit_16,
209
uint8_t
*stream_block_16,
210
size_t
*nc_or_iv_off,
int
taglen);
211
lws_genaes_ctx::cipher
const EVP_CIPHER * cipher
Definition
lws-genaes.h:117
lws_genaes_ctx::taglen
int taglen
Definition
lws-genaes.h:126
lws_genaes_ctx::engine
ENGINE * engine
Definition
lws-genaes.h:118
lws_genaes_ctx::mode
enum enum_aes_modes mode
Definition
lws-genaes.h:124
lws_genaes_ctx::underway
char underway
Definition
lws-genaes.h:127
lws_genaes_ctx::buf_len
int buf_len
Definition
lws-genaes.h:130
lws_genaes_ctx::op
enum enum_aes_operation op
Definition
lws-genaes.h:123
lws_genaes_ctx::ctx
EVP_CIPHER_CTX * ctx
Definition
lws-genaes.h:116
lws_genaes_ctx::buf
unsigned char buf[16]
Definition
lws-genaes.h:129
lws_genaes_ctx::tag
unsigned char tag[16]
Definition
lws-genaes.h:121
lws_genaes_ctx::k
struct lws_gencrypto_keyelem * k
Definition
lws-genaes.h:122
lws_genaes_ctx::init
char init
Definition
lws-genaes.h:119
lws_genaes_ctx::padding
enum enum_aes_padding padding
Definition
lws-genaes.h:125
enum_aes_modes
enum_aes_modes
Definition
lws-genaes.h:45
enum_aes_operation
enum_aes_operation
Definition
lws-genaes.h:57
lws_genaes_crypt
LWS_VISIBLE LWS_EXTERN int lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, uint8_t *out, uint8_t *iv_or_nonce_ctr_or_data_unit_16, uint8_t *stream_block_16, size_t *nc_or_iv_off, int taglen)
enum_aes_padding
enum_aes_padding
Definition
lws-genaes.h:62
lws_genaes_destroy
LWS_VISIBLE LWS_EXTERN int lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen)
lws_genaes_create
LWS_VISIBLE LWS_EXTERN int lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op, enum enum_aes_modes mode, struct lws_gencrypto_keyelem *el, enum enum_aes_padding padding, void *engine)
LWS_AES_CBC_BLOCKLEN
#define LWS_AES_CBC_BLOCKLEN
Definition
lws-genaes.h:70
LWS_GAESM_CFB128
@ LWS_GAESM_CFB128
Definition
lws-genaes.h:47
LWS_GAESM_CBC
@ LWS_GAESM_CBC
Definition
lws-genaes.h:46
LWS_GAESM_OFB
@ LWS_GAESM_OFB
Definition
lws-genaes.h:51
LWS_GAESM_KW
@ LWS_GAESM_KW
Definition
lws-genaes.h:54
LWS_GAESM_CFB8
@ LWS_GAESM_CFB8
Definition
lws-genaes.h:48
LWS_GAESM_ECB
@ LWS_GAESM_ECB
Definition
lws-genaes.h:50
LWS_GAESM_GCM
@ LWS_GAESM_GCM
Definition
lws-genaes.h:53
LWS_GAESM_XTS
@ LWS_GAESM_XTS
Definition
lws-genaes.h:52
LWS_GAESM_CTR
@ LWS_GAESM_CTR
Definition
lws-genaes.h:49
LWS_GAESO_DEC
@ LWS_GAESO_DEC
Definition
lws-genaes.h:59
LWS_GAESO_ENC
@ LWS_GAESO_ENC
Definition
lws-genaes.h:58
LWS_GAESP_NO_PADDING
@ LWS_GAESP_NO_PADDING
Definition
lws-genaes.h:63
LWS_GAESP_WITH_PADDING
@ LWS_GAESP_WITH_PADDING
Definition
lws-genaes.h:64
lws_genaes_ctx
Definition
lws-genaes.h:72
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:706
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:291
lws_gencrypto_keyelem::len
uint32_t len
Definition
lws-gencrypto.h:111
lws_gencrypto_keyelem
Definition
lws-gencrypto.h:109
include
libwebsockets
lws-genaes.h
Generated on
for libwebsockets by
1.18.0