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