summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authortb <>2019-12-03 16:02:49 +0000
committertb <>2019-12-03 16:02:49 +0000
commit707f682b7a9172496ab9df20ec87bba59d62e3ef (patch)
tree5c3974c9fde2e1ee7d666d056740b02384562382 /src/regress/lib
parent3111e517bb111c8a24ebef616c9157b570c93f8b (diff)
downloadopenbsd-707f682b7a9172496ab9df20ec87bba59d62e3ef.tar.gz
openbsd-707f682b7a9172496ab9df20ec87bba59d62e3ef.tar.bz2
openbsd-707f682b7a9172496ab9df20ec87bba59d62e3ef.zip
Add an EcPoint variant and pass it to the ECDH test runner.
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index 3dd776241e..2e8513dddf 100644
--- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go
+++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
@@ -1,4 +1,4 @@
1/* $OpenBSD: wycheproof.go,v 1.108 2019/12/03 15:59:24 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.109 2019/12/03 16:02:49 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org>
@@ -68,14 +68,29 @@ type testVariant int
68 68
69const ( 69const (
70 Normal testVariant = 0 70 Normal testVariant = 0
71 P1363 testVariant = 1 71 EcPoint testVariant = 1
72 Webcrypto testVariant = 2 72 P1363 testVariant = 2
73 Asn1 testVariant = 3 73 Webcrypto testVariant = 3
74 Pem testVariant = 4 74 Asn1 testVariant = 4
75 Jwk testVariant = 5 75 Pem testVariant = 5
76 Skip testVariant = 6 76 Jwk testVariant = 6
77 Skip testVariant = 7
77) 78)
78 79
80func (variant testVariant) String() string {
81 variants := [...]string{
82 "Normal",
83 "EcPoint",
84 "P1363",
85 "Webcrypto",
86 "Asn1",
87 "Pem",
88 "Jwk",
89 "Skip",
90 }
91 return variants[variant]
92}
93
79var acceptableAudit = false 94var acceptableAudit = false
80var acceptableComments map[string]int 95var acceptableComments map[string]int
81var acceptableFlags map[string]int 96var acceptableFlags map[string]int
@@ -1363,7 +1378,7 @@ func runDSATestGroup(algorithm string, wtg *wycheproofTestGroupDSA) bool {
1363 return success 1378 return success
1364} 1379}
1365 1380
1366func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { 1381func runECDHTest(nid int, variant testVariant, wt *wycheproofTestECDH) bool {
1367 privKey := C.EC_KEY_new_by_curve_name(C.int(nid)) 1382 privKey := C.EC_KEY_new_by_curve_name(C.int(nid))
1368 if privKey == nil { 1383 if privKey == nil {
1369 log.Fatalf("EC_KEY_new_by_curve_name failed") 1384 log.Fatalf("EC_KEY_new_by_curve_name failed")
@@ -1403,7 +1418,7 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool {
1403 1418
1404 p := (*C.uchar)(Cpub) 1419 p := (*C.uchar)(Cpub)
1405 var pubKey *C.EC_KEY 1420 var pubKey *C.EC_KEY
1406 if doECpoint { 1421 if variant == EcPoint {
1407 pubKey = C.EC_KEY_new_by_curve_name(C.int(nid)) 1422 pubKey = C.EC_KEY_new_by_curve_name(C.int(nid))
1408 if pubKey == nil { 1423 if pubKey == nil {
1409 log.Fatal("EC_KEY_new_by_curve_name failed") 1424 log.Fatal("EC_KEY_new_by_curve_name failed")
@@ -1462,12 +1477,7 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool {
1462 return success 1477 return success
1463} 1478}
1464 1479
1465func runECDHTestGroup(algorithm string, wtg *wycheproofTestGroupECDH) bool { 1480func runECDHTestGroup(algorithm string, variant testVariant, wtg *wycheproofTestGroupECDH) bool {
1466 doECpoint := false
1467 if wtg.Encoding == "ecpoint" {
1468 doECpoint = true
1469 }
1470
1471 // XXX 1481 // XXX
1472 if wtg.Curve == "secp224k1" { 1482 if wtg.Curve == "secp224k1" {
1473 fmt.Printf("INFO: skipping %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding) 1483 fmt.Printf("INFO: skipping %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding)
@@ -1484,7 +1494,7 @@ func runECDHTestGroup(algorithm string, wtg *wycheproofTestGroupECDH) bool {
1484 1494
1485 success := true 1495 success := true
1486 for _, wt := range wtg.Tests { 1496 for _, wt := range wtg.Tests {
1487 if !runECDHTest(nid, doECpoint, wt) { 1497 if !runECDHTest(nid, variant, wt) {
1488 success = false 1498 success = false
1489 } 1499 }
1490 } 1500 }
@@ -2500,7 +2510,7 @@ func runTestVectors(path string, variant testVariant) bool {
2500 success = false 2510 success = false
2501 } 2511 }
2502 default: 2512 default:
2503 if !runECDHTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDH)) { 2513 if !runECDHTestGroup(wtv.Algorithm, variant, wtg.(*wycheproofTestGroupECDH)) {
2504 success = false 2514 success = false
2505 } 2515 }
2506 } 2516 }
@@ -2577,7 +2587,8 @@ func main() {
2577 {"DSA", "dsa_*test.json", Normal}, 2587 {"DSA", "dsa_*test.json", Normal},
2578 {"DSA", "dsa_*_p1363_test.json", Skip}, 2588 {"DSA", "dsa_*_p1363_test.json", Skip},
2579 {"ECDH", "ecdh_test.json", Normal}, 2589 {"ECDH", "ecdh_test.json", Normal},
2580 {"ECDH", "ecdh_[^w]*test.json", Normal}, 2590 {"ECDH", "ecdh_[^w_]*_test.json", Normal},
2591 {"ECDH EcPoint", "ecdh_*_ecpoint_test.json", EcPoint},
2581 {"ECDH webcrypto", "ecdh_webcrypto_test.json", Webcrypto}, 2592 {"ECDH webcrypto", "ecdh_webcrypto_test.json", Webcrypto},
2582 {"ECDSA", "ecdsa_test.json", Normal}, 2593 {"ECDSA", "ecdsa_test.json", Normal},
2583 {"ECDSA", "ecdsa_[^w]*test.json", Normal}, 2594 {"ECDSA", "ecdsa_[^w]*test.json", Normal},
@@ -2595,7 +2606,7 @@ func main() {
2595 2606
2596 success := true 2607 success := true
2597 2608
2598 skip := regexp.MustCompile(`_(p1363|sha3|sha512_(224|256))_`) 2609 skipNormal := regexp.MustCompile(`_(ecpoint|p1363|sha3|sha512_(224|256))_`)
2599 2610
2600 for _, test := range tests { 2611 for _, test := range tests {
2601 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) 2612 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern))
@@ -2607,7 +2618,7 @@ func main() {
2607 // log.Fatalf("Failed to find %v test vectors at %q\n", test.name, testVectorPath) 2618 // log.Fatalf("Failed to find %v test vectors at %q\n", test.name, testVectorPath)
2608 // } 2619 // }
2609 for _, tv := range tvs { 2620 for _, tv := range tvs {
2610 if test.variant == Skip || (test.variant == Normal && skip.Match([]byte(tv))) { 2621 if test.variant == Skip || (test.variant == Normal && skipNormal.Match([]byte(tv))) {
2611 fmt.Printf("INFO: Skipping tests from \"%s\"\n", strings.TrimPrefix(tv, testVectorPath+"/")) 2622 fmt.Printf("INFO: Skipping tests from \"%s\"\n", strings.TrimPrefix(tv, testVectorPath+"/"))
2612 continue 2623 continue
2613 } 2624 }