libwebsockets
Lightweight C library for HTML5 websockets
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#if defined(LWS_WITH_OPENHITLS)
45#include <crypt_eal_cipher.h>
46#endif
47
59
64
69
70/* include/libwebsockets/lws-jwk.h must be included before this */
71
72#define LWS_AES_BLOCKSIZE 128
73#define LWS_AES_CBC_BLOCKLEN 16
74
76#if defined(LWS_WITH_MBEDTLS)
77#if !defined(LWS_HAVE_MBEDTLS_V4)
78 union {
79 mbedtls_aes_context ctx;
80#if defined(MBEDTLS_CIPHER_MODE_XTS)
81 mbedtls_aes_xts_context ctx_xts;
82#endif
83 mbedtls_gcm_context ctx_gcm;
84 } u;
85#else
86 psa_key_id_t key_id;
87 psa_algorithm_t alg;
88 psa_cipher_operation_t cipher_ctx;
89 psa_aead_operation_t aead_ctx;
90#endif
91#elif defined(LWS_WITH_SCHANNEL)
92 struct {
93 void *hAlg;
94 void *hKey;
95 void *pbMacContext;
96 size_t cbMacContext;
97 void *pbNonce;
98 size_t cbNonce;
99 void *pbTag;
100 size_t cbTag;
101 void *pbAuthData;
102 size_t cbAuthData;
103 unsigned char iv[LWS_AES_CBC_BLOCKLEN]; /* Internal IV buffer for chaining */
104 } u;
105#elif defined(LWS_WITH_GNUTLS)
106 gnutls_cipher_hd_t ctx;
107 int gnutls_gcm_initialized;
108#elif defined(LWS_WITH_BEARSSL)
109 union {
110 br_aes_ct_cbcenc_keys cbcenc;
111 br_aes_ct_cbcdec_keys cbcdec;
112 br_aes_ct_ctr_keys ctr;
113 } u;
114 br_gcm_context gcm;
115 const br_block_cbcenc_class *cbcenc_vtable;
116 const br_block_cbcdec_class *cbcdec_vtable;
117 const br_block_ctr_class *ctr_vtable;
118#elif defined(LWS_WITH_OPENHITLS)
119 CRYPT_EAL_CipherCtx *ctx;
120#else
121 EVP_CIPHER_CTX *ctx;
122 const EVP_CIPHER *cipher;
123 ENGINE *engine;
124 char init;
125#endif
126 unsigned char tag[16];
133#if !defined(LWS_WITH_MBEDTLS) && !defined(LWS_WITH_OPENSSL)
134 unsigned char buf[16]; /* partial block */
135 int buf_len; /* length of partial block */
136#endif
137};
138
157 enum enum_aes_modes mode, struct lws_gencrypto_keyelem *el,
158 enum enum_aes_padding padding, void *engine);
159
173lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen);
174
211lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len,
212 uint8_t *out,
213 uint8_t *iv_or_nonce_ctr_or_data_unit_16,
214 uint8_t *stream_block_16,
215 size_t *nc_or_iv_off, int taglen);
216
const EVP_CIPHER * cipher
Definition lws-genaes.h:122
ENGINE * engine
Definition lws-genaes.h:123
enum enum_aes_modes mode
Definition lws-genaes.h:129
enum enum_aes_operation op
Definition lws-genaes.h:128
EVP_CIPHER_CTX * ctx
Definition lws-genaes.h:121
unsigned char buf[16]
Definition lws-genaes.h:134
unsigned char tag[16]
Definition lws-genaes.h:126
struct lws_gencrypto_keyelem * k
Definition lws-genaes.h:127
enum enum_aes_padding padding
Definition lws-genaes.h:130
enum_aes_modes
Definition lws-genaes.h:48
enum_aes_operation
Definition lws-genaes.h:60
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
Definition lws-genaes.h:65
LWS_VISIBLE LWS_EXTERN int lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen)
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)
#define LWS_AES_CBC_BLOCKLEN
Definition lws-genaes.h:73
@ LWS_GAESM_CFB128
Definition lws-genaes.h:50
@ LWS_GAESM_CBC
Definition lws-genaes.h:49
@ LWS_GAESM_OFB
Definition lws-genaes.h:54
@ LWS_GAESM_KW
Definition lws-genaes.h:57
@ LWS_GAESM_CFB8
Definition lws-genaes.h:51
@ LWS_GAESM_ECB
Definition lws-genaes.h:53
@ LWS_GAESM_GCM
Definition lws-genaes.h:56
@ LWS_GAESM_XTS
Definition lws-genaes.h:55
@ LWS_GAESM_CTR
Definition lws-genaes.h:52
@ LWS_GAESO_DEC
Definition lws-genaes.h:62
@ LWS_GAESO_ENC
Definition lws-genaes.h:61
@ LWS_GAESP_NO_PADDING
Definition lws-genaes.h:66
@ LWS_GAESP_WITH_PADDING
Definition lws-genaes.h:67
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE