Repository navigation
Releases
Beryl 0.2.5
MD5 at OpenSSL's speed or better on AMD Zen.
- MD5 holds each step's early sum behind an empty
asmbarrier, so on x86-64 the step's last addition stays a two-operandaddinstead of a three-operandlea, which takes two cycles on Zen. The barrier emits no instruction; on AArch64 the compiled steps keep the same instructions. At 1 MiB against OpenSSL (crimson-knight/grant run 46163811839), MD5 went from 0.86 to 1.06 times its speed on EPYC 7763 (Zen 3) and from 0.87 to 1.06 on EPYC 9V45 (Zen 5); Xeon 6975P-C was already there and measures 1.05 to 1.06. (#50)
Commit: cc0948fd41b9026ceed2a60e601b8e3088d9a6f2
Tree: 4c208fc48d770aa75a36942caeca90f814a761d0
Tag object: bbd92df6ca5c07b8d98cc98e20d3fb135467c93d
Tarball: beryl-0.2.5.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.5/ cc0948fd41b9026ceed2a60e601b8e3088d9a6f2)
Tarball sha256: 781859eb609900a0c3581306ac3623024f4bbcf8a83b706dfc93c0a0bb0a1fd2
The tarball was built twice from the commit and gave the same sha256 both times, and the copy attached here was downloaded again three times and matched each time.
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.
Beryl 0.2.3: client certificates (mutual TLS)
Client certificates (mutual TLS) in both directions.
- A TLS server can ask for client certificates (mutual TLS), off by default.
Context::Server#client_verify_mode=takesClientVerifyMode::None,
Optional(request; verify a chain when one is sent) orRequired(an
empty Certificate fails withcertificate_required);verify_mode = VerifyMode::Peermaps toRequired, as OpenSSL's server context takes it.
Client chains are verified toclient_ca_certificates=(PEM) or
client_trust_store=by the newClientCertificateVerifier(B4's
ChainVerificationwith purposeclientAuth, digitalSignature key usage,
no name check);client_certificate_verifier=replaces it. The
CertificateRequest lists the schemes Beryl verifies and the trust store's
root names (largest_certificate_authorities_bytesize, 16 KiB). The
client's CertificateVerify is checked with the client context string over
the transcript, and a bad signature ends the handshake with
decrypt_error. Socket::Server#peer_certificatereturns the client's leaf (nil when none
was asked for or sent), and#list_of_peer_certificates(alias
#peer_certificate_chain) the chain.- Session tickets record the client's chain (ticket format 2; a format 1
ticket gets a full handshake), so a resumed connection keeps its client
identity. A server that asks for certificates verifies the chain again on
resumption, and one that requires a certificate resumes only a session
that had one. - BoGo: the shim runs server
-verify-peer,-require-any-client-certificate,
-verify-fail,-expect-peer-cert-file,-expect-verify-resultand an
empty-use-client-ca-list; the TLS 1.3 server client-certificate tests
run and pass. tlsfuzzer runstest-tls13-certificate-request.py,
test-tls13-certificate-verify.py,
test-tls13-ecdsa-in-certificate-verify.pyand
test-tls13-eddsa-in-certificate-verify.py. The interop matrix adds
OpenSSL s_client and the Go client presenting client certificates to the
example server, which now takes--client-verify,--client-caand
--any-client-chain. - TLS client certificates (mutual TLS), client side.
Context::Client
gainscertificate_chain=(PEM chain, leaf first),private_key=
(PKCS #8, SEC 1 or PKCS #1),certified_key=andcertified_key?, shaped
likeOpenSSL::SSL::Context. On a CertificateRequest the client picks the
first signature scheme its key signs (P-256, RSA-PSS, Ed25519) that the
request lists, and sends its chain and a CertificateVerify signed with the
client context string (RFC 9846 §4.4.3) before its Finished. With no
certificate, or no scheme in common, it sends an empty Certificate as
before. A chain set without its key, or a key without its chain, raises
TLS::Errornaming the missing half. certificate_authorities is now
parsed (an empty or malformed list is a decode_error) and otherwise read
as information only. - BoGo: as a client the shim configures its certificate from
-cert-file
and-key-file, treats-use-old-client-cert-callbackas neutral, and
runs-verify-fail,-expect-verify-result,-expect-peer-cert-file
and-require-any-client-certificatethe way BoringSSL's shim does (its
verify callback accepts any chain unless-verify-fail; the
CertificateVerify signature is always checked). The client-side TLS 1.3
ClientAuth, CertificateAuthorities, SignatureAlgorithms and
CertificateVerification tests now run and pass (727 passed, up from 631);
the TLS 1.2 variants they uncovered are disabled with the TLS 1.2 reason,
and six TLS 1.3 SignDefault tests where BoringSSL aborts but Beryl sends
an empty Certificate are disabled with that reason. - Interop:
examples/https_client.crtakes--certificate-chainand
--private-key; the matrix presents P-256, RSA and Ed25519 client
certificates toopenssl s_server -Verify 1and to a Go server with
tls.RequireAndVerifyClientCert(go_peer server -client-ca), each of
which reports the verified subject.
Commit: 357b10ad61fdc0d795e1e390200ce3cdad6e2bfa
Tree: 326b2be3c3f9c2869f6a0dceca293d63459065fb
Tarball: beryl-0.2.3.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.3/ 357b10ad61fdc0d795e1e390200ce3cdad6e2bfa)
Tarball sha256: 4ed99b3cc22ecef6d08ad5d3f7074286f2cadafae90a69176a2609b5ee2703d9
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.
Beryl 0.2.2
Memory and polish for HTTPS servers: a --tls Amber app under 32 keep-alive
connections peaks at 15.8 to 19.6 MiB, down from 17.6 to 25.2 MiB on 0.2.1.
- A TLS socket keeps about 8 KiB per connection instead of about 103 KiB.
The record layer reads ahead into its own buffer, sized to the first record
and doubled only when a larger record arrives, up to the record limits; it
turns off read buffering on theIO::Bufferedbeneath it.TLS::Socket
reads straight from the opened record, soIO::Bufferedallocates no read
buffer, and writes gather in a small growable buffer sealed atflush, when
a record fills, or atclose.flush_on_newlineis honored. Handshake
reassembly storage is released once no message is waiting, and a server
socket wipes its resumption master secret when the handshake ends (#34). TLS::RecordProtection#wipenow also zeroes the AEAD's key material:
AES-GCM's expanded round keys and GHASH key state (H to H^8 on the
processor instructions), and the ChaCha20-Poly1305 key. Every
AuthenticatedEncryptiongainswipeandis_wiped?; once wiped, every
encryption, decryption and tag check raisesCrypto::KeyWiped. The check
is one branch on public state at each call, outside the per-block loops.- A certificate signed with SHA-1 (sha1WithRSAEncryption, ecdsa-with-SHA1,
dsa-with-SHA1) or MD5 is refused by its algorithm identifier, before any
signature check, with a message that names the hash: "the certificate for
CN=... is signed with SHA-1, which Beryl refuses (RFC 9155)". The new
FailureReason::SignatureAlgorithmRefusedmaps to the bad_certificate
alert in TLS. A SHA-1 CertificateVerify scheme, should one be configured,
raises with illegal_parameter and the same wording. scripts/fetch_vectors.rbaccepts manifest entries of kindgenerated:
fixtures made by a script in this repository, committed and pinned by
sha256 rather than downloaded. The first is
spec/vectors/beryl/sha1_signed_chains.pem, from
scripts/generate_sha1_signed_chains.sh(OpenSSL 4.1.0 pinned by version
and binary sha256).
Checks at the tagged commit
Release PR #35 on GitHub Actions; its head e46bf1b passed run 45699664111: 19 jobs green, one on-request job skipped. The merge commit has the same tree as the tested head (6e900023). main requires all 19 checks.
Measured for relay chunk B1 (M1 Max, wrk 4.2.0 pinned, 32 keep-alive connections): an Amber --tls app peaks at 15.8 to 19.6 MiB on 0.2.2 against 17.6 to 25.2 MiB on 0.2.1 and about 28 to 31 MiB with OpenSSL. testssl.sh 3.2.5 against an Amber --tls app: 0 critical, high or medium findings, grade A+.
Commit: 8ba496ec6dec614435e3dd8ac30fbf20e2d90e36
Tree: 6e900023799a4ec4b36c8d0983b5027108f62afc
Tarball: beryl-0.2.2.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.2/ 8ba496ec6dec614435e3dd8ac30fbf20e2d90e36)
Tarball sha256: 15cacec959287134d9230620ced5b3f559ed9b7fc8e3331c81ecddcb034fa791
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.
Beryl 0.2.1
For the Amber stack's Beryl adoption release: connection pools and private
database CAs.
- Certificate verification accepts a leaf or intermediate without an
authority key identifier: the issuer is found by name and tried by
signature, as Go's crypto/x509 and OpenSSL do, so private CAs for
PostgreSQL and MySQL that omit the extension verify. The path-building
limits still apply. x509-limbo:rfc5280::aki::leaf-missing-akiand
rfc5280::aki::intermediate-missing-akiare now listed as departures,
with the reason; every other case still matches. - On macOS,
TrustStore.systemjoins the pinned Mozilla roots to
/etc/ssl/cert.pem, unlessSSL_CERT_FILEis set. The file trails the
keychain the system actually trusts: macOS 27.2.1's copy lacks SSL.com TLS
ECC Root CA 2022 and AAA Certificate Services, so clients that use the
system store (HTTP::Client on Beryl, Grant's PostgreSQL driver,
crystal-mysql) refused www.example.com. Linux bundles are read as before. TLS::Socket#closed?answers whetherclosewas called, as
OpenSSL::SSL::Socket#closed?does, andcloseis idempotent. Reads and
writes aftercloseraiseIO::Error("Closed stream"), so database pools
andHTTP::Clientsee a closed TLS connection the way they see any other.
Checks at the tagged commit
Release PRs #31 and #32 on GitHub Actions; the tagged commit's own PR head edabff6 passed run 45545620346: 19 jobs green (specs, published vectors and the no-OpenSSL linkage proof; differentials against libcrypto on ubuntu-24.04 and ubuntu-24.04-arm; constant-time and timing checks including RSA at 2,048, 3,072 and 4,096 bits; Linux on AArch64; TLS against BoringSSL's BoGo, tlsfuzzer's TLS 1.3 scripts, OpenSSL, curl and Go; the TLS handshake fuzzer). x509-limbo: 9,793 run, every one matching except 14 listed skips. The merge commit has the same tree as the tested head. main requires all 19 checks.
Commit: 6afec738aac1aeefc016b0ba826d8d9f0acc3541
Tree: 72cd3de3531a7c8ac546f7fcfc563f345ddf1170
Tarball: beryl-0.2.1.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.1/ 6afec738aac1aeefc016b0ba826d8d9f0acc3541)
Tarball sha256: df6290dbf2341c3d099ad23a2060ae83dc8121009f84abf3e3823c88b2e70f62
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.
Beryl 0.2.0
TLS 1.3, client and server, in pure Crystal. A program that serves or
fetches HTTPS through Beryl links no OpenSSL. TLS 1.3 is the only version
Beryl speaks.
- TLS 1.3 (#21 to #25): the key schedule and transcript hash, the record
layer, the client and server state machines,Beryl::TLS::Context,
SocketandServershaped likeOpenSSL::SSL, session tickets and PSK
resumption (psk_dhe_keonly), HelloRetryRequest, ALPN, SNI, KeyUpdate,
record_size_limit, GREASE, and certificate verification through
Beryl::Certificateswith name and IP checks against the Mozilla roots
or a trust store of the program's choosing. Gates: RFC 8448 traces byte
for byte, BoGo (every applicable TLS 1.3 test), tlsfuzzer's TLS 1.3
scripts, interop with OpenSSL 4.1.0, curl 8.23.0 and Go 1.27.4 in both
roles, and a handshake fuzzer, all in CI. Guide:docs/tls.md. - Security review follow-ups (#26), from the independent review of the
TLS code (M4, L1, L2, L3, L5, L6, L8):- Handshakes wipe every secret they derive in an
ensure, including on
failure; connections wipe the traffic, exporter and resumption master
secrets and the record IVs at close and after a failure (M4). - A plaintext alert read while keys are installed raises
UnauthenticatedAlertinstead of passing as the peer's alert (L1). - Duplicate extensions and key shares are found with sets, so a
ClientHello of many entries is checked in linear time (L2). - change_cipher_spec is refused before the first ClientHello and between
the fragments of a handshake message (L3). - A ticket issued in the future is never resumed (L5).
- A client ticket records the certificate verifier of its connection and
is offered only by a context with the same verifier (L6). - A sending key moves on with an automatic KeyUpdate after
Limits#largest_record_count_per_keyrecords (16,777,216 by default);
Context::Server#session_ticket_count=accepts 0 to 16 (L8). - The client sends its own
record_size_limit(RFC 8449) and the server
answers with its own; both come fromLimits#record_size_limitand
are enforced on what each end reads once both sent one.
- Handshakes wipe every secret they derive in an
- HTTP::Server seam (#27): sockets accepted by
Beryl::TLS::Server
raise TLS failures from reads and writes asConnectionFailed < IO::Error,
soHTTP::Server#bind(Beryl::TLS::Server.new(tcp_server, context))ends a
client whose handshake fails without an unhandled exception
(Socket#is_raising_io_errors=). - Record layer speed (F4, first step) (#30): each connection reuses its
record buffers (grown to the largest record seen) instead of allocating
two per record read and two per record written. On an Amber app over
HTTPS (wrk, 32 connections, M1 Max) this took requests per second from
about 65,000 to 79,000 on a small page, ahead of the same app on OpenSSL
(71,000). - System trust store (#28):
TrustStore.systemreadsSSL_CERT_FILE,
as OpenSSL and Go do. Beryl::VERSIONreads 0.2.0.- Handshakes wipe every secret they derive in an
ensure, including on
failure; connections wipe the traffic, exporter and resumption master
secrets and the record IVs at close and after a failure (M4). - A plaintext alert read while keys are installed raises
UnauthenticatedAlertinstead of passing as the peer's alert (L1). - Duplicate extensions and key shares are found with sets, so a
ClientHello of many entries is checked in linear time (L2). - change_cipher_spec is refused before the first ClientHello and between
the fragments of a handshake message (L3). - A ticket issued in the future is never resumed (L5).
- A client ticket records the certificate verifier of its connection and
is offered only by a context with the same verifier (L6). - A sending key moves on with an automatic KeyUpdate after
Limits#largest_record_count_per_keyrecords (16,777,216 by default);
Context::Server#session_ticket_count=accepts 0 to 16 (L8). - The client sends its own
record_size_limit(RFC 8449) and the server
answers with its own; both come fromLimits#record_size_limitand
are enforced on what each end reads once both sent one.
- Handshakes wipe every secret they derive in an
- HTTP::Server seam (#27): sockets accepted by
Beryl::TLS::Server
raise TLS failures from reads and writes asConnectionFailed < IO::Error,
soHTTP::Server#bind(Beryl::TLS::Server.new(tcp_server, context))ends a
client whose handshake fails without an unhandled exception
(Socket#is_raising_io_errors=). Beryl::VERSIONreads 0.2.0.
Checks at the tagged commit
Release PR #30 on GitHub Actions, run 45508940460: 19 jobs green (specs, published vectors and the no-OpenSSL linkage proof; differentials against libcrypto on ubuntu-24.04 and ubuntu-24.04-arm; constant-time and timing checks including RSA at 2,048, 3,072 and 4,096 bits; Linux on AArch64; TLS against BoringSSL's BoGo, tlsfuzzer's TLS 1.3 scripts, OpenSSL, curl and Go; the TLS handshake fuzzer). The merge commit has the same tree as the tested head.
Commit: 36bf6b5c5fb06041d9f9e96f7eaf9344aaa48cd5
Tree: 746c331161a07ebe8f1a196f29e808045cc4570a
Tarball: beryl-0.2.0.tar.gz (git archive --format=tar.gz --prefix=beryl-0.2.0/ v0.2.0)
Tarball sha256: 7397eea11d9d40fd6aa55f767901835b49121f2ae64c64077d97b3ab24a2a6cb
Beryl v0.1.0
The first release: cryptography for Amber V2 in pure Crystal. A program
that uses Beryl links no OpenSSL. TLS is not in this release.
- Hashes and MACs (#1): SHA-224, SHA-256, SHA-384, SHA-512,
SHA-512/256, HMAC and HKDF; MD5, SHA-1 and PBKDF2 for existing formats.
On the processor's SHA instructions where it has them (#3). - Ciphers and AEADs (#2): XChaCha20-Poly1305, ChaCha20-Poly1305 and
AES-GCM; AES-CBC for existing formats. On the processor's cipher
instructions where it has them (#4). - Public key (#6, #7): X25519, Ed25519, P-256 ECDSA (RFC 6979 nonces)
and ECDH, P-384 ECDSA verification, and RSA (PKCS #1 v1.5 and PSS
signatures, OAEP encryption, 2,048 to 4,096-bit private keys). Field
arithmetic follows fiat-crypto's output, with assembly on arm64 and
x86-64 (#11, #13, #14, #15). - Certificates (#10): X.509 parsing and path validation
(Beryl::Certificates.verify_server_chain). - Timing: on Arm every operation on a secret runs with Data Independent
Timing on (#9); on x86-64 the curve multiplications take fresh operands
in every window, gated by a two-of-three timing check in CI (#18). - One API that picks the algorithm:
Beryl::Cryptouses the algorithm
Beryl recommends today,Beryl::Crypto::V1names each one, and
Beryl::Crypto::Compatibilityholds the old ones existing formats need. - Vendoring: rooted
::Beryl::references move under the host's
namespace when Beryl is vendored (#5). - Speed against OpenSSL, measured per operation, is in the README and
docs/(#8, #12, #17). Beryl::VERSIONreads 0.1.0.
Checks at the tagged commit
Release PR #20 (no code changes) on GitHub Actions, run 45465280680: 15 jobs green (specs, published vectors and the no-OpenSSL linkage proof; differentials against libcrypto on ubuntu-24.04 and ubuntu-24.04-arm; Valgrind and compiled-code constant-time checks; timing checks for HMAC, the ciphers, the curves and RSA at 2,048, 3,072 and 4,096 bits; Linux on AArch64). The merge commit has the same tree as the tested head.
Commit: 2c56823597f43e624317f55eb4d6822cc538cb71
Tree: 49f451dc737f07f7979c2bb433085ffdc21e04e4
Tarball: beryl-0.1.0.tar.gz (git archive --format=tar.gz --prefix=beryl-0.1.0/ v0.1.0)
Tarball sha256: 0dbcd1e9a31f65ad33d723c5a3411dfc30828c9b5672cdf3eef38194f5c3d5a6