mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebcbfc61ba | ||
|
|
785709bdaf |
No files matched your search
@@ -14,6 +14,10 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.15.1)
|
||||
|
||||
if(POLICY CMP0157)
|
||||
cmake_policy(SET CMP0157 NEW)
|
||||
endif()
|
||||
|
||||
project(SwiftCrypto
|
||||
LANGUAGES ASM C CXX Swift)
|
||||
|
||||
@@ -47,6 +51,18 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING)
|
||||
set(CMAKE_RANLIB "/usr/bin/ranlib")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||
# We need to ensure that we don't include the min/max macros from the Windows SDK.
|
||||
add_compile_definitions(NOMINMAX)
|
||||
# We can only link against the DLL version of the MSVC runtime library for now.
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
||||
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
|
||||
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
find_package(dispatch CONFIG)
|
||||
find_package(Foundation CONFIG)
|
||||
|
||||
+21
@@ -334,6 +334,27 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD" AND CMAKE_SYSTEM_PROCES
|
||||
gen/bcm/vpaes-armv8-linux.S
|
||||
gen/crypto/chacha-armv8-linux.S
|
||||
gen/crypto/chacha20_poly1305_armv8-linux.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
gen/bcm/aesv8-armv8-win.S
|
||||
gen/bcm/aesv8-gcm-armv8-win.S
|
||||
gen/bcm/armv8-mont-win.S
|
||||
gen/bcm/bn-armv8-win.S
|
||||
gen/bcm/ghash-neon-armv8-win.S
|
||||
gen/bcm/ghashv8-armv8-win.S
|
||||
gen/bcm/p256-armv8-asm-win.S
|
||||
gen/bcm/p256_beeu-armv8-asm-win.S
|
||||
gen/bcm/sha1-armv8-win.S
|
||||
gen/bcm/sha256-armv8-win.S
|
||||
gen/bcm/sha512-armv8-win.S
|
||||
gen/bcm/vpaes-armv8-win.S
|
||||
gen/crypto/chacha-armv8-win.S
|
||||
gen/crypto/chacha20_poly1305_armv8-win.S)
|
||||
else()
|
||||
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif()
|
||||
|
||||
target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
|
||||
@@ -29,8 +29,22 @@ struct RFCVectorDecoder {
|
||||
let bundle = Bundle(for: type(of: bundleType))
|
||||
let fileURL = bundle.url(forResource: fileName, withExtension: "txt")
|
||||
#else
|
||||
let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/")
|
||||
let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/Test Vectors/\(fileName).txt")
|
||||
var fileURL: URL? = URL(fileURLWithPath: "\(#file)")
|
||||
for _ in 0..<3 {
|
||||
fileURL!.deleteLastPathComponent()
|
||||
}
|
||||
#if compiler(>=6.0)
|
||||
if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) {
|
||||
fileURL!.append(path: "Test Vectors", directoryHint: .isDirectory)
|
||||
fileURL!.append(path: "\(fileName).txt", directoryHint: .notDirectory)
|
||||
} else {
|
||||
fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true)
|
||||
fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false)
|
||||
}
|
||||
#else
|
||||
fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true)
|
||||
fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
let rfcVectorData = try Data(contentsOf: fileURL!)
|
||||
|
||||
@@ -25,8 +25,22 @@ extension XCTestCase {
|
||||
let bundle = Bundle(for: type(of: bundleType))
|
||||
let fileURL = bundle.url(forResource: jsonName, withExtension: "json")
|
||||
#else
|
||||
let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/")
|
||||
let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/Test Vectors/\(jsonName).json")
|
||||
var fileURL = URL(fileURLWithPath: "\(#file)")
|
||||
for _ in 0..<3 {
|
||||
fileURL.deleteLastPathComponent()
|
||||
}
|
||||
#if compiler(>=6.0)
|
||||
if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) {
|
||||
fileURL.append(path: "Test Vectors", directoryHint: .isDirectory)
|
||||
fileURL.append(path: "\(jsonName).json", directoryHint: .notDirectory)
|
||||
} else {
|
||||
fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true)
|
||||
fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false)
|
||||
}
|
||||
#else
|
||||
fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true)
|
||||
fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
let data = try orFail(file: file, line: line) { try Data(contentsOf: unwrap(fileURL, file: file, line: line)) }
|
||||
|
||||
@@ -25,8 +25,22 @@ struct RFCVectorDecoder {
|
||||
private var index: Int?
|
||||
|
||||
init(bundleType: AnyObject, fileName: String) throws {
|
||||
let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/")
|
||||
let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/_CryptoExtrasVectors/\(fileName).txt")
|
||||
var fileURL: URL? = URL(fileURLWithPath: "\(#file)")
|
||||
for _ in 0..<3 {
|
||||
fileURL!.deleteLastPathComponent()
|
||||
}
|
||||
#if compiler(>=6.0)
|
||||
if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) {
|
||||
fileURL!.append(path: "_CryptoExtrasVectors", directoryHint: .isDirectory)
|
||||
fileURL!.append(path: "\(fileName).txt", directoryHint: .notDirectory)
|
||||
} else {
|
||||
fileURL! = fileURL!.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true)
|
||||
fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false)
|
||||
}
|
||||
#else
|
||||
fileURL! = fileURL!.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true)
|
||||
fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false)
|
||||
#endif
|
||||
|
||||
let rfcVectorData = try Data(contentsOf: fileURL!)
|
||||
self.rfcVectorData = String(decoding: rfcVectorData, as: Unicode.UTF8.self)
|
||||
|
||||
@@ -21,10 +21,24 @@ struct WycheproofTest<T: Codable>: Codable {
|
||||
|
||||
extension XCTestCase {
|
||||
func wycheproofTest<T: Codable>(jsonName: String, file: StaticString = #file, line: UInt = #line, testFunction: (T) throws -> Void) throws {
|
||||
let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/")
|
||||
let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/_CryptoExtrasVectors/\(jsonName).json")
|
||||
var fileURL = URL(fileURLWithPath: "\(#file)")
|
||||
for _ in 0..<3 {
|
||||
fileURL.deleteLastPathComponent()
|
||||
}
|
||||
#if compiler(>=6.0)
|
||||
if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) {
|
||||
fileURL.append(path: "_CryptoExtrasVectors", directoryHint: .isDirectory)
|
||||
fileURL.append(path: "\(jsonName).json", directoryHint: .notDirectory)
|
||||
} else {
|
||||
fileURL = fileURL.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true)
|
||||
fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false)
|
||||
}
|
||||
#else
|
||||
fileURL = fileURL.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true)
|
||||
fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false)
|
||||
#endif
|
||||
|
||||
let data = try Data(contentsOf: fileURL!)
|
||||
let data = try Data(contentsOf: fileURL)
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
let wpTest = try decoder.decode(WycheproofTest<T>.self, from: data)
|
||||
|
||||
Reference in new issue
Block a user