mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Add five new Wycheproof ECDSA test vectors using IEEE P1363 format (#167)
* Add five new ECDSA Wycheproof test vectors with signatures on IEEE P1363 format, remove four unused Wycheproof test vectors. * Revert unnecessary protocol extension
This commit is contained in:
1 parent
d1047c1c9a
commit
3ea0bdb8fd
10 files changed
+26684
-52427
No files matched your search
@@ -53,7 +53,7 @@ struct EdDSAPublicKey: Codable {
|
||||
class SignatureTests: XCTestCase {
|
||||
let data = "Testing Signatures".data(using: String.Encoding.utf8)!
|
||||
|
||||
func testWycheProofEdDSA() throws {
|
||||
func testWycheproofEdDSA() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
@@ -63,13 +63,14 @@ class SignatureTests: XCTestCase {
|
||||
})
|
||||
}
|
||||
}
|
||||
func testWycheProofP256() throws {
|
||||
|
||||
func testWycheproofP256DER() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp256r1_sha256_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA256.self) }
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA256.self, deserializeSignature: P256.Signing.ECDSASignature.init(derRepresentation:)) }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,18 +79,18 @@ class SignatureTests: XCTestCase {
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp256r1_sha512_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA512.self) }
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA512.self, deserializeSignature: P256.Signing.ECDSASignature.init(derRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testWycheProofP384() throws {
|
||||
func testWycheproofP384DER() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp384r1_sha384_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA384.self) }
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA384.self, deserializeSignature: P384.Signing.ECDSASignature.init(derRepresentation:)) }
|
||||
})
|
||||
}
|
||||
try orFail {
|
||||
@@ -97,18 +98,68 @@ class SignatureTests: XCTestCase {
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp384r1_sha512_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA512.self) }
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA512.self, deserializeSignature: P384.Signing.ECDSASignature.init(derRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testWycheProofP521() throws {
|
||||
func testWycheproofP521DER() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp521r1_sha512_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P521.Signing.self, hashFunction: SHA512.self) }
|
||||
try orFail { try testGroup(group: group, curve: P521.Signing.self, hashFunction: SHA512.self, deserializeSignature: P521.Signing.ECDSASignature.init(derRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testWycheproofP256P1363() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp256r1_sha256_p1363_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA256.self, deserializeSignature: P256.Signing.ECDSASignature.init(rawRepresentation:)) }
|
||||
})
|
||||
}
|
||||
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp256r1_sha512_p1363_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P256.Signing.self, hashFunction: SHA512.self, deserializeSignature: P256.Signing.ECDSASignature.init(rawRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testWycheproofP384P1363() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp384r1_sha384_p1363_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA384.self, deserializeSignature: P384.Signing.ECDSASignature.init(rawRepresentation:)) }
|
||||
})
|
||||
}
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp384r1_sha512_p1363_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P384.Signing.self, hashFunction: SHA512.self, deserializeSignature: P384.Signing.ECDSASignature.init(rawRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testWycheproofP521P1363() throws {
|
||||
try orFail {
|
||||
try wycheproofTest(
|
||||
bundleType: self,
|
||||
jsonName: "ecdsa_secp521r1_sha512_p1363_test",
|
||||
testFunction: { (group: ECDSATestGroup) in
|
||||
try orFail { try testGroup(group: group, curve: P521.Signing.self, hashFunction: SHA512.self, deserializeSignature: P521.Signing.ECDSASignature.init(rawRepresentation:)) }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -148,7 +199,7 @@ class SignatureTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testGroup<C: NISTSigning, HF: HashFunction>(group: ECDSATestGroup, curve: C.Type, hashFunction: HF.Type, file: StaticString = #file, line: UInt = #line) throws where C.ECDSASignature == C.PublicKey.Signature {
|
||||
func testGroup<C: NISTSigning, HF: HashFunction>(group: ECDSATestGroup, curve: C.Type, hashFunction: HF.Type, deserializeSignature: (Data) throws -> C.ECDSASignature, file: StaticString = #file, line: UInt = #line) throws where C.ECDSASignature == C.PublicKey.Signature {
|
||||
let keyBytes = try orFail(file: file, line: line) { try Array(hexString: group.publicKey.uncompressed) }
|
||||
let key = try orFail(file: file, line: line) { try C.PublicKey(x963Representation: keyBytes) }
|
||||
|
||||
@@ -165,7 +216,7 @@ class SignatureTests: XCTestCase {
|
||||
|
||||
let digest = HF.hash(data: msg)
|
||||
|
||||
let signature = try C.ECDSASignature(derRepresentation: sig)
|
||||
let signature = try deserializeSignature(sig)
|
||||
|
||||
isValid = key.isValidSignature(signature, for: digest)
|
||||
} catch {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user