libwebsockets
Lightweight C library for HTML5 websockets
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
49};
50
60
69lws_chacha_ivsetup(struct lws_chacha_ctx *x, const uint8_t *iv, const uint8_t *counter);
70
79lws_chacha_ivsetup_ietf(struct lws_chacha_ctx *x, const uint8_t *nonce, uint32_t counter);
80
91
92
93#define LWS_POLY1305_TAGLEN 16
94#define LWS_POLY1305_KEYLEN 32
95
106
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 */
120 void *engine;
121};
122
125 struct lws_gencrypto_keyelem *el, void *engine);
126
129
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
166 const uint8_t *in, size_t len, uint8_t *out,
167 const uint8_t *nonce, size_t nonce_len);
168
170
171#endif
struct lws_chacha_ctx native_ctx
uint32_t input[16]
struct lws_gencrypto_keyelem * k
enum enum_aes_operation op
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
Definition lws-genaes.h:53
LWS_VISIBLE LWS_EXTERN void lws_chacha_ivsetup(struct lws_chacha_ctx *x, const uint8_t *iv, const uint8_t *counter)
#define LWS_POLY1305_KEYLEN
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_VISIBLE LWS_EXTERN int lws_genchacha_destroy(struct lws_genchacha_ctx *ctx)
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_VISIBLE LWS_EXTERN void lws_chacha_keysetup(struct lws_chacha_ctx *x, const uint8_t *k, uint32_t kbits)
#define LWS_POLY1305_TAGLEN
LWS_VISIBLE LWS_EXTERN void lws_chacha_ivsetup_ietf(struct lws_chacha_ctx *x, const uint8_t *nonce, uint32_t counter)
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_VISIBLE LWS_EXTERN int lws_genchacha_create(struct lws_genchacha_ctx *ctx, enum enum_aes_operation op, struct lws_gencrypto_keyelem *el, void *engine)
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE