mirror of
https://github.com/apple/swift-crypto
synced 2026-11-26 04:47:49 +00:00
## Motivation The ARC IETF draft has been updated to now support P256 and drop support for P384. ## Modifications - Update the internal ARC implementation to accommodate multiple curves - Add API surface for P256 - Deprecate API for P384 - Add tests for P256 with test vectors from the draft - Move over the end-to-end API tests to P256 - Add benchmarks for P256 ## Result - New API `P256._ARCV1`, which provides an implementation of ARC(P-256). - Deprecate `P384._ARCV1`, which provides an implementation of ARC(P-256). [^1]: https://chris-wood.github.io/draft-arc/draft-yun-cfrg-arc.html#name-arcv1-p256 --------- Co-authored-by: Cory Benfield <lukasa@apple.com>
162 lines
5.7 KiB
Swift
162 lines
5.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftCrypto open source project
|
|
//
|
|
// Copyright (c) 2025 Apple Inc. and the SwiftCrypto project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
import Benchmark
|
|
import Crypto
|
|
import Foundation
|
|
import _CryptoExtras
|
|
|
|
let benchmarks = {
|
|
let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal]
|
|
|
|
Benchmark(
|
|
"arc-issue-p256",
|
|
configuration: Benchmark.Configuration(
|
|
metrics: defaultMetrics,
|
|
scalingFactor: .kilo,
|
|
maxDuration: .seconds(10_000_000),
|
|
maxIterations: 3
|
|
)
|
|
) { benchmark in
|
|
let privateKey = P256._ARCV1.PrivateKey()
|
|
let publicKey = privateKey.publicKey
|
|
let requestContext = Data("shared request context".utf8)
|
|
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
|
let credentialRequest = precredential.credentialRequest
|
|
|
|
benchmark.startMeasurement()
|
|
|
|
for _ in benchmark.scaledIterations {
|
|
blackHole(try privateKey.issue(credentialRequest))
|
|
}
|
|
}
|
|
|
|
Benchmark(
|
|
"arc-verify-p256",
|
|
configuration: Benchmark.Configuration(
|
|
metrics: defaultMetrics,
|
|
scalingFactor: .kilo,
|
|
maxDuration: .seconds(10_000_000),
|
|
maxIterations: 10
|
|
)
|
|
) { benchmark in
|
|
let privateKey = P256._ARCV1.PrivateKey()
|
|
let publicKey = privateKey.publicKey
|
|
let requestContext = Data("shared request context".utf8)
|
|
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
|
|
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
|
let credentialRequest = precredential.credentialRequest
|
|
let credentialResponse = try privateKey.issue(credentialRequest)
|
|
var credential = try publicKey.finalize(credentialResponse, for: precredential)
|
|
let (presentation, nonce) = try credential.makePresentation(
|
|
context: presentationContext,
|
|
presentationLimit: presentationLimit
|
|
)
|
|
|
|
benchmark.startMeasurement()
|
|
|
|
for _ in benchmark.scaledIterations {
|
|
blackHole(
|
|
try privateKey.verify(
|
|
presentation,
|
|
requestContext: requestContext,
|
|
presentationContext: presentationContext,
|
|
presentationLimit: presentationLimit,
|
|
nonce: nonce
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
Benchmark(
|
|
"arc-issue-p384",
|
|
configuration: Benchmark.Configuration(
|
|
metrics: defaultMetrics,
|
|
scalingFactor: .kilo,
|
|
maxDuration: .seconds(10_000_000),
|
|
maxIterations: 3
|
|
)
|
|
) { benchmark in
|
|
let privateKey = P384._ARCV1.PrivateKey()
|
|
let publicKey = privateKey.publicKey
|
|
let requestContext = Data("shared request context".utf8)
|
|
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
|
let credentialRequest = precredential.credentialRequest
|
|
|
|
benchmark.startMeasurement()
|
|
|
|
for _ in benchmark.scaledIterations {
|
|
blackHole(try privateKey.issue(credentialRequest))
|
|
}
|
|
}
|
|
|
|
Benchmark(
|
|
"arc-verify-p384",
|
|
configuration: Benchmark.Configuration(
|
|
metrics: defaultMetrics,
|
|
scalingFactor: .kilo,
|
|
maxDuration: .seconds(10_000_000),
|
|
maxIterations: 10
|
|
)
|
|
) { benchmark in
|
|
let privateKey = P384._ARCV1.PrivateKey()
|
|
let publicKey = privateKey.publicKey
|
|
let requestContext = Data("shared request context".utf8)
|
|
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
|
|
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
|
let credentialRequest = precredential.credentialRequest
|
|
let credentialResponse = try privateKey.issue(credentialRequest)
|
|
var credential = try publicKey.finalize(credentialResponse, for: precredential)
|
|
let (presentation, nonce) = try credential.makePresentation(
|
|
context: presentationContext,
|
|
presentationLimit: presentationLimit
|
|
)
|
|
|
|
benchmark.startMeasurement()
|
|
|
|
for _ in benchmark.scaledIterations {
|
|
blackHole(
|
|
try privateKey.verify(
|
|
presentation,
|
|
requestContext: requestContext,
|
|
presentationContext: presentationContext,
|
|
presentationLimit: presentationLimit,
|
|
nonce: nonce
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
Benchmark(
|
|
"voprf-evaluate-p384",
|
|
configuration: Benchmark.Configuration(
|
|
metrics: defaultMetrics,
|
|
scalingFactor: .kilo,
|
|
maxDuration: .seconds(10_000_000),
|
|
maxIterations: 3
|
|
)
|
|
) { benchmark in
|
|
let privateKey = P384._VOPRF.PrivateKey()
|
|
let publicKey = privateKey.publicKey
|
|
let privateInput = Data("This is some input data".utf8)
|
|
let blindedInput = try publicKey.blind(privateInput)
|
|
let blindedElement = blindedInput.blindedElement
|
|
|
|
benchmark.startMeasurement()
|
|
|
|
for _ in benchmark.scaledIterations {
|
|
blackHole(try privateKey.evaluate(blindedElement))
|
|
}
|
|
}
|
|
}
|