Files
shadowsocks-libev/third_party/mbedtls_config.h
Max Lv 556c1f0696 Add allocation-free C++ AEAD codecs
src/crypto/aead.hpp implements the SIP004/SIP007 AEAD ciphers as value
types: AeadEngine holds the libsodium or Mbed TLS GCM state by value,
AeadTcpEncryptor/AeadTcpDecryptor frame the chunk stream with a fixed
reassembly buffer, and aead_udp_seal/open handle packets. HKDF-SHA1 runs
on stack SHA-1 state instead of Mbed TLS's allocating HMAC API.

The bundled Mbed TLS config now enables MBEDTLS_BLOCK_CIPHER_C, which
keeps the AES context inside mbedtls_gcm_context, so GCM key setup no
longer allocates. That alone saves the C programs two allocations per
connection.

test_crypto_aead_cpp checks HKDF against RFC 5869 and crypto_hkdf, runs
TCP streams and UDP packets between the C and C++ implementations in
both directions for all five AEAD methods, and covers tampering,
framing and salt replay. alloc_steady_crypto_aead runs it under the
malloc counter and requires zero allocations across 600 new
connections and 600 packets (tests/alloc_audit/check_steady.py).

ss_strict_warnings() now applies -Wextra per source file so targets
mixing new C++ with converted C modules keep the latter at -Wall, and
Result gains move assignment.
2026-10-14 22:51:56 +08:00

37 lines
1.2 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef SS_MBEDTLS_CONFIG_H
#define SS_MBEDTLS_CONFIG_H
/* Only the primitives used by Shadowsocks. No TLS, X.509, networking, public
* key operations, PSA storage or independent entropy subsystem. Randomness
* is supplied by libsodium. MD5/SHA1 remain required by legacy AEAD key
* derivation even when legacy stream ciphers are disabled. */
#define MBEDTLS_AES_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_GCM_C
/* GCM on the block-cipher layer keeps the AES context inside
* mbedtls_gcm_context, so mbedtls_gcm_setkey() does not allocate. Mbed TLS
* only enables this by itself when MBEDTLS_CIPHER_C is off, and the legacy
* stream ciphers need MBEDTLS_CIPHER_C. */
#define MBEDTLS_BLOCK_CIPHER_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_VERSION_C
#define MBEDTLS_VERSION_FEATURES
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_CIPHER_MODE_CFB
#define MBEDTLS_CAMELLIA_C
#if defined(__x86_64__) || defined(_M_X64)
#define MBEDTLS_AESNI_C
#if defined(__GNUC__) || defined(__clang__)
#define MBEDTLS_HAVE_ASM
#endif
#endif
#if defined(__aarch64__)
#define MBEDTLS_AESCE_C
#endif
#endif