Rename _CryptoExtras Take 2 (#407)

Following on from #281, opened as a new PR as the conflicts were too
many

### Checklist
- [x] I've run tests to see all new and existing tests pass
- [x] I've followed the code style of the rest of the project
- [x] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [x] I've updated the documentation if necessary

#### If you've made changes to `gyb` files
- [ ] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request

### Motivation:

_[Explain here the context, and why you're making that change. What is
the problem you're trying to solve.]_

### Modifications:

_[Describe the modifications you've done.]_

### Result:

_[After your change, what will change.]_
This commit is contained in:
Tim Condon authored and GitHub committed 2025-09-15 15:07:07 +01:00
1 parent ea7f8fbce1
commit 4e662b89da
152 files changed
+244 -219

No files matched your search

+1 -1
View File
@@ -56,7 +56,7 @@ jobs:
{ "name": "CXKCP", "type": "source", "exceptions": [] },
{ "name": "CXKCPShims", "type": "source", "exceptions": [] },
{ "name": "Crypto", "type": "source", "exceptions": [] },
{ "name": "_CryptoExtras", "type": "source", "exceptions": [] },
{ "name": "CryptoExtras", "type": "source", "exceptions": [] },
{ "name": "CCryptoBoringSSL", "type": "assembly", "exceptions": [ "*/AES/*.swift" ] }
]
}
+2 -1
View File
@@ -1,5 +1,5 @@
.DS_Store
/.build
.build
/out
/Packages
/*.xcodeproj
@@ -12,6 +12,7 @@ Package.resolved
DerivedData
.swiftpm
**/gyb.pyc
scripts/__pycache__/
.*.sw[nop]
+1 -1
View File
@@ -1,5 +1,5 @@
version: 1
builder:
configs:
- documentation_targets: [Crypto, _CryptoExtras]
- documentation_targets: [Crypto, CryptoExtras]
platform: linux
+68 -68
View File
@@ -69,46 +69,46 @@ Sources/Crypto/Util/PrettyBytes.swift
Sources/Crypto/Util/SafeCompare.swift
Sources/Crypto/Util/SecureBytes.swift
Sources/Crypto/Util/Zeroization.swift
Sources/_CryptoExtras/AES/AES_CBC.swift
Sources/_CryptoExtras/AES/AES_CFB.swift
Sources/_CryptoExtras/AES/AES_CTR.swift
Sources/_CryptoExtras/AES/AES_GCM_SIV.swift
Sources/_CryptoExtras/AES/Block Function.swift
Sources/_CryptoExtras/ARC/ARC+API.swift
Sources/_CryptoExtras/ARC/ARC.swift
Sources/_CryptoExtras/ARC/ARCCredential.swift
Sources/_CryptoExtras/ARC/ARCEncoding.swift
Sources/_CryptoExtras/ARC/ARCPrecredential.swift
Sources/_CryptoExtras/ARC/ARCPresentation.swift
Sources/_CryptoExtras/ARC/ARCRequest.swift
Sources/_CryptoExtras/ARC/ARCResponse.swift
Sources/_CryptoExtras/ARC/ARCServer.swift
Sources/_CryptoExtras/ZKPs/Prover.swift
Sources/_CryptoExtras/ZKPs/Verifier.swift
Sources/_CryptoExtras/ZKPs/ZKPToolbox.swift
Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift
Sources/_CryptoExtras/ECToolbox/ECToolbox.swift
Sources/_CryptoExtras/H2G/HashToField.swift
Sources/_CryptoExtras/Key Derivation/KDF.swift
Sources/_CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift
Sources/_CryptoExtras/Key Derivation/Scrypt/Scrypt.swift
Sources/_CryptoExtras/OPRFs/OPRF.swift
Sources/_CryptoExtras/OPRFs/OPRFClient.swift
Sources/_CryptoExtras/OPRFs/OPRFServer.swift
Sources/_CryptoExtras/OPRFs/VOPRF+API.swift
Sources/_CryptoExtras/OPRFs/VOPRFClient.swift
Sources/_CryptoExtras/OPRFs/VOPRFServer.swift
Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
Sources/_CryptoExtras/RSA/RSA.swift
Sources/_CryptoExtras/Util/BoringSSLHelpers.swift
Sources/_CryptoExtras/Util/DigestType.swift
Sources/_CryptoExtras/Util/Error.swift
Sources/_CryptoExtras/Util/I2OSP.swift
Sources/_CryptoExtras/Util/IntegerEncoding.swift
Sources/_CryptoExtras/Util/PEMDocument.swift
Sources/_CryptoExtras/Util/PrettyBytes.swift
Sources/_CryptoExtras/Util/SubjectPublicKeyInfo.swift
Sources/_CryptoExtras/ZKPs/DLEQ.swift
Sources/CryptoExtras/AES/AES_CBC.swift
Sources/CryptoExtras/AES/AES_CFB.swift
Sources/CryptoExtras/AES/AES_CTR.swift
Sources/CryptoExtras/AES/AES_GCM_SIV.swift
Sources/CryptoExtras/AES/Block Function.swift
Sources/CryptoExtras/ARC/ARC+API.swift
Sources/CryptoExtras/ARC/ARC.swift
Sources/CryptoExtras/ARC/ARCCredential.swift
Sources/CryptoExtras/ARC/ARCEncoding.swift
Sources/CryptoExtras/ARC/ARCPrecredential.swift
Sources/CryptoExtras/ARC/ARCPresentation.swift
Sources/CryptoExtras/ARC/ARCRequest.swift
Sources/CryptoExtras/ARC/ARCResponse.swift
Sources/CryptoExtras/ARC/ARCServer.swift
Sources/CryptoExtras/ZKPs/Prover.swift
Sources/CryptoExtras/ZKPs/Verifier.swift
Sources/CryptoExtras/ZKPs/ZKPToolbox.swift
Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift
Sources/CryptoExtras/ECToolbox/ECToolbox.swift
Sources/CryptoExtras/H2G/HashToField.swift
Sources/CryptoExtras/Key Derivation/KDF.swift
Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift
Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift
Sources/CryptoExtras/OPRFs/OPRF.swift
Sources/CryptoExtras/OPRFs/OPRFClient.swift
Sources/CryptoExtras/OPRFs/OPRFServer.swift
Sources/CryptoExtras/OPRFs/VOPRF+API.swift
Sources/CryptoExtras/OPRFs/VOPRFClient.swift
Sources/CryptoExtras/OPRFs/VOPRFServer.swift
Sources/CryptoExtras/RSA/RSA+BlindSigning.swift
Sources/CryptoExtras/RSA/RSA.swift
Sources/CryptoExtras/Util/BoringSSLHelpers.swift
Sources/CryptoExtras/Util/DigestType.swift
Sources/CryptoExtras/Util/Error.swift
Sources/CryptoExtras/Util/I2OSP.swift
Sources/CryptoExtras/Util/IntegerEncoding.swift
Sources/CryptoExtras/Util/PEMDocument.swift
Sources/CryptoExtras/Util/PrettyBytes.swift
Sources/CryptoExtras/Util/SubjectPublicKeyInfo.swift
Sources/CryptoExtras/ZKPs/DLEQ.swift
Sources/crypto-shasum/main.swift
Tests/CryptoTests/ASN1/ASN1Tests.swift
Tests/CryptoTests/ASN1/GeneralizedTimeTests.swift
@@ -141,31 +141,31 @@ Tests/CryptoTests/Utils/RFCVector.swift
Tests/CryptoTests/Utils/SplitData.swift
Tests/CryptoTests/Utils/Wycheproof.swift
Tests/CryptoTests/Utils/XCTestUtils.swift
Tests/_CryptoExtrasTests/AES Block Function Tests.swift
Tests/_CryptoExtrasTests/AES-GCM-SIV-Runner.swift
Tests/_CryptoExtrasTests/AES_CBCTests.swift
Tests/_CryptoExtrasTests/AES_CFBTests.swift
Tests/_CryptoExtrasTests/AES_CTRTests.swift
Tests/_CryptoExtrasTests/ARC/ARCAPITests.swift
Tests/_CryptoExtrasTests/ARC/ARCEncodingTests.swift
Tests/_CryptoExtrasTests/ARC/ARCPublicAPITests.swift
Tests/_CryptoExtrasTests/ARC/ARCTestVectors.swift
Tests/_CryptoExtrasTests/ARC/ARCTests.swift
Tests/_CryptoExtrasTests/ChaCha20CTRTests.swift
Tests/_CryptoExtrasTests/ECToolbox/HashToCurveTests.swift
Tests/_CryptoExtrasTests/OPRFs/ECVOPRFTests.swift
Tests/_CryptoExtrasTests/OPRFs/VOPRFAPITests.swift
Tests/_CryptoExtrasTests/OPRFs/VOPRFPublicAPITests.swift
Tests/_CryptoExtrasTests/PBKDF2Tests.swift
Tests/_CryptoExtrasTests/ScryptTests.swift
Tests/_CryptoExtrasTests/TestRSABlindSigning.swift
Tests/_CryptoExtrasTests/TestRSABlindSigningAPI.swift
Tests/_CryptoExtrasTests/TestRSAEncryption.swift
Tests/_CryptoExtrasTests/TestRSASigning.swift
Tests/_CryptoExtrasTests/Util/IntegerEncodingTests.swift
Tests/_CryptoExtrasTests/Utils/BytesUtil.swift
Tests/_CryptoExtrasTests/Utils/RFCVector.swift
Tests/_CryptoExtrasTests/Utils/SplitData.swift
Tests/_CryptoExtrasTests/Utils/Wycheproof.swift
Tests/_CryptoExtrasTests/Utils/XCTestUtils.swift
Tests/_CryptoExtrasTests/ZKPs/ZKPToolbox.swift
Tests/CryptoExtrasTests/AES Block Function Tests.swift
Tests/CryptoExtrasTests/AES-GCM-SIV-Runner.swift
Tests/CryptoExtrasTests/AES_CBCTests.swift
Tests/CryptoExtrasTests/AES_CFBTests.swift
Tests/CryptoExtrasTests/AES_CTRTests.swift
Tests/CryptoExtrasTests/ARC/ARCAPITests.swift
Tests/CryptoExtrasTests/ARC/ARCEncodingTests.swift
Tests/CryptoExtrasTests/ARC/ARCPublicAPITests.swift
Tests/CryptoExtrasTests/ARC/ARCTestVectors.swift
Tests/CryptoExtrasTests/ARC/ARCTests.swift
Tests/CryptoExtrasTests/ChaCha20CTRTests.swift
Tests/CryptoExtrasTests/ECToolbox/HashToCurveTests.swift
Tests/CryptoExtrasTests/OPRFs/ECVOPRFTests.swift
Tests/CryptoExtrasTests/OPRFs/VOPRFAPITests.swift
Tests/CryptoExtrasTests/OPRFs/VOPRFPublicAPITests.swift
Tests/CryptoExtrasTests/PBKDF2Tests.swift
Tests/CryptoExtrasTests/ScryptTests.swift
Tests/CryptoExtrasTests/TestRSABlindSigning.swift
Tests/CryptoExtrasTests/TestRSABlindSigningAPI.swift
Tests/CryptoExtrasTests/TestRSAEncryption.swift
Tests/CryptoExtrasTests/TestRSASigning.swift
Tests/CryptoExtrasTests/Util/IntegerEncodingTests.swift
Tests/CryptoExtrasTests/Utils/BytesUtil.swift
Tests/CryptoExtrasTests/Utils/RFCVector.swift
Tests/CryptoExtrasTests/Utils/SplitData.swift
Tests/CryptoExtrasTests/Utils/Wycheproof.swift
Tests/CryptoExtrasTests/Utils/XCTestUtils.swift
Tests/CryptoExtrasTests/ZKPs/ZKPToolbox.swift
+1 -1
View File
@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
import Benchmark
import Crypto
import _CryptoExtras
import CryptoExtras
#if canImport(FoundationEssentials)
import FoundationEssentials
+1 -1
View File
@@ -14,7 +14,7 @@ let package = Package(
dependencies: [
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "_CryptoExtras", package: "swift-crypto"),
.product(name: "CryptoExtras", package: "swift-crypto"),
],
path: "Benchmarks/",
plugins: [
+1 -1
View File
@@ -69,7 +69,7 @@ act --container-architecture linux/amd64 pull_request -j cmake-lists -W ./.githu
You can find the underlying script at https://github.com/apple/swift-nio/blob/main/scripts/update-cmake-lists.sh . Using the script directly is less straightforwards because it requires you to pass the JSON config from the `pull_request.yml` file into the script, such as:
```
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"CCryptoBoringSSL","type":"source","exceptions":[]},{"name":"CCryptoBoringSSLShims","type":"source","exceptions":[]},{"name":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"_CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"CCryptoBoringSSL","type":"source","exceptions":[]},{"name":"CCryptoBoringSSLShims","type":"source","exceptions":[]},{"name":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash
```
## API Evolution
+12 -3
View File
@@ -89,7 +89,9 @@ let package = Package(
name: "swift-crypto",
products: [
.library(name: "Crypto", targets: ["Crypto"]),
// Kept for backward compatibility
.library(name: "_CryptoExtras", targets: ["_CryptoExtras"]),
.library(name: "CryptoExtras", targets: ["CryptoExtras"]),
/* This target is used only for symbol mangling. It's added and removed automatically because it emits build warnings. MANGLE_START
.library(name: "CCryptoBoringSSL", type: .static, targets: ["CCryptoBoringSSL"]),
MANGLE_END */
@@ -177,7 +179,7 @@ let package = Package(
swiftSettings: swiftSettings
),
.target(
name: "_CryptoExtras",
name: "CryptoExtras",
dependencies: [
"CCryptoBoringSSL",
"CCryptoBoringSSLShims",
@@ -191,6 +193,13 @@ let package = Package(
resources: privacyManifestResource,
swiftSettings: swiftSettings
),
.target(
name: "_CryptoExtras",
dependencies: [
"CryptoExtras",
],
swiftSettings: swiftSettings
),
.target(
name: "CryptoBoringWrapper",
dependencies: [
@@ -219,8 +228,8 @@ let package = Package(
swiftSettings: swiftSettings
),
.testTarget(
name: "_CryptoExtrasTests",
dependencies: ["_CryptoExtras"],
name: "CryptoExtrasTests",
dependencies: ["CryptoExtras"],
resources: [
.copy("ECToolbox/H2CVectors/P256_XMD-SHA-256_SSWU_RO_.json"),
.copy("ECToolbox/H2CVectors/P384_XMD-SHA-384_SSWU_RO_.json"),
+1 -1
View File
@@ -34,7 +34,7 @@ When building Swift Crypto for use on Linux or Windows, Swift Crypto builds subs
2. The common API of Swift Crypto and CryptoKit.
3. The backing implementation of this common API, which calls into BoringSSL.
The API code, and some cryptographic primitives which are directly implemented in Swift, are exactly the same for both Apple CryptoKit and Swift Crypto. The backing BoringSSL-based implementation is unique to Swift Crypto.
The API code, and some cryptographic primitives which are directly implemented in Swift, are exactly the same for both Apple CryptoKit and Swift Crypto. The backing BoringSSL-based implementation is unique to Swift Crypto. In addition, there is another product, `CryptoExtras`, which provides additional functionality that is not offered in CryptoKit, which contains cryptographic APIS predominantly useful in the server ecosystem. **Note**: if you depend on CryptoExtras you'll bundle the BoringSSL implementation of the library in your application, no matter the platform.
## Evolution
+1 -1
View File
@@ -18,4 +18,4 @@ add_subdirectory(CXKCP)
add_subdirectory(CXKCPShims)
add_subdirectory(CryptoBoringWrapper)
add_subdirectory(Crypto)
add_subdirectory(_CryptoExtras)
add_subdirectory(CryptoExtras)
File renamed without changes.
File renamed without changes.
@@ -12,7 +12,7 @@
##
##===----------------------------------------------------------------------===##
add_library(_CryptoExtras
add_library(CryptoExtras
"AES/AES_CBC.swift"
"AES/AES_CFB.swift"
"AES/AES_CTR.swift"
@@ -76,29 +76,29 @@ add_library(_CryptoExtras
"ZKPs/ZKPToolbox.swift"
)
target_compile_options(_CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM)
target_compile_options(CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_options(_CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM_FORCE_BUILD_API)
target_compile_options(CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM_FORCE_BUILD_API)
endif()
target_include_directories(_CryptoExtras PRIVATE
target_include_directories(CryptoExtras PRIVATE
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:CCryptoBoringSSLShims,INCLUDE_DIRECTORIES>)
target_link_libraries(_CryptoExtras PUBLIC
target_link_libraries(CryptoExtras PUBLIC
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
Crypto
CryptoBoringWrapper
CCryptoBoringSSL
CCryptoBoringSSLShims)
target_compile_options(_CryptoExtras PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})
target_compile_options(CryptoExtras PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})
target_link_options(_CryptoExtras PRIVATE
target_link_options(CryptoExtras PRIVATE
"$<$<PLATFORM_ID:Darwin>:SHELL:-Xlinker -framework -Xlinker Security>")
set_target_properties(_CryptoExtras PROPERTIES
set_target_properties(CryptoExtras PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS _CryptoExtras)
set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CryptoExtras)
@@ -1,4 +1,4 @@
# ``_CryptoExtras``
# ``CryptoExtras``
Provides additional cryptographic APIs that are not available in CryptoKit (and therefore the core Crypto library).
@@ -10,7 +10,7 @@ Provides additional cryptographic APIs that are not available in CryptoKit (and
### Ciphers
- ``_CryptoExtras/Crypto/AES``
- ``CryptoExtras/Crypto/AES``
### Public key cryptography
@@ -22,4 +22,4 @@ Provides additional cryptographic APIs that are not available in CryptoKit (and
### Legacy algorithms
- ``_CryptoExtras/Crypto/Insecure``
- ``CryptoExtras/Crypto/Insecure``
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+15
View File
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCrypto open source project
//
// Copyright (c) 2019 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
//
//===----------------------------------------------------------------------===//
@_exported import CryptoExtras
@@ -18,7 +18,7 @@ import Foundation
#endif
import XCTest
import Crypto
import _CryptoExtras
import CryptoExtras
final class AESBlockFunctionTests: XCTestCase {
static let nistPlaintextChunks: [[UInt8]] = [
@@ -18,7 +18,7 @@ import Foundation
#endif
import XCTest
import Crypto
import _CryptoExtras
import CryptoExtras
struct AEADTestGroup: Codable {
let ivSize: Int
@@ -18,7 +18,7 @@ import FoundationEssentials
#else
import Foundation
#endif
import _CryptoExtras
import CryptoExtras
import XCTest
final class CBCTests: XCTestCase {
@@ -162,7 +162,7 @@ final class CBCTests: XCTestCase {
}
}
}
func testToDataConversion() throws {
let randomBytes = (0..<16).map { _ in UInt8.random(in: UInt8.min...UInt8.max) }
let dataIn = Data(randomBytes)
@@ -14,7 +14,7 @@
import Crypto
import CryptoBoringWrapper
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
final class AES_CFBTests: XCTestCase {
@@ -18,7 +18,7 @@ import FoundationEssentials
#else
import Foundation
#endif
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
final class AESCTRTests: XCTestCase {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, visionOS 2.0, *)
@@ -11,7 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
import Crypto
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
import _CryptoExtras // NOTE: No @testable import, because we want to test the public API.
import CryptoExtras // NOTE: No @testable import, because we want to test the public API.
import XCTest
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, visionOS 2.0, *)
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
let ARCEncodedTestVector = """
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
@available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, macCatalyst 13.2, visionOS 1.2, *)
@@ -12,9 +12,9 @@
//
//===----------------------------------------------------------------------===//
import Crypto
import CryptoExtras
import Foundation
import XCTest
import _CryptoExtras
final class CMACTests: XCTestCase {
// Borrowed from CryptoKit
@@ -18,7 +18,7 @@ import Foundation
#endif
import XCTest
import Crypto
import _CryptoExtras
import CryptoExtras
class ChaCha20CTRTests: XCTestCase {
@@ -17,10 +17,10 @@ import XCTest
#if !canImport(Darwin) || canImport(CryptoKit, _version: 241.100.42)
// Corresponds to the CryptoKit in XCode 16.3, which has Sendable annotations
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
#else
@preconcurrency import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
#endif
final class ECToolboxBoringSSLTests: XCTestCase {
@@ -12,13 +12,13 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
struct HashToCurveTestVectorCurvePoint: Codable {
let x: String
let y: String
var rawRepresentation: Data {
return try! Data(hexString: String(x.dropFirst(2))) + Data(hexString: String(y.dropFirst(2)))
}
@@ -44,28 +44,28 @@ class HashToCurveTests: XCTestCase {
let bundle = Bundle(for: type(of: self))
#endif
let fileURL = bundle.url(forResource: file, withExtension: "json")
let data = try Data(contentsOf: fileURL!)
let decoder = JSONDecoder()
let testVectorFile = try decoder.decode(HashToCurveTestVectorFile.self, from: data)
let dst = testVectorFile.dst
for vector in testVectorFile.vectors {
let msg = vector.msg.data(using: .ascii)!
let point = h2c.hashToGroup(msg, domainSeparationString: Data(dst.utf8))
XCTAssert(point.oprfRepresentation.hexString.dropFirst(2) == vector.P.x.dropFirst(2))
}
}
func testVectors() throws {
try testVector(vectorFileName: "P256_XMD-SHA-256_SSWU_RO_", with: HashToCurveImpl<P256>.self)
try testVector(vectorFileName: "P384_XMD-SHA-384_SSWU_RO_", with: HashToCurveImpl<P384>.self)
// try testVector(vectorFileName: "P521_XMD-SHA-512_SSWU_RO_", with: HashToCurveImpl<P521>.self)
}
func testH2F() throws {
let data = try! Data(hexString: "436f6e746578742d564f50524630372d00000300097465737420696e666f")
let dst = try! Data(hexString: "48617368546f5363616c61722d564f50524630372d000003")
@@ -16,7 +16,7 @@
import XCTest
@testable import _CryptoExtras
@testable import CryptoExtras
final class MLDSATests: XCTestCase {
func testMLDSA65Signing() throws {
@@ -232,7 +232,7 @@ final class MLDSATests: XCTestCase {
for _ in 0..<2 {
fileURL.deleteLastPathComponent()
}
fileURL = fileURL.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true)
fileURL = fileURL.appendingPathComponent("CryptoExtrasVectors", isDirectory: true)
fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false)
let data = try Data(contentsOf: fileURL)
@@ -16,7 +16,7 @@
import Crypto
import XCTest
@testable import _CryptoExtras
@testable import CryptoExtras
final class MLKEMTests: XCTestCase {
func testMLKEM768() throws {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
import XCTest
struct OPRFSuite: Codable {
@@ -64,50 +64,50 @@ class ECVOPRFTests: XCTestCase {
fatalError("Unknown mode")
}
}
func testBaseSuite<G: SupportedCurveDetailsImpl>(suite: OPRFSuite, C: G.Type, v8DraftCompatible: Bool) throws {
print("Testing \(suite.suiteName ?? suite.identifier!) in base mode.")
let privateKey = try GroupImpl<G>.Scalar(bytes: Data(hexString: suite.skSm))
let ciphersuite = OPRF.Ciphersuite(HashToCurveImpl<G>.self)
for vector in suite.vectors {
if vector.Batch != 1 {
continue
}
let client = OPRF.Client(mode: .base, ciphersuite: ciphersuite, v8CompatibilityMode: v8DraftCompatible)
let blindTestVector = try GroupImpl<G>.Scalar(bytes: Data(hexString: vector.Blind))
let input = try Data(hexString: vector.Input)
let (blind, blindedElement) = client.blindMessage(input, blind: blindTestVector)
XCTAssert(blindTestVector == blind)
XCTAssert(blindedElement.oprfRepresentation.hexString == vector.BlindedElement)
let server = OPRF.Server(mode: .base, ciphersuite: ciphersuite, privateKey: privateKey, v8CompatibilityMode: v8DraftCompatible)
var info = Data()
if vector.Info != nil { info = try Data(hexString: vector.Info!) }
let evaluate = try server.evaluate(blindedElement: blindedElement, info: info)
let evaluatedElementTv = try GroupImpl<G>.Element(oprfRepresentation: Data(hexString: vector.EvaluationElement))
XCTAssert(evaluate.0 == evaluatedElementTv)
let finalized = try client.finalize(message: input,
info: info,
blind: blind,
evaluatedElement: evaluate.0)
XCTAssert(finalized.hexString == vector.Output)
XCTAssert(try server.verifyFinalize(msg: input, output: finalized, info: info))
}
}
func testVerifiableSuite<G: SupportedCurveDetailsImpl>(suite: OPRFSuite, C: G.Type, v8DraftCompatible: Bool, mode: OPRF.Mode) throws {
print("Testing \(suite.suiteName ?? suite.identifier!) in \(mode) mode.")
let privateKey = try GroupImpl<G>.Scalar(bytes: Data(hexString: suite.skSm))
let ciphersuite = OPRF.Ciphersuite(HashToCurveImpl<G>.self)
@@ -119,23 +119,23 @@ class ECVOPRFTests: XCTestCase {
let client = try! OPRF.VerifiableClient(ciphersuite: ciphersuite, v8CompatibilityMode: v8DraftCompatible, mode: mode)
let blindTestVector = try GroupImpl<G>.Scalar(bytes: Data(hexString: vector.Blind))
let input = try Data(hexString: vector.Input)
let (blind, blindedElement) = client.blindMessage(input, blind: blindTestVector)
XCTAssert(blindTestVector == blind)
XCTAssert(blindedElement.oprfRepresentation.hexString == vector.BlindedElement)
let server = try! OPRF.VerifiableServer(ciphersuite: ciphersuite, privateKey: privateKey, v8CompatibilityMode: v8DraftCompatible, mode: mode)
let proofBlind = try GroupImpl<G>.Scalar(bytes: Data(hexString: vector.Proof!.r))
var info: Data?
if (vector.Info?.count ?? 0) > 0 { info = try Data(hexString: vector.Info!) }
let evaluate = try server.evaluate(blindedElement: blindedElement, info: info, proofScalar: proofBlind)
let evaluatedElementTv = try GroupImpl<G>.Element(oprfRepresentation: Data(hexString: vector.EvaluationElement))
XCTAssert(evaluate.0 == evaluatedElementTv)
let proof_tv = vector.Proof!.proof
let c_tv = try GroupImpl<G>.Scalar(bytes: Data(hexString: String(proof_tv.prefix(proof_tv.count / 2))))
let s_tv = try GroupImpl<G>.Scalar(bytes: Data(hexString: String(proof_tv.suffix(proof_tv.count / 2))))
@@ -169,7 +169,7 @@ class ECVOPRFTests: XCTestCase {
}
}
}
func testVectors() throws {
print("Testing VOPRF Draft8 vectors.")
try testVectors(filename: "OPRFVectors-VOPRFDraft8", v8DraftCompatible: true)
@@ -178,7 +178,7 @@ class ECVOPRFTests: XCTestCase {
print("Testing VOPRF edge case vectors.")
try testVectors(filename: "OPRFVectors-edgecases", v8DraftCompatible: false)
}
func testVectors(filename: String, v8DraftCompatible: Bool) throws {
#if CRYPTO_IN_SWIFTPM
let bundle = Bundle.module
@@ -187,11 +187,11 @@ class ECVOPRFTests: XCTestCase {
#endif
let fileURL = bundle.url(forResource: filename, withExtension: "json")
let data = try Data(contentsOf: fileURL!)
let decoder = JSONDecoder()
let suites = try decoder.decode([OPRFSuite].self, from: data)
if v8DraftCompatible {
for suite in suites {
switch (suite.suiteID, suite.mode) {
@@ -204,7 +204,7 @@ class ECVOPRFTests: XCTestCase {
// case (OPRF.Ciphersuite(HashToCurveImpl<P521>.self).suiteID, let modeValue): do {
// try testSuite(suite: suite, C: P521.self, modeValue: modeValue, v8DraftCompatible: v8DraftCompatible)
// }
default:
print("Unsupported Ciphersuite: \(suite.suiteName ?? suite.identifier!)")
}
@@ -221,67 +221,67 @@ class ECVOPRFTests: XCTestCase {
// case (OPRF.Ciphersuite(HashToCurveImpl<P521>.self).stringIdentifier, let modeValue): do {
// try testSuite(suite: suite, C: P521.self, modeValue: modeValue, v8DraftCompatible: v8DraftCompatible)
// }
default:
print("Unsupported Ciphersuite: \(suite.suiteName ?? suite.identifier!)")
}
}
}
}
func testDistributivity() throws {
let r = GroupImpl<P256>.Scalar.random
let a = GroupImpl<P256>.Scalar.random
let b = GroupImpl<P256>.Scalar.random
let ab = (a + b)
let ar = a * r
let br = b * r
XCTAssert(ab - b == a)
XCTAssert(ab - a == b)
let arbr = (ab) * r
XCTAssert(arbr - br == ar)
XCTAssert(arbr - ar == br)
}
func testMath() throws {
let r = GroupImpl<P256>.Scalar.random
let k = GroupImpl<P256>.Scalar.random
let c = GroupImpl<P256>.Scalar.random
let A = GroupImpl<P256>.Element.generator
let B = k * A
let m = GroupImpl<P256>.Scalar.random
let z = k * m
let t2 = r * A
let t3 = r * m
let s = (r - c * k)
let t2_recontructed = (s * A) + (c * B)
let t3_reconstructed = ((s * m) + (c * z))
XCTAssert(t2 == t2_recontructed)
XCTAssert(t3.rawRepresentation == t3_reconstructed.rawRepresentation)
}
func testDLEQProver() throws {
let k = GroupImpl<P256>.Scalar.random
let A = GroupImpl<P256>.Element.generator
let B = k * A
let C = GroupImpl<P256>.Element.random
let D = k * C
let CDs = [(C: C, D: D)]
let proof = try DLEQ<HashToCurveImpl<P256>>.proveEquivalenceBetween(k: k, A: A, B: B, CDs: CDs, dst: Data(), proofScalar: .random, v8CompatibilityMode: false)
XCTAssert(try DLEQ<HashToCurveImpl<P256>>.verifyProof(A: A, B: B, CDs: CDs, proof: proof, dst: Data(), v8CompatibilityMode: false))
}
}
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@testable import _CryptoExtras // NOTE: @testable import, to inject fixed values from test vectors.
@testable import CryptoExtras // NOTE: @testable import, to inject fixed values from test vectors.
import XCTest
extension OPRFSuite {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
import Crypto
import _CryptoExtras // NOTE: No @testable import, because we want to test the public API.
import CryptoExtras // NOTE: No @testable import, because we want to test the public API.
import XCTest
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
import XCTest
import Crypto
@testable import _CryptoExtras
@testable import CryptoExtras
// Test Vectors are coming from https://tools.ietf.org/html/rfc6070
class PBKDF2Tests: XCTestCase {
@@ -24,7 +24,7 @@ class PBKDF2Tests: XCTestCase {
var rounds: Int
var outputLength: Int
var derivedKey: [UInt8]
enum CodingKeys: String, CodingKey {
case hash = "Hash"
case inputSecret = "P"
@@ -34,57 +34,57 @@ class PBKDF2Tests: XCTestCase {
case derivedKey = "DK"
}
}
func oneshotTesting(_ vector: RFCTestVector, hash: KDF.Insecure.PBKDF2.HashFunction) throws {
let (contiguousInput, discontiguousInput) = vector.inputSecret.asDataProtocols()
let (contiguousSalt, discontiguousSalt) = vector.salt.asDataProtocols()
let DK1 = try KDF.Insecure.PBKDF2.deriveKey(from: contiguousInput, salt: contiguousSalt, using: hash,
outputByteCount: vector.outputLength,
unsafeUncheckedRounds: vector.rounds)
let DK2 = try KDF.Insecure.PBKDF2.deriveKey(from: discontiguousInput, salt: contiguousSalt, using: hash,
outputByteCount: vector.outputLength,
unsafeUncheckedRounds: vector.rounds)
let DK3 = try KDF.Insecure.PBKDF2.deriveKey(from: contiguousInput, salt: discontiguousSalt, using: hash,
outputByteCount: vector.outputLength,
unsafeUncheckedRounds: vector.rounds)
let DK4 = try KDF.Insecure.PBKDF2.deriveKey(from: discontiguousInput, salt: discontiguousSalt, using: hash,
outputByteCount: vector.outputLength,
unsafeUncheckedRounds: vector.rounds)
let expectedDK = SymmetricKey(data: vector.derivedKey)
XCTAssertEqual(DK1, expectedDK)
XCTAssertEqual(DK2, expectedDK)
XCTAssertEqual(DK3, expectedDK)
XCTAssertEqual(DK4, expectedDK)
}
func testRFCVector(_ vector: RFCTestVector, hash: KDF.Insecure.PBKDF2.HashFunction) throws {
try oneshotTesting(vector, hash: hash)
}
func testRfcTestVectorsSHA1() throws {
var decoder = try orFail { try RFCVectorDecoder(bundleType: self, fileName: "rfc-6070-PBKDF2-SHA1") }
let vectors = try orFail { try decoder.decode([RFCTestVector].self) }
for vector in vectors {
precondition(vector.hash == "SHA-1")
try orFail { try self.testRFCVector(vector, hash: .insecureSHA1) }
}
}
func testRoundsParameterCheck() {
let (contiguousInput, contiguousSalt) = (Data("password".utf8), Data("salt".utf8))
XCTAssertThrowsError(try KDF.Insecure.PBKDF2.deriveKey(from: contiguousInput, salt: contiguousSalt, using: .insecureSHA1,
outputByteCount: 20, rounds: 209_999))
XCTAssertNoThrow(try KDF.Insecure.PBKDF2.deriveKey(from: contiguousInput, salt: contiguousSalt, using: .insecureSHA1,
outputByteCount: 20, unsafeUncheckedRounds: 209_999))
XCTAssertNoThrow(try KDF.Insecure.PBKDF2.deriveKey(from: contiguousInput, salt: contiguousSalt, using: .insecureSHA1,
outputByteCount: 20, rounds: 210_000))
}
Loaded 100 of 152 files, more files were not shown because too many files have changed in this diff. Show more