Update Wycheproof ecdh_secp256r1_test.json to v1 (#160)

This commit is contained in:
Alexander Cyon 2023-04-03 11:14:02 +02:00 committed by GitHub
parent 25a68d63b7
commit 6be84be0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5645 additions and 2311 deletions

View File

@ -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
}
}
@ -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

File diff suppressed because one or more lines are too long