Compare commits

...
2 Commits
Author SHA1 Message Date
Cory Benfield 176abc28e0 Cache curves to avoid repeatedly reallocating state (#391)
Motivation

We shouldn't repeatedly reconstruct static data

Modifications

- Turn the groups into static lets instead of computed properties

Result

Fewer allocations
2025-07-30 11:53:08 +00:00
Cory Benfield 64a4de00fb Add some benchmarks for EC key agreement (#390)
We should have some benchmarks for EC key agreement.
2025-07-30 12:45:10 +01:00
2 changed files with 51 additions and 12 deletions

No files matched your search

+45
View File
@@ -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))
}
}
}
@@ -36,26 +36,20 @@ extension OpenSSLSupportedNISTCurve {
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension P256: OpenSSLSupportedNISTCurve {
@inlinable
static var group: BoringSSLEllipticCurveGroup {
try! BoringSSLEllipticCurveGroup(.p256)
}
@usableFromInline
static let group = try! BoringSSLEllipticCurveGroup(.p256)
}
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension P384: OpenSSLSupportedNISTCurve {
@inlinable
static var group: BoringSSLEllipticCurveGroup {
try! BoringSSLEllipticCurveGroup(.p384)
}
@usableFromInline
static let group = try! BoringSSLEllipticCurveGroup(.p384)
}
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension P521: OpenSSLSupportedNISTCurve {
@inlinable
static var group: BoringSSLEllipticCurveGroup {
try! BoringSSLEllipticCurveGroup(.p521)
}
@usableFromInline
static let group = try! BoringSSLEllipticCurveGroup(.p521)
}
@usableFromInline