mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 14:33:55 +00:00
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.
34 lines
740 B
C++
34 lines
740 B
C++
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
#ifndef SS_ALLOC_PROBE_HPP
|
|
#define SS_ALLOC_PROBE_HPP
|
|
|
|
// Mark points in a test program for tests/alloc_audit/check_steady.py.
|
|
//
|
|
// When the alloc_counter shim is preloaded (it sets SS_ALLOC_AUDIT_OUT and
|
|
// handles SIGUSR2), each mark appends the running allocation count to the
|
|
// audit file. Without the shim the marks do nothing, so the same test binary
|
|
// also runs normally.
|
|
|
|
#include <csignal>
|
|
#include <cstdlib>
|
|
|
|
namespace ss::test {
|
|
|
|
inline bool alloc_audit_enabled()
|
|
{
|
|
return std::getenv("SS_ALLOC_AUDIT_OUT") != nullptr;
|
|
}
|
|
|
|
inline void alloc_mark()
|
|
{
|
|
#ifdef SIGUSR2
|
|
if (alloc_audit_enabled()) {
|
|
std::raise(SIGUSR2);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
} // namespace ss::test
|
|
|
|
#endif
|