mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-26 10:43:43 +00:00
* Make the crypto, config, DNS and plugin modules compile as C++
Cast allocator and memchr results explicitly, pass mbedtls_operation_t
to mbedtls_cipher_setkey, and declare the two locals in
ss2022_encrypt_first() before the gotos that jump past them. Drop the
unused RESOLV_MODE global that resolv.c defined by accident through an
anonymous enum declaration. Still valid C.
* Raise the test origin's listen backlog
socketserver listens with a backlog of 5. With concurrent connections
through the proxy on a loaded machine (parallel ctest), the backlog
overflows, the kernel resets the origin connection, and the proxy
correctly drops the client, which surfaced as intermittent
alloc_audit_report failures ("getpeername: Invalid argument" in
ss-local, "Connection reset by peer" in ss-server). Reproduced
reliably at 64 concurrent connections; gone with a backlog of 256.
* Compile the crypto, config, DNS, ACL and plugin modules as C++
Rename netutils, jconf, stream, aead, aead2022, aead2022_udp, crypto,
acl, plugin, plugin_disabled and resolv from .c to .cpp without changing
their contents, and update source lists, snippet references, test
comments and debian/copyright.
The Doxygen source list and scripts/check_cli_docs.py now accept either
extension for each module, so the remaining programs can move one at a
time. The new .cpp files are added to the no-heap ratchet baseline.
85 lines
2.8 KiB
C
85 lines
2.8 KiB
C
/*
|
|
* aead_internal.h - Internal interface shared by aead.cpp and aead2022.cpp
|
|
*
|
|
* Copyright (C) 2013 - 2026, Max Lv <max.c.lv@gmail.com>
|
|
*
|
|
* This file is part of the shadowsocks-libev.
|
|
*
|
|
* shadowsocks-libev is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* shadowsocks-libev is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with shadowsocks-libev; see the file COPYING. If not, see
|
|
* <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _AEAD_INTERNAL_H
|
|
#define _AEAD_INTERNAL_H
|
|
|
|
#include "crypto.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* AEAD method identifiers (indexes into the supported_aead_ciphers tables) */
|
|
#define AES128GCM 0
|
|
#define AES192GCM 1
|
|
#define AES256GCM 2
|
|
#define AES128GCM2022 3
|
|
#define AES256GCM2022 4
|
|
/*
|
|
* methods above require a gcm context
|
|
* methods below don't require it,
|
|
* then we need to fake one
|
|
*/
|
|
#define CHACHA20POLY1305IETF 5
|
|
#define CHACHA20POLY1305IETF2022 6
|
|
|
|
#ifdef FS_HAVE_XCHACHA20IETF
|
|
#define XCHACHA20POLY1305IETF 7
|
|
#endif
|
|
|
|
static inline int
|
|
is_aead_2022(int method)
|
|
{
|
|
return method == AES128GCM2022 || method == AES256GCM2022
|
|
|| method == CHACHA20POLY1305IETF2022;
|
|
}
|
|
|
|
/* Low-level one-shot AEAD operations implemented in aead.cpp */
|
|
int aead_cipher_encrypt(cipher_ctx_t *cipher_ctx,
|
|
uint8_t *c, size_t *clen,
|
|
uint8_t *m, size_t mlen,
|
|
uint8_t *ad, size_t adlen,
|
|
uint8_t *n, uint8_t *k);
|
|
int aead_cipher_decrypt(cipher_ctx_t *cipher_ctx,
|
|
uint8_t *p, size_t *plen,
|
|
uint8_t *m, size_t mlen,
|
|
uint8_t *ad, size_t adlen,
|
|
uint8_t *n, uint8_t *k);
|
|
void aead_cipher_ctx_set_key(cipher_ctx_t *cipher_ctx, int enc);
|
|
|
|
/* AEAD-2022 pieces implemented in aead2022.cpp */
|
|
int aead_get_role(void);
|
|
void ss2022_derive_subkey(const uint8_t *key, size_t key_len,
|
|
const uint8_t *salt, size_t salt_len,
|
|
uint8_t *subkey, size_t subkey_len);
|
|
int ss2022_tcp_encrypt(buffer_t *plaintext, cipher_ctx_t *cipher_ctx,
|
|
size_t capacity);
|
|
int ss2022_tcp_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx,
|
|
size_t capacity);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // _AEAD_INTERNAL_H
|