From 64a4de00fb65d97d68420ac908ba3962dfb97017 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Wed, 30 Jul 2025 12:45:10 +0100 Subject: [PATCH] Add some benchmarks for EC key agreement (#390) We should have some benchmarks for EC key agreement. --- Benchmarks/Benchmarks/Benchmarks.swift | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Benchmarks/Benchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/Benchmarks.swift index b7e2d241..b9b5ad55 100644 --- a/Benchmarks/Benchmarks/Benchmarks.swift +++ b/Benchmarks/Benchmarks/Benchmarks.swift @@ -158,4 +158,49 @@ let benchmarks = { blackHole(try privateKey.evaluate(blindedElement)) } } + + Benchmark( + "key-exchange-p256", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 10 + ) + ) { benchmark in + for _ in benchmark.scaledIterations { + let (key1, key2) = (P256.KeyAgreement.PrivateKey(), P256.KeyAgreement.PrivateKey()) + blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey)) + } + } + + Benchmark( + "key-exchange-p384", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 10 + ) + ) { benchmark in + for _ in benchmark.scaledIterations { + let (key1, key2) = (P384.KeyAgreement.PrivateKey(), P384.KeyAgreement.PrivateKey()) + blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey)) + } + } + + Benchmark( + "key-exchange-p521", + configuration: Benchmark.Configuration( + metrics: defaultMetrics, + scalingFactor: .kilo, + maxDuration: .seconds(10_000_000), + maxIterations: 10 + ) + ) { benchmark in + for _ in benchmark.scaledIterations { + let (key1, key2) = (P521.KeyAgreement.PrivateKey(), P521.KeyAgreement.PrivateKey()) + blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey)) + } + } }