From 23e9aec99b00cb9bc5aabb39975341f411c0db55 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Thu, 26 Jul 2018 11:40:47 -0700 Subject: [PATCH] Support Wycheproof vectors with the curve given in the group. Future versions of the Wycheproof vectors will specify the curve for a group of tests, rather than for each test. This change works with both the old and new style. Change-Id: I0d9a503c8357eb4c617544e727d8f4a703c2c2b0 Reviewed-on: https://boringssl-review.googlesource.com/30084 Reviewed-by: Adam Langley --- util/convert_wycheproof.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/convert_wycheproof.go b/util/convert_wycheproof.go index 2f2acae1..0d1432a1 100644 --- a/util/convert_wycheproof.go +++ b/util/convert_wycheproof.go @@ -157,7 +157,8 @@ func convertWycheproof(f io.Writer, jsonPath string) error { // Skip tests with unsupported curves. We filter these out at // conversion time to avoid unnecessarily inflating // crypto_test_data.cc. - if curve, ok := group["curve"]; ok && !isSupportedCurve(curve.(string)) { + groupCurve := group["curve"] + if groupCurve != nil && !isSupportedCurve(groupCurve.(string)) { continue } if keyI, ok := group["key"]; ok { @@ -183,8 +184,10 @@ func convertWycheproof(f io.Writer, jsonPath string) error { tests := group["tests"].([]interface{}) for _, testI := range tests { test := testI.(map[string]interface{}) + + curve := test["curve"] // Skip tests with unsupported curves. - if curve, ok := test["curve"]; ok && !isSupportedCurve(curve.(string)) { + if curve != nil && !isSupportedCurve(curve.(string)) { continue } if _, err := fmt.Fprintf(f, "# tcId = %d\n", int(test["tcId"].(float64))); err != nil { @@ -203,6 +206,13 @@ func convertWycheproof(f io.Writer, jsonPath string) error { return err } } + // If the curve was only specified at the group level then copy it into + // each test. + if curve == nil && groupCurve != nil { + if err := printAttribute(f, "curve", groupCurve, false); err != nil { + return err + } + } if flags, ok := test["flags"]; ok { for _, flag := range flags.([]interface{}) { if note, ok := w.Notes[flag.(string)]; ok {