libwebsockets
Lightweight C library for HTML5 websockets
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 #include <mbedtls/aes.h>
38 #include <mbedtls/gcm.h>
39 #endif
40 
48  LWS_GAESM_XTS, /* care... requires double-length key */
51 };
52 
56 };
57 
61 };
62 
63 /* include/libwebsockets/lws-jwk.h must be included before this */
64 
65 #define LWS_AES_BLOCKSIZE 128
66 #define LWS_AES_CBC_BLOCKLEN 16
67 
69 #if defined(LWS_WITH_MBEDTLS)
70  union {
71  mbedtls_aes_context ctx;
72 #if defined(MBEDTLS_CIPHER_MODE_XTS)
73  mbedtls_aes_xts_context ctx_xts;
74 #endif
75  mbedtls_gcm_context ctx_gcm;
76  } u;
77 #else
78  EVP_CIPHER_CTX *ctx;
79  const EVP_CIPHER *cipher;
80  ENGINE *engine;
81  char init;
82 #endif
83  unsigned char tag[16];
86  enum enum_aes_modes mode;
88  int taglen;
89  char underway;
90 };
91 
110  enum enum_aes_modes mode, struct lws_gencrypto_keyelem *el,
111  enum enum_aes_padding padding, void *engine);
112 
126 lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen);
127 
164 lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len,
165  uint8_t *out,
166  uint8_t *iv_or_nonce_ctr_or_data_unit_16,
167  uint8_t *stream_block_16,
168  size_t *nc_or_iv_off, int taglen);
169 
const EVP_CIPHER * cipher
Definition: lws-genaes.h:79
ENGINE * engine
Definition: lws-genaes.h:80
enum enum_aes_modes mode
Definition: lws-genaes.h:86
enum enum_aes_operation op
Definition: lws-genaes.h:85
EVP_CIPHER_CTX * ctx
Definition: lws-genaes.h:78
unsigned char tag[16]
Definition: lws-genaes.h:83
struct lws_gencrypto_keyelem * k
Definition: lws-genaes.h:84
enum enum_aes_padding padding
Definition: lws-genaes.h:87
enum_aes_modes
Definition: lws-genaes.h:41
enum_aes_operation
Definition: lws-genaes.h:53
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:58
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)
@ LWS_GAESM_CFB128
Definition: lws-genaes.h:43
@ LWS_GAESM_CBC
Definition: lws-genaes.h:42
@ LWS_GAESM_OFB
Definition: lws-genaes.h:47
@ LWS_GAESM_KW
Definition: lws-genaes.h:50
@ LWS_GAESM_CFB8
Definition: lws-genaes.h:44
@ LWS_GAESM_ECB
Definition: lws-genaes.h:46
@ LWS_GAESM_GCM
Definition: lws-genaes.h:49
@ LWS_GAESM_XTS
Definition: lws-genaes.h:48
@ LWS_GAESM_CTR
Definition: lws-genaes.h:45
@ LWS_GAESO_DEC
Definition: lws-genaes.h:55
@ LWS_GAESO_ENC
Definition: lws-genaes.h:54
@ LWS_GAESP_NO_PADDING
Definition: lws-genaes.h:59
@ LWS_GAESP_WITH_PADDING
Definition: lws-genaes.h:60
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE