Repository navigation
Beryl 0.2.4: speed work and TCP_NODELAY
Speed on x86-64: AES-GCM, ChaCha20-Poly1305, SHA-512, RSA and P-256 on the processor's vector and wide-multiply instructions, chosen at run time; X25519 and Ed25519 on a four-word field on x86-64 and AArch64; TCP_NODELAY on accepted sockets; and one contract change: a failed decrypt(..., into:) now zeroes the buffer.
- x86-64 finds AVX2, AVX-512, AVX-512 IFMA, VAES, VPCLMULQDQ and MULX/ADX at
run time (CPUID leaf 7 and XCR0), and each algorithm below picks its path
from them.-Dberyl_without_avx2,-Dberyl_without_avx512and
-Dberyl_without_mulxforce the narrower paths. (#39) - RSA on x86-64: MULX/ADCX/ADOX Montgomery multiplication and squaring with
AVX2 constant-time table selection; with AVX-512 IFMA, both CRT
exponentiations run side by side for signing and decryption (2048, 3072 and
4096 bits) with a dedicated squaring. Secret exponents keep the 5-bit fixed
window with masked table reads. (#43, #45) - ChaCha20-Poly1305 on x86-64: AVX2 (8 blocks a pass) and AVX-512 (16 blocks
a pass) keystream and vector Poly1305, at least OpenSSL 3.0.13's speed on
every ubuntu-24.04 x86-64 runner model; SSE stays the fallback. (#44) - SHA-384, SHA-512 and SHA-512/256 (and HMAC over them) on x86-64: an AVX2
message schedule of two blocks at once and BMI2 rounds, with AVX-512
rotations where present. (#41) - AES-GCM opens messages under 240 bytes in one counter-mode call, as the
short seal does. (#47) Beryl::TLS::ServersetsTCP_NODELAYon everyTCPSocketit accepts;
Server#tcp_nodelay = falsekeeps Nagle on. Each WebSocket message goes
out as one record in one write, and with Nagle on, a small write waited
for the ACK of the one before it. On Linux, where the peer delays its ACK
up to 40 ms, a game relay writing about 34 small messages a second per
socket went from 38.7 ms to 3.6 ms p95 per message with the option set.- Contract change: a failed
decrypt(..., into:)now overwrites the
wholeinto:buffer with zeros, for every AEAD, at every length and on
every path; it used to leave the buffer untouched.decryptwithout
into:still returnsnil. The reason is speed: AES-GCM on x86-64 with
AVX-512 now decrypts while it hashes, in one pass, as OpenSSL does, so it
writes the buffer before the verdict; every path zeroes on failure so
that callers see one rule (Go'scrypto/cipherGCMOpendoes the
same). Beryl's TLS record layer opens into its own buffer and never read
it after a failure. - AES-GCM on x86-64 runs on VAES and VPCLMULQDQ: 512-bit registers with
AVX-512 (sealing and opening stitched in one loop), 256-bit registers
without (AMD Zen 3); AES-NI andpclmulqdqstay the fallback. - X25519 runs on four 64-bit words (fiat-crypto's
curve25519_solinas_64,
products reduced modulo 2^256 - 38), in assembly on x86-64 (mulx/adx,
elsemulq) and AArch64, each x86-64 ladder step one statement; the
randomized starting point stays. Against OpenSSL 3.0.13 on Linux, X25519
key agreement went from 0.87 to 1.06 times its speed on Xeon 6975P-C,
from 0.74 to 1.04 on EPYC 7763 and from 0.90 to 1.27 on Linux in Colima
on M4; 1.23 on macOS against OpenSSL 4.1.0. - Ed25519 verification uses ref10's double-scalar method with wider windows
on the same field: 2.2 to 2.8 times OpenSSL's speed on Linux (from 0.855
in Colima at 0.2.3), 3.48 on macOS. - P-256 on x86-64:
mulx/adcx/adoxfield multiplication reducing after
each row, assembly addition, subtraction and halving, AVX2 table
selection, and the point doubling, addition and window steps each as one
assembly statement. P-256 ECDH went from 0.80 to 1.11 times OpenSSL's
speed on Xeon 6975P-C and from 0.65 to 0.99 on EPYC 7763; it is 1.05 on
EPYC 9V74; at #42, before the follow-up below, it was still behind on
EPYC 9V45 (0.87) and Xeon Platinum 8573C (0.96). P-256 verification is 1.05 to 1.19 on every x86-64 model measured. - P-256 ECDH on x86-64: the window loop runs one copy of the point
doubling, never inlined, instead of five unrolled copies; themulx
multiplication and squaring take fewer instructions; the doubling's and
addition's steps are ordered so that a result passes to the next step in
registers, and scratch results no later step reads are not stored.
Against OpenSSL 3.0.13, ECDH went from 0.870 to 1.10 times its speed on
EPYC 9V45 (Zen 5), from 0.96 to 1.11 on Xeon Platinum 8573C and from
0.99 to 1.037 on EPYC 7763 (Zen 3).
Commit: 8b823baa2b3a15b4b19e0a95436523004d3a78d3
Tree: 311256ffc0db69e727c4c727e26fb25dd6fa7712
Tarball: beryl-0.2.4.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.4/ 8b823baa2b3a15b4b19e0a95436523004d3a78d3)
Tarball sha256: 356c8249f394cdcff8a61974f5fdbeeb677958a8ec4e58cb123ab9ce7ebde977
The tarball was built twice from the commit and gave the same sha256 both times, and the copy attached here was downloaded again and matched.