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 <agl@google.com>
diff --git a/util/convert_wycheproof.go b/util/convert_wycheproof.go
index 2f2acae..0d1432a 100644
--- a/util/convert_wycheproof.go
+++ b/util/convert_wycheproof.go
@@ -157,7 +157,8 @@
 		// 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 @@
 		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 @@
 					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 {