From 1118fe21e2836602ad2f3fa691ac4126a59c42d6 Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 4 Sep 2025 16:48:42 +0000 Subject: wycheproof: add struct to support the testvector_v1 schema --- src/regress/lib/libcrypto/wycheproof/wycheproof.go | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 41ad449b96..0463a9b3be 100644 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -1,4 +1,4 @@ -/* $OpenBSD: wycheproof.go,v 1.164 2025/09/04 16:44:14 tb Exp $ */ +/* $OpenBSD: wycheproof.go,v 1.165 2025/09/04 16:48:42 tb Exp $ */ /* * Copyright (c) 2018,2023 Joel Sing * Copyright (c) 2018,2019,2022-2024 Theo Buehler @@ -594,6 +594,15 @@ type wycheproofTestVectors struct { TestGroups []json.RawMessage `json:"testGroups"` } +type wycheproofTestVectorsV1 struct { + Algorithm string `json:"algorithm"` + Schema string `json:"schema"` + NumberOfTests int `json:"numberOfTests"` + Header []string `json:"header"` + Notes json.RawMessage `json:"notes"` + TestGroups []json.RawMessage `json:"testGroups"` +} + var nids = map[string]int{ "brainpoolP224r1": C.NID_brainpoolP224r1, "brainpoolP256r1": C.NID_brainpoolP256r1, @@ -2658,13 +2667,23 @@ func runTestVectors(path string, variant testVariant, version wycheproofVersion) if err != nil { log.Fatalf("Failed to read test vectors: %v", err) } - wtv := &wycheproofTestVectors{} - if err := json.Unmarshal(b, wtv); err != nil { - log.Fatalf("Failed to unmarshal JSON: %v", err) + if version == v0 { + wtv := &wycheproofTestVectors{} + if err := json.Unmarshal(b, wtv); err != nil { + log.Fatalf("Failed to unmarshal JSON: %v", err) + } + algorithm = wtv.Algorithm + testGroups = wtv.TestGroups + fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) + } else { + wtv := &wycheproofTestVectorsV1{} + if err := json.Unmarshal(b, wtv); err != nil { + log.Fatalf("Failed to unmarshal JSON: %v", err) + } + algorithm = wtv.Algorithm + testGroups = wtv.TestGroups + fmt.Printf("Loaded Wycheproof v1 test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) } - algorithm = wtv.Algorithm - testGroups = wtv.TestGroups - fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", algorithm, wtv.NumberOfTests, filepath.Base(path)) success := true for _, tg := range testGroups { -- cgit v1.2.3-55-g6feb