libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
class="ui-resizable-handle">
Loading...
Searching...
No Matches
lws-genchacha.h
Go to the documentation of this file.
1
/*
2
* libwebsockets - small server side websockets and web server implementation
3
*
4
* Copyright (C) 2010 - 2026 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
25
#ifndef __LWS_GENCHACHA_H__
26
#define __LWS_GENCHACHA_H__
27
28
#include <stdint.h>
29
30
#if defined(LWS_WITH_MBEDTLS)
31
#include <mbedtls/chachapoly.h>
32
#endif
33
40
41
#define LWS_CHACHA_MINKEYLEN 16
42
#define LWS_CHACHA_NONCELEN 8
43
#define LWS_CHACHA_CTRLEN 8
44
#define LWS_CHACHA_STATELEN (LWS_CHACHA_NONCELEN+LWS_CHACHA_CTRLEN)
45
#define LWS_CHACHA_BLOCKLEN 64
46
47
struct
lws_chacha_ctx
{
48
uint32_t
input
[16];
49
};
50
58
LWS_VISIBLE
LWS_EXTERN
void
59
lws_chacha_keysetup
(
struct
lws_chacha_ctx
*x,
const
uint8_t
*k,
uint32_t
kbits);
60
68
LWS_VISIBLE
LWS_EXTERN
void
69
lws_chacha_ivsetup
(
struct
lws_chacha_ctx
*x,
const
uint8_t
*iv,
const
uint8_t
*counter);
70
78
LWS_VISIBLE
LWS_EXTERN
void
79
lws_chacha_ivsetup_ietf
(
struct
lws_chacha_ctx
*x,
const
uint8_t
*nonce,
uint32_t
counter);
80
89
LWS_VISIBLE
LWS_EXTERN
void
90
lws_chacha_encrypt_bytes
(
struct
lws_chacha_ctx
*x,
const
uint8_t
*m,
uint8_t
*c,
uint32_t
bytes);
91
92
93
#define LWS_POLY1305_TAGLEN 16
94
#define LWS_POLY1305_KEYLEN 32
95
104
LWS_VISIBLE
LWS_EXTERN
void
105
lws_poly1305_auth
(
uint8_t
out[
LWS_POLY1305_TAGLEN
],
const
uint8_t
*m,
size_t
inlen,
const
uint8_t
key[
LWS_POLY1305_KEYLEN
]);
106
107
struct
lws_genchacha_ctx
{
108
#if defined(LWS_WITH_MBEDTLS)
109
union
{
110
mbedtls_chachapoly_context cp;
111
mbedtls_cipher_context_t cipher;
112
} u;
113
#elif defined(LWS_WITH_OPENSSL)
114
EVP_CIPHER_CTX *ctx;
115
#endif
116
/* fallback native ctx */
117
struct
lws_chacha_ctx
native_ctx
;
118
struct
lws_gencrypto_keyelem
*
k
;
119
enum
enum_aes_operation
op
;
120
void
*
engine
;
121
};
122
123
LWS_VISIBLE
LWS_EXTERN
int
124
lws_genchacha_create
(
struct
lws_genchacha_ctx
*ctx,
enum
enum_aes_operation
op,
125
struct
lws_gencrypto_keyelem
*el,
void
*engine);
126
127
LWS_VISIBLE
LWS_EXTERN
int
128
lws_genchacha_destroy
(
struct
lws_genchacha_ctx
*ctx);
129
145
LWS_VISIBLE
LWS_EXTERN
int
146
lws_genchacha_crypt
(
struct
lws_genchacha_ctx
*ctx,
147
const
uint8_t
*in,
size_t
len
,
uint8_t
*out,
148
const
uint8_t
*nonce,
149
const
uint8_t
*aad,
size_t
aad_len,
150
uint8_t
*tag,
size_t
tag_len);
151
164
LWS_VISIBLE
LWS_EXTERN
int
165
lws_genchacha_stream
(
struct
lws_genchacha_ctx
*ctx,
166
const
uint8_t
*in,
size_t
len
,
uint8_t
*out,
167
const
uint8_t
*nonce,
size_t
nonce_len);
168
170
171
#endif
lws_genchacha_ctx::engine
void * engine
Definition
lws-genchacha.h:120
lws_genchacha_ctx::native_ctx
struct lws_chacha_ctx native_ctx
Definition
lws-genchacha.h:117
lws_chacha_ctx::input
uint32_t input[16]
Definition
lws-genchacha.h:48
lws_genchacha_ctx::k
struct lws_gencrypto_keyelem * k
Definition
lws-genchacha.h:118
lws_genchacha_ctx::op
enum enum_aes_operation op
Definition
lws-genchacha.h:119
lws_chacha_encrypt_bytes
LWS_VISIBLE LWS_EXTERN void lws_chacha_encrypt_bytes(struct lws_chacha_ctx *x, const uint8_t *m, uint8_t *c, uint32_t bytes)
enum_aes_operation
enum_aes_operation
Definition
lws-genaes.h:53
lws_chacha_ivsetup
LWS_VISIBLE LWS_EXTERN void lws_chacha_ivsetup(struct lws_chacha_ctx *x, const uint8_t *iv, const uint8_t *counter)
LWS_POLY1305_KEYLEN
#define LWS_POLY1305_KEYLEN
Definition
lws-genchacha.h:94
lws_genchacha_crypt
LWS_VISIBLE LWS_EXTERN int lws_genchacha_crypt(struct lws_genchacha_ctx *ctx, const uint8_t *in, size_t len, uint8_t *out, const uint8_t *nonce, const uint8_t *aad, size_t aad_len, uint8_t *tag, size_t tag_len)
lws_genchacha_destroy
LWS_VISIBLE LWS_EXTERN int lws_genchacha_destroy(struct lws_genchacha_ctx *ctx)
lws_poly1305_auth
LWS_VISIBLE LWS_EXTERN void lws_poly1305_auth(uint8_t out[LWS_POLY1305_TAGLEN], const uint8_t *m, size_t inlen, const uint8_t key[LWS_POLY1305_KEYLEN])
lws_chacha_keysetup
LWS_VISIBLE LWS_EXTERN void lws_chacha_keysetup(struct lws_chacha_ctx *x, const uint8_t *k, uint32_t kbits)
LWS_POLY1305_TAGLEN
#define LWS_POLY1305_TAGLEN
Definition
lws-genchacha.h:93
lws_chacha_ivsetup_ietf
LWS_VISIBLE LWS_EXTERN void lws_chacha_ivsetup_ietf(struct lws_chacha_ctx *x, const uint8_t *nonce, uint32_t counter)
lws_genchacha_stream
LWS_VISIBLE LWS_EXTERN int lws_genchacha_stream(struct lws_genchacha_ctx *ctx, const uint8_t *in, size_t len, uint8_t *out, const uint8_t *nonce, size_t nonce_len)
lws_genchacha_create
LWS_VISIBLE LWS_EXTERN int lws_genchacha_create(struct lws_genchacha_ctx *ctx, enum enum_aes_operation op, struct lws_gencrypto_keyelem *el, void *engine)
lws_chacha_ctx
Definition
lws-genchacha.h:47
lws_genchacha_ctx
Definition
lws-genchacha.h:107
uint32_t
unsigned int uint32_t
Definition
libwebsockets.h:695
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:697
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-genchacha.h
Generated on
for libwebsockets by
1.18.0