Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wycheproof testvectors to v1 #154

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ extension ArraySlice where Element == UInt8 {
self = self[self.index(after: subidentifierEndIndex)...]

// We need to compact the bits. These are 7-bit integers, which is really awkward.
return UInt(sevenBitBigEndianBytes: oidSlice)
guard let int = UInt(sevenBitBigEndianBytes: oidSlice) else {
// too big to parse, happens for Wycheproof vectors with comment "large integer in oid"
throw ECDHTestErrors.ParseSPKIFailure
}
return int
}
}

Expand All @@ -313,10 +317,13 @@ extension UInt {
}
}

init<Bytes: Collection>(sevenBitBigEndianBytes bytes: Bytes) where Bytes.Element == UInt8 {
init?<Bytes: Collection>(sevenBitBigEndianBytes bytes: Bytes) where Bytes.Element == UInt8 {
// We need to know how many bytes we _need_ to store this "int".
guard ((bytes.count * 7) + 7) / 8 <= MemoryLayout<UInt>.size else {
fatalError("Too big to parse")
// Too big to parse, this happens for e.g. Wycheproof in testvector 'ecdh_secp256r1_test' for
// tests with comment "large integer in oid", thus we let this
// initializer be failable.
return nil
}

self = 0
Expand Down
8 changes: 4 additions & 4 deletions Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ struct SignatureTestVector: Codable {

struct EdDSATestGroup: Codable {
let tests: [SignatureTestVector]
let key: EdDSAKey
let publicKey: EdDSAPublicKey
}

struct EdDSAKey: Codable {
struct EdDSAPublicKey: Codable {
let pk: String
}

Expand All @@ -57,7 +57,7 @@ class SignatureTests: XCTestCase {
try orFail {
try wycheproofTest(
bundleType: self,
jsonName: "eddsa_test",
jsonName: "ed25519_test",
testFunction: { (group: EdDSATestGroup) in
try orFail { try testEdGroup(group: group) }
})
Expand Down Expand Up @@ -114,7 +114,7 @@ class SignatureTests: XCTestCase {
}

func testEdGroup(group: EdDSATestGroup, file: StaticString = #file, line: UInt = #line) throws {
let keyBytes = try orFail { try Array(hexString: group.key.pk) }
let keyBytes = try orFail { try Array(hexString: group.publicKey.pk) }
let key = try orFail { try Curve25519.Signing.PublicKey(rawRepresentation: keyBytes) }

for testVector in group.tests {
Expand Down
Loading