Commit Graph
49 Commits
Author SHA1 Message Date
Max Lv 201e70c4bd Modernize C builds with offline dependencies and portable runtime helpers (#3050)
Bundle pinned offline dependencies, remove libcork/libipset and submodule requirements, and add portable runtime helpers with relocatable static/shared library installations.

Add Clang static build validation for Linux/musl, macOS and Windows, real TCP/UDP and SIP003 interoperability coverage, and recorded performance tradeoffs. All 21 hosted checks pass at the reviewed PR head 8d504e6218.
2026-09-11 13:42:11 +08:00
Max Lv 46791234c0 Add Shadowsocks 2022 (SIP022) ciphers
shadowsocks-rust has supported the 2022 edition for years while libev was
stuck on the 2017 AEAD construction, the largest functional gap between
the two implementations. This adds the three SIP022 methods:

  2022-blake3-aes-128-gcm
  2022-blake3-aes-256-gcm
  2022-blake3-chacha20-poly1305

TCP uses BLAKE3 derive_key for session subkeys, standalone header chunks
carrying a type byte and timestamp, request padding, and a response header
echoing the request salt. Replay protection uses an exact-match salt pool
with 60s retention rather than the bloom filter, which SIP022 forbids
because false positives are unacceptable there.

UDP is session-based: an AES-ECB separate header for the AES methods and a
merged XChaCha20-Poly1305 construction for ChaCha, with a per-session
sliding window replay filter. Servers must route by client session ID,
which is only known after decryption, so the crypto layer owns the
server-side session table and hands the session back to udprelay for the
reply path.

The 2022 code lives in aead2022.c and aead2022_udp.c so aead.c keeps its
current size, with aead_internal.h carrying what they share. BLAKE3 is
vendored (portable backend only) as its own build target.

Keys are base64 pre-shared keys of exactly the cipher's key size; per
SIP022 a password is never stretched into a key.

Verified interoperable in both directions against shadowsocks-rust 1.24.0
for all three ciphers over TCP and UDP, including an 8MB transfer checked
by digest, plus unit tests for header framing, partial delivery, tamper
detection, and UDP replay rejection.
2026-08-19 18:15:35 +08:00
Max Lv 5559eec939 Harden security-sensitive input handling (#3045)
* harden security-sensitive input handling

* enable ctest failure checks in ci

* add valgrind leak smoke tests

* split tests into separate workflow
2026-07-15 11:10:24 +08:00
Max Lv 9292a30225 Merge pull request #3017 from ayuusweetfish/mbedtls3-aesgcm
Fix failed assertion with Mbed TLS 3
2026-06-17 11:26:35 +08:00
Max LvandClaude Opus 4.6 ff44361f5d Fix unbounded buffer growth in aead_decrypt chunk reassembly
The idx-tracking optimization in aead_decrypt skipped memmove when
partial AEAD chunks spanned multiple calls, but never compacted the
dead space before idx. This caused the chunk buffer to grow
proportionally to total data transferred (~10 MB growth per 10 MB
transferred), tripping the stress test memory leak threshold.

Compact residual data to the front when appending new ciphertext,
keeping the buffer bounded to the size of the residual plus new data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 09:04:58 +08:00
Max LvandClaude Opus 4.6 31731baa44 Reduce memory copies in crypto encrypt/decrypt paths
Add bswap_data() to swap buffer pointers instead of copying, replace
brealloc+memcpy with pointer swaps in aead and stream codecs, add
in-place fast paths for non-Salsa20 stream ciphers, and use index
tracking instead of memmove in aead_decrypt chunked reassembly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 08:53:28 +08:00
Ayu 60ad4ca4b5 Fix failed assertion with Mbed TLS 3 2026-01-18 16:59:48 +08:00
Lu jicongandZxl hhyccc 9afa3cacf9 Fix in 'mbedtls 3.6.0 ver' compilation failure issue
Fix mbedtls 3.6 compatibility

Co-authored-by: Zxl hhyccc <zxlhhy@gmail.com>
Signed-off-by: Lu jicong <jiconglu58@gmail.com>
2025-01-20 11:11:47 +08:00
babarosaM33 30d5b85fe7 Revert "ppbloom:remove unnecessay bloom_check"
ppbloom_add only checks current bloom filter not both PING PONG filters

This reverts commit 9ae59819be.
2020-01-29 16:09:10 +08:00
babarosaM33 9576dcea54 initialize after pass check
if check failes, no need to initialize crypto.
2020-01-13 13:39:02 +08:00
babarosaM33 9ae59819be ppbloom:remove unnecessay bloom_check
bbloom_add and bbloom_check are in fact the same function.
let's make bbloom_add return collision information.
2020-01-13 13:24:52 +08:00
babarosaM33 7fe555c756 Remove unnecessary memmove
Before patch, after one chunk decoded, we do a memmove.
After patch, after all complete chunk decoded, we do a memmove.
2020-01-08 04:33:35 +08:00
Max Lv 9109b63aaa Avoid confusion of the return value of aead_cipher_decrypt() 2019-09-21 08:34:54 +08:00
Max Lv 64b97cd9a3 Clean up 2019-07-17 09:16:06 +08:00
Max Lv 6c28add775 Enable -Wcas-align for #2412 2019-06-30 21:34:35 +08:00
Chinsyo 7bd382042b bump copyright year 2019-03-21 12:39:29 +08:00
Max Lv 782311ad2b Refine ss_align interfaces 2019-01-22 12:59:29 +08:00
Max Lv 569570cfa9 Fix #2215 2018-11-13 21:31:34 +08:00
Max Lv 92cab3503c Add check for reusing server's nonce/salt 2018-10-19 09:01:39 +08:00
Max Lv ed7c1e64af Fix a compilation issue for GCC < 5.0 2018-09-13 14:20:07 -07:00
edsgerlin 761e66a969 Implement AES256-GCM with precomputation. 2018-09-12 02:14:11 +09:00
edsgerlin 79592a8b16 Use libsodium for aes-256-gcm when available. 2018-09-12 00:52:33 +09:00
Yegor Ievlev 8fd83e2686 Use chacha20-ietf as a default cipher instead of rc4-md5 (#2080)
* Use chacha20-ietf as a default cipher instead of rc4-md5

* Update tunnel.c

* Update utils.c

* Update ss-local.asciidoc

* Update ss-local.asciidoc

* Update tunnel.c

* Update ss-tunnel.asciidoc

* Update ss-manager.asciidoc

* Update ss-redir.asciidoc

* Update shadowsocks-libev.asciidoc

* Update aead.c

* Update local.c

* Update server.c

* Update utils.c
2018-06-07 08:58:10 +08:00
Linus Yang 2ed8791dab Re-add support for MinGW 2018-03-08 17:26:11 +08:00
Max Lv 26e06a7a1d Fix #1948 2018-02-27 21:14:16 +08:00
Max Lv 85a64ae836 Bump version 2018-01-15 17:25:03 -08:00
星野ハジメ cc1bb4cf62 format with .uncrustify.cfg (#1759)
* format with .uncrustify.cfg

format with .uncrustify.cfg

* format with .uncrustify.cfg

* format with .uncrustify.cfg exclude json.* base64.* uthash.h

* format with .uncrustify.cfg exclude json.* base64.* uthash.h
2017-10-30 21:28:53 +08:00
Max Lv bf8f8312b4 Refine the ppbloom filter 2017-07-21 19:54:00 +08:00
Max Lv 4b1550626f Update specs 2017-05-27 09:34:55 +08:00
Syrone Wong b74108db09 drop redundant sodium_init() call
It is done in crypto.c

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-03-19 17:16:19 +08:00
Max Lv a4bebe3ee9 Refine assertion 2017-03-09 11:15:36 +08:00
Max Lv b655fb2b8f Replace nonce cache with a ping-pong bloom filter (#1282)
* Add Ping-Pong bloom filter

* Refine bloom filter insertion

* Reduce the error rate to 0.00001

* Avoid alignment issue in murmurhash2

* Fix a memory leak

* Fix build on non-GPU targets

* Detect get_current_dir_name in configure

* Update README.md

* Remove redudant bfree()

* Reduce the memory usage for local client

* Fix #1275

* Refine #1275

* Use IP when bypassing SNI domains

* Also apply replay detector on UDP traffic

* Update deb build script

Now build script is able to auto detect system and choose libraries
necessary to build.

Also update the README accordingly.

* Update build script to enable jessie/stretch etc

Also include a few cleanup that simplified pkg installation from
backports repository.
2017-02-20 10:29:32 +08:00
Max Lv d434cd20ec Fix a memory leak 2017-02-17 12:31:22 +08:00
Syrone Wong 80ca9469e6 Output error log when repeat IV/salt detected
This is useful when checking connection issues, and can be used to
check broken random number generator and replay attacks.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-02-14 19:41:46 +08:00
Max Lv 8a34b3ea0b Rename DEBUG to SS_DEBUG 2017-02-13 13:16:57 +08:00
Max Lv 6520f340bb Fix #1240 2017-02-12 20:15:22 +08:00
Max Lv 6c62647a66 Add session key following SIP007 2017-02-12 16:34:42 +08:00
Max Lv d1018e4ca5 Ignore empty payload 2017-02-11 09:12:02 +08:00
Max Lv c5c8389a8d Fix data len 2017-02-06 18:03:05 +08:00
Max Lv c9d7ff16d6 Fix a typo 2017-02-06 17:26:58 +08:00
Max Lv ef0402eb10 Add --key option to set key directly (#1207) 2017-02-06 17:02:04 +08:00
Dijkstra 43aabb2303 Fix typo. (#1206) 2017-02-06 16:33:21 +08:00
Max Lv 894eae567c Refine ciphers 2017-02-04 20:04:48 +08:00
Max Lv a906d0cfc8 Fix UDP relay issue on Android 2017-02-03 12:33:28 +08:00
Max Lv 05d5121707 Fix typos for endian 2017-01-31 18:51:52 +08:00
Max Lv 32057ed3c5 Fix key sizes 2017-01-31 16:22:33 +08:00
Max Lv c89f5f3f3f Limit the max payload length to 0x3FFF 2017-01-30 19:03:41 +08:00
Max Lv e18f71b03f Add Argon2i password hashing for AEAD 2017-01-29 17:41:39 +08:00
Max Lv 4ebe5aeb12 Add SIP004 (AEAD) support 2017-01-29 10:10:44 +08:00