Files
shadowsocks-libev/third_party
Max Lv 8d39cd7569 C++20 port 6/14: allocation-free AEAD codecs (#3070)
* 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.

* Include <algorithm> for std::min in test_crypto_aead_cpp.cpp

* Build the C++ AEAD codecs against Mbed TLS 2.x

Mbed TLS 2 returns void from mbedtls_sha1_starts/update/finish (the int
versions are the _ret variants), which the system-library build on
Ubuntu (2.28) rejects. crypto/mbedtls_compat.hpp gives one int-returning
spelling for both.

* Include C++ headers before crypto.h in test_crypto_aead_cpp.cpp

crypto.h defines min/max macros for the C sources; libstdc++ headers
included after it fail to parse.

* Disable the zero-allocation checks with a system Mbed TLS

They hold for the bundled Mbed TLS (MBEDTLS_BLOCK_CIPHER_C); a system
one may allocate in GCM key setup, as the Debian package build shows.
2026-10-15 09:56:12 +08:00
..

Bundled sources

dist/ contains unmodified upstream source release archives. manifest.json records upstream URLs, versions and SHA-256 hashes; CMake verifies hashes before extracting into the build tree. Configuration never downloads dependencies. These hashes pin downloaded content; they are not a claim of an independent signature verification.

  • Mbed TLS 3.6.7: Apache-2.0 OR GPL-2.0-or-later; see the archive's LICENSE files.
  • libsodium 1.0.22: ISC; see LICENSE in the archive.
  • c-ares 1.34.8: MIT; see LICENSE.md in the archive.
  • PCRE2 10.48: BSD-3-Clause; see LICENCE.md in the archive, including third-party notices.
  • libuv 1.52.1: MIT; see LICENSE in the archive, including third-party notices.
  • bloom: copied unchanged from the former shadowsocks/libbloom submodule, commit 437e1add5a2b9a87797d8c648df7cf5f3ee155a8. BSD-2-Clause; license and MurmurHash2 source notices retained alongside the sources.
  • BLAKE3 remains in src/blake3; its existing license files remain there.
  • uthash remains in src/uthash.h with its upstream copyright/license notice.

Mbed TLS, c-ares, libuv and PCRE2 use their upstream CMake builds. The local libsodium CMake adapter compiles the portable C backends listed in upstream Makefile.am; it is maintained by this project, not upstream. Upstream known-answer tests are built and run under the vendor CTest label. SIMD acceleration needs its own compiler probes and validation before enabling additional backends. On Windows, LibuvWindows.cmake applies a checked, idempotent fix to extracted libuv 1.52.1 CPU-info code: a mutable string temporary replaces an incompatible const char ** output argument rejected by GCC 14+. The archive is unchanged.

Libuv replaces libev. Its Windows socket polling uses AFD readiness requests completed through IOCP; macOS uses kqueue. The internal ss_event layer combines read/write watchers for each descriptor and owns libuv handle lifetime separately from connection objects. c-ares stays integrated into that loop for asynchronous A/AAAA resolution, custom DNS servers and cancellation. Native platform tests exercise the backend, concurrent watchers, delayed DNS completion and shutdown.

To update an archive: select a supported upstream release, download its release archive from the upstream source, verify published signatures/checksums where available, update manifest.json (including version-specific configuration in Sodium.cmake), and run bundled builds, vendor tests, project tests, sanitizers, and independent TCP/UDP interoperability on the supported platform matrix. Keep release archives and notices intact. Review upstream advisories and local adapter changes when selecting an update. System mode remains available to packagers who update libraries separately.