summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go75
1 files changed, 48 insertions, 27 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index 3f3dd82903..3dd776241e 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.107 2019/11/28 23:13:34 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.108 2019/12/03 15:59:24 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>
@@ -64,6 +64,18 @@ import (
64 64
65const testVectorPath = "/usr/local/share/wycheproof/testvectors" 65const testVectorPath = "/usr/local/share/wycheproof/testvectors"
66 66
67type testVariant int
68
69const (
70 Normal testVariant = 0
71 P1363 testVariant = 1
72 Webcrypto testVariant = 2
73 Asn1 testVariant = 3
74 Pem testVariant = 4
75 Jwk testVariant = 5
76 Skip testVariant = 6
77)
78
67var acceptableAudit = false 79var acceptableAudit = false
68var acceptableComments map[string]int 80var acceptableComments map[string]int
69var acceptableFlags map[string]int 81var acceptableFlags map[string]int
@@ -2392,7 +2404,7 @@ func runX25519TestGroup(algorithm string, wtg *wycheproofTestGroupX25519) bool {
2392 return success 2404 return success
2393} 2405}
2394 2406
2395func runTestVectors(path string, webcrypto bool) bool { 2407func runTestVectors(path string, variant testVariant) bool {
2396 b, err := ioutil.ReadFile(path) 2408 b, err := ioutil.ReadFile(path)
2397 if err != nil { 2409 if err != nil {
2398 log.Fatalf("Failed to read test vectors: %v", err) 2410 log.Fatalf("Failed to read test vectors: %v", err)
@@ -2419,15 +2431,17 @@ func runTestVectors(path string, webcrypto bool) bool {
2419 case "DSA": 2431 case "DSA":
2420 wtg = &wycheproofTestGroupDSA{} 2432 wtg = &wycheproofTestGroupDSA{}
2421 case "ECDH": 2433 case "ECDH":
2422 if webcrypto { 2434 switch variant {
2435 case Webcrypto:
2423 wtg = &wycheproofTestGroupECDHWebCrypto{} 2436 wtg = &wycheproofTestGroupECDHWebCrypto{}
2424 } else { 2437 default:
2425 wtg = &wycheproofTestGroupECDH{} 2438 wtg = &wycheproofTestGroupECDH{}
2426 } 2439 }
2427 case "ECDSA": 2440 case "ECDSA":
2428 if webcrypto { 2441 switch variant {
2442 case Webcrypto:
2429 wtg = &wycheproofTestGroupECDSAWebCrypto{} 2443 wtg = &wycheproofTestGroupECDSAWebCrypto{}
2430 } else { 2444 default:
2431 wtg = &wycheproofTestGroupECDSA{} 2445 wtg = &wycheproofTestGroupECDSA{}
2432 } 2446 }
2433 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512": 2447 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512":
@@ -2480,21 +2494,23 @@ func runTestVectors(path string, webcrypto bool) bool {
2480 success = false 2494 success = false
2481 } 2495 }
2482 case "ECDH": 2496 case "ECDH":
2483 if webcrypto { 2497 switch variant {
2498 case Webcrypto:
2484 if !runECDHWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDHWebCrypto)) { 2499 if !runECDHWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDHWebCrypto)) {
2485 success = false 2500 success = false
2486 } 2501 }
2487 } else { 2502 default:
2488 if !runECDHTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDH)) { 2503 if !runECDHTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDH)) {
2489 success = false 2504 success = false
2490 } 2505 }
2491 } 2506 }
2492 case "ECDSA": 2507 case "ECDSA":
2493 if webcrypto { 2508 switch variant {
2509 case Webcrypto:
2494 if !runECDSAWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSAWebCrypto)) { 2510 if !runECDSAWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSAWebCrypto)) {
2495 success = false 2511 success = false
2496 } 2512 }
2497 } else { 2513 default:
2498 if !runECDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSA)) { 2514 if !runECDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSA)) {
2499 success = false 2515 success = false
2500 } 2516 }
@@ -2554,21 +2570,27 @@ func main() {
2554 tests := []struct { 2570 tests := []struct {
2555 name string 2571 name string
2556 pattern string 2572 pattern string
2573 variant testVariant
2557 }{ 2574 }{
2558 {"AES", "aes_[cg]*[^xv]_test.json"}, // Skip AES-EAX, AES-GCM-SIV and AES-SIV-CMAC. 2575 {"AES", "aes_[cg]*[^xv]_test.json", Normal}, // Skip AES-EAX, AES-GCM-SIV and AES-SIV-CMAC.
2559 {"ChaCha20-Poly1305", "chacha20_poly1305_test.json"}, 2576 {"ChaCha20-Poly1305", "chacha20_poly1305_test.json", Normal},
2560 {"DSA", "dsa_*test.json"}, 2577 {"DSA", "dsa_*test.json", Normal},
2561 {"ECDH", "ecdh_test.json"}, 2578 {"DSA", "dsa_*_p1363_test.json", Skip},
2562 {"ECDH", "ecdh_[^w]*test.json"}, 2579 {"ECDH", "ecdh_test.json", Normal},
2563 {"ECDHWebCrypto", "ecdh_webcrypto_test.json"}, 2580 {"ECDH", "ecdh_[^w]*test.json", Normal},
2564 {"ECDSA", "ecdsa_[^w]*test.json"}, 2581 {"ECDH webcrypto", "ecdh_webcrypto_test.json", Webcrypto},
2565 {"ECDSA", "ecdsa_test.json"}, 2582 {"ECDSA", "ecdsa_test.json", Normal},
2566 {"ECDSAWebCrypto", "ecdsa_webcrypto_test.json"}, 2583 {"ECDSA", "ecdsa_[^w]*test.json", Normal},
2567 {"HKDF", "hkdf_sha*_test.json"}, 2584 {"ECDSA P1363", "ecdsa_*_p1363_test.json", Skip},
2568 {"KW", "kw_test.json"}, 2585 {"ECDSA webcrypto", "ecdsa_webcrypto_test.json", Webcrypto},
2569 {"RSA", "rsa_*test.json"}, 2586 {"HKDF", "hkdf_sha*_test.json", Normal},
2570 {"X25519", "x25519_test.json"}, 2587 {"KW", "kw_test.json", Normal},
2571 {"XCHACHA20-POLY1305", "xchacha20_poly1305_test.json"}, 2588 {"RSA", "rsa_*test.json", Normal},
2589 {"X25519", "x25519_test.json", Normal},
2590 {"X25519 ASN", "x25519_asn_test.json", Skip},
2591 {"X25519 JWK", "x25519_jwk_test.json", Skip},
2592 {"X25519 PEM", "x25519_pem_test.json", Skip},
2593 {"XCHACHA20-POLY1305", "xchacha20_poly1305_test.json", Normal},
2572 } 2594 }
2573 2595
2574 success := true 2596 success := true
@@ -2576,7 +2598,6 @@ func main() {
2576 skip := regexp.MustCompile(`_(p1363|sha3|sha512_(224|256))_`) 2598 skip := regexp.MustCompile(`_(p1363|sha3|sha512_(224|256))_`)
2577 2599
2578 for _, test := range tests { 2600 for _, test := range tests {
2579 webcrypto := test.name == "ECDSAWebCrypto" || test.name == "ECDHWebCrypto"
2580 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) 2601 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern))
2581 if err != nil { 2602 if err != nil {
2582 log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) 2603 log.Fatalf("Failed to glob %v test vectors: %v", test.name, err)
@@ -2586,11 +2607,11 @@ func main() {
2586 // log.Fatalf("Failed to find %v test vectors at %q\n", test.name, testVectorPath) 2607 // log.Fatalf("Failed to find %v test vectors at %q\n", test.name, testVectorPath)
2587 // } 2608 // }
2588 for _, tv := range tvs { 2609 for _, tv := range tvs {
2589 if skip.Match([]byte(tv)) { 2610 if test.variant == Skip || (test.variant == Normal && skip.Match([]byte(tv))) {
2590 fmt.Printf("INFO: Skipping tests from \"%s\"\n", strings.TrimPrefix(tv, testVectorPath+"/")) 2611 fmt.Printf("INFO: Skipping tests from \"%s\"\n", strings.TrimPrefix(tv, testVectorPath+"/"))
2591 continue 2612 continue
2592 } 2613 }
2593 if !runTestVectors(tv, webcrypto) { 2614 if !runTestVectors(tv, test.variant) {
2594 success = false 2615 success = false
2595 } 2616 }
2596 } 2617 }