authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-16 18:21:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-02 16:57:15-07:00
log8ef4dcd39f08a543f067a9820d82840dbf9d2ce5
tree17df02ee8540423e85799bf1e3d564661b83e194
parent942b5b468fe0a517618b62f0260d3a32c7cc642e

std.crypto.tls: add some benchmark data points

Looks like aegis-128l is the winner on baseline too.

1 files changed, 28 insertions(+), 16 deletions(-)

lib/std/crypto/tls/Client.zig+28-16
...@@ -23,22 +23,6 @@ partially_read_buffer: [tls.max_ciphertext_record_len]u8,...@@ -23,22 +23,6 @@ partially_read_buffer: [tls.max_ciphertext_record_len]u8,
23partially_read_len: u15,23partially_read_len: u15,
24eof: bool,24eof: bool,
2525
26// Measurement taken with 0.11.0-dev.810+c2f5848fe
27// on x86_64-linux Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz:
28// zig run .lib/std/crypto/benchmark.zig -OReleaseFast
29// aegis-128l: 15382 MiB/s
30// aegis-256: 9553 MiB/s
31// aes128-gcm: 3721 MiB/s
32// aes256-gcm: 3010 MiB/s
33// chacha20Poly1305: 597 MiB/s
34
35const cipher_suites =
36 int2(@enumToInt(tls.CipherSuite.AEGIS_128L_SHA256)) ++
37 int2(@enumToInt(tls.CipherSuite.AEGIS_256_SHA384)) ++
38 int2(@enumToInt(tls.CipherSuite.AES_128_GCM_SHA256)) ++
39 int2(@enumToInt(tls.CipherSuite.AES_256_GCM_SHA384)) ++
40 int2(@enumToInt(tls.CipherSuite.CHACHA20_POLY1305_SHA256));
41
42/// `host` is only borrowed during this function call.26/// `host` is only borrowed during this function call.
43pub fn init(stream: net.Stream, host: []const u8) !Client {27pub fn init(stream: net.Stream, host: []const u8) !Client {
44 const kp = crypto.dh.X25519.KeyPair.create(null) catch |err| switch (err) {28 const kp = crypto.dh.X25519.KeyPair.create(null) catch |err| switch (err) {
...@@ -713,3 +697,31 @@ inline fn int2(x: u16) [2]u8 {...@@ -713,3 +697,31 @@ inline fn int2(x: u16) [2]u8 {
713 @truncate(u8, x),697 @truncate(u8, x),
714 };698 };
715}699}
700
701/// The priority order here is chosen based on what crypto algorithms Zig has
702/// available in the standard library as well as what is faster. Following are
703/// a few data points on the relative performance of these algorithms.
704///
705/// Measurement taken with 0.11.0-dev.810+c2f5848fe
706/// on x86_64-linux Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz:
707/// zig run .lib/std/crypto/benchmark.zig -OReleaseFast
708/// aegis-128l: 15382 MiB/s
709/// aegis-256: 9553 MiB/s
710/// aes128-gcm: 3721 MiB/s
711/// aes256-gcm: 3010 MiB/s
712/// chacha20Poly1305: 597 MiB/s
713///
714/// Measurement taken with 0.11.0-dev.810+c2f5848fe
715/// on x86_64-linux Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz:
716/// zig run .lib/std/crypto/benchmark.zig -OReleaseFast -mcpu=baseline
717/// aegis-128l: 629 MiB/s
718/// chacha20Poly1305: 529 MiB/s
719/// aegis-256: 461 MiB/s
720/// aes128-gcm: 138 MiB/s
721/// aes256-gcm: 120 MiB/s
722const cipher_suites =
723 int2(@enumToInt(tls.CipherSuite.AEGIS_128L_SHA256)) ++
724 int2(@enumToInt(tls.CipherSuite.AEGIS_256_SHA384)) ++
725 int2(@enumToInt(tls.CipherSuite.AES_128_GCM_SHA256)) ++
726 int2(@enumToInt(tls.CipherSuite.AES_256_GCM_SHA384)) ++
727 int2(@enumToInt(tls.CipherSuite.CHACHA20_POLY1305_SHA256));