libwebsockets
Lightweight C library for HTML5 websockets
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#if !defined(LWS_HAVE_MBEDTLS_V4)
32#include <mbedtls/chachapoly.h>
33#else
34#include <psa/crypto.h>
35#endif
36#endif
37
44
45#define LWS_CHACHA_MINKEYLEN 16
46#define LWS_CHACHA_NONCELEN 8
47#define LWS_CHACHA_CTRLEN 8
48#define LWS_CHACHA_STATELEN (LWS_CHACHA_NONCELEN+LWS_CHACHA_CTRLEN)
49#define LWS_CHACHA_BLOCKLEN 64
50
53};
54
64
73lws_chacha_ivsetup(struct lws_chacha_ctx *x, const uint8_t *iv, const uint8_t *counter);
74
83lws_chacha_ivsetup_ietf(struct lws_chacha_ctx *x, const uint8_t *nonce, uint32_t counter);
84
95
96
97#define LWS_POLY1305_TAGLEN 16
98#define LWS_POLY1305_KEYLEN 32
99
110
112#if defined(LWS_WITH_MBEDTLS)
113 union {
114 mbedtls_chachapoly_context cp;
115 mbedtls_cipher_context_t cipher;
116 } u;
117#elif defined(LWS_WITH_OPENSSL)
118 EVP_CIPHER_CTX *ctx;
119#endif
120 /* fallback native ctx */
124 void *engine;
125};
126
129 struct lws_gencrypto_keyelem *el, void *engine);
130
133
151 const uint8_t *in, size_t len, uint8_t *out,
152 const uint8_t *nonce,
153 const uint8_t *aad, size_t aad_len,
154 uint8_t *tag, size_t tag_len);
155
170 const uint8_t *in, size_t len, uint8_t *out,
171 const uint8_t *nonce, size_t nonce_len);
172
174
175#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:57
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