summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-11-06 15:17:02 +0000
committertb <>2023-11-06 15:17:02 +0000
commit59fa23f90a8faf4520e9a24019a3c71c2d81a9e1 (patch)
treeda17a6e5039ac4948df587004db0732f0f51b7b3
parent582bb3a80d27e2c82069e50309c478f7fe127886 (diff)
downloadopenbsd-59fa23f90a8faf4520e9a24019a3c71c2d81a9e1.tar.gz
openbsd-59fa23f90a8faf4520e9a24019a3c71c2d81a9e1.tar.bz2
openbsd-59fa23f90a8faf4520e9a24019a3c71c2d81a9e1.zip
Introduce testGroupFromAlgorithm()
This factors another ugly switch into a helper function. This should probably become a map eventually, but for now keep things straightforward.
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go104
1 files changed, 54 insertions, 50 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index ef88532a15..feeb6c897f 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.149 2023/11/06 15:14:52 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.150 2023/11/06 15:17:02 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,2022 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018,2019,2022 Theo Buehler <tb@openbsd.org>
@@ -2765,6 +2765,57 @@ func (wtg *wycheproofTestGroupX25519) run(algorithm string, variant testVariant)
2765 return success 2765 return success
2766} 2766}
2767 2767
2768func testGroupFromAlgorithm(algorithm string, variant testVariant) wycheproofTestGroupRunner {
2769 switch algorithm {
2770 case "AES-CBC-PKCS5":
2771 return &wycheproofTestGroupAesCbcPkcs5{}
2772 case "AES-CCM", "AES-GCM":
2773 return &wycheproofTestGroupAesAead{}
2774 case "AES-CMAC":
2775 return &wycheproofTestGroupAesCmac{}
2776 case "CHACHA20-POLY1305", "XCHACHA20-POLY1305":
2777 return &wycheproofTestGroupChaCha{}
2778 case "DSA":
2779 return &wycheproofTestGroupDSA{}
2780 case "ECDH":
2781 switch variant {
2782 case Webcrypto:
2783 return &wycheproofTestGroupECDHWebCrypto{}
2784 default:
2785 return &wycheproofTestGroupECDH{}
2786 }
2787 case "ECDSA":
2788 switch variant {
2789 case Webcrypto:
2790 return &wycheproofTestGroupECDSAWebCrypto{}
2791 default:
2792 return &wycheproofTestGroupECDSA{}
2793 }
2794 case "EDDSA":
2795 return &wycheproofTestGroupEdDSA{}
2796 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512":
2797 return &wycheproofTestGroupHkdf{}
2798 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512", "HMACSHA3-224", "HMACSHA3-256", "HMACSHA3-384", "HMACSHA3-512":
2799 return &wycheproofTestGroupHmac{}
2800 case "KW":
2801 return &wycheproofTestGroupKW{}
2802 case "PrimalityTest":
2803 return &wycheproofTestGroupPrimality{}
2804 case "RSAES-OAEP":
2805 return &wycheproofTestGroupRsaesOaep{}
2806 case "RSAES-PKCS1-v1_5":
2807 return &wycheproofTestGroupRsaesPkcs1{}
2808 case "RSASSA-PSS":
2809 return &wycheproofTestGroupRsassa{}
2810 case "RSASSA-PKCS1-v1_5", "RSASig":
2811 return &wycheproofTestGroupRSA{}
2812 case "XDH", "X25519":
2813 return &wycheproofTestGroupX25519{}
2814 default:
2815 return nil
2816 }
2817}
2818
2768func runTestVectors(path string, variant testVariant) bool { 2819func runTestVectors(path string, variant testVariant) bool {
2769 b, err := ioutil.ReadFile(path) 2820 b, err := ioutil.ReadFile(path)
2770 if err != nil { 2821 if err != nil {
@@ -2781,55 +2832,8 @@ func runTestVectors(path string, variant testVariant) bool {
2781 for _, tg := range wtv.TestGroups { 2832 for _, tg := range wtv.TestGroups {
2782 testGroupJSON := tg 2833 testGroupJSON := tg
2783 testc.runTest(func() bool { 2834 testc.runTest(func() bool {
2784 var wtg wycheproofTestGroupRunner 2835 wtg := testGroupFromAlgorithm(wtv.Algorithm, variant)
2785 switch wtv.Algorithm { 2836 if wtg == nil {
2786 case "AES-CBC-PKCS5":
2787 wtg = &wycheproofTestGroupAesCbcPkcs5{}
2788 case "AES-CCM":
2789 wtg = &wycheproofTestGroupAesAead{}
2790 case "AES-CMAC":
2791 wtg = &wycheproofTestGroupAesCmac{}
2792 case "AES-GCM":
2793 wtg = &wycheproofTestGroupAesAead{}
2794 case "CHACHA20-POLY1305", "XCHACHA20-POLY1305":
2795 wtg = &wycheproofTestGroupChaCha{}
2796 case "DSA":
2797 wtg = &wycheproofTestGroupDSA{}
2798 case "ECDH":
2799 switch variant {
2800 case Webcrypto:
2801 wtg = &wycheproofTestGroupECDHWebCrypto{}
2802 default:
2803 wtg = &wycheproofTestGroupECDH{}
2804 }
2805 case "ECDSA":
2806 switch variant {
2807 case Webcrypto:
2808 wtg = &wycheproofTestGroupECDSAWebCrypto{}
2809 default:
2810 wtg = &wycheproofTestGroupECDSA{}
2811 }
2812 case "EDDSA":
2813 wtg = &wycheproofTestGroupEdDSA{}
2814 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512":
2815 wtg = &wycheproofTestGroupHkdf{}
2816 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512", "HMACSHA3-224", "HMACSHA3-256", "HMACSHA3-384", "HMACSHA3-512":
2817 wtg = &wycheproofTestGroupHmac{}
2818 case "KW":
2819 wtg = &wycheproofTestGroupKW{}
2820 case "PrimalityTest":
2821 wtg = &wycheproofTestGroupPrimality{}
2822 case "RSAES-OAEP":
2823 wtg = &wycheproofTestGroupRsaesOaep{}
2824 case "RSAES-PKCS1-v1_5":
2825 wtg = &wycheproofTestGroupRsaesPkcs1{}
2826 case "RSASSA-PSS":
2827 wtg = &wycheproofTestGroupRsassa{}
2828 case "RSASSA-PKCS1-v1_5", "RSASig":
2829 wtg = &wycheproofTestGroupRSA{}
2830 case "XDH", "X25519":
2831 wtg = &wycheproofTestGroupX25519{}
2832 default:
2833 log.Printf("INFO: Unknown test vector algorithm %q", wtv.Algorithm) 2837 log.Printf("INFO: Unknown test vector algorithm %q", wtv.Algorithm)
2834 return false 2838 return false
2835 } 2839 }