diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 106 |
1 files changed, 38 insertions, 68 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index b6f9c3c208..63b8eedb8e 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.180 2025/09/05 14:09:09 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.181 2025/09/05 14:11:39 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018,2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018,2023 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2018,2019,2022-2024 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018,2019,2022-2024 Theo Buehler <tb@openbsd.org> |
@@ -92,7 +92,7 @@ import ( | |||
92 | "unsafe" | 92 | "unsafe" |
93 | ) | 93 | ) |
94 | 94 | ||
95 | const testVectorPath = "/usr/local/share/wycheproof/testvectors" | 95 | const testVectorPath = "/usr/local/share/wycheproof/testvectors_v1" |
96 | 96 | ||
97 | type testVariant int | 97 | type testVariant int |
98 | 98 | ||
@@ -671,22 +671,6 @@ type wycheproofTestGroupRunner interface { | |||
671 | run(string, testVariant) bool | 671 | run(string, testVariant) bool |
672 | } | 672 | } |
673 | 673 | ||
674 | type wycheproofVersion int | ||
675 | |||
676 | const ( | ||
677 | v0 wycheproofVersion = iota | ||
678 | v1 | ||
679 | ) | ||
680 | |||
681 | type wycheproofTestVectors struct { | ||
682 | Algorithm string `json:"algorithm"` | ||
683 | GeneratorVersion string `json:"generatorVersion"` | ||
684 | Notes map[string]string `json:"notes"` | ||
685 | NumberOfTests int `json:"numberOfTests"` | ||
686 | // Header | ||
687 | TestGroups []json.RawMessage `json:"testGroups"` | ||
688 | } | ||
689 | |||
690 | type wycheproofTestVectorsV1 struct { | 674 | type wycheproofTestVectorsV1 struct { |
691 | Algorithm string `json:"algorithm"` | 675 | Algorithm string `json:"algorithm"` |
692 | Schema string `json:"schema"` | 676 | Schema string `json:"schema"` |
@@ -2847,30 +2831,20 @@ func testGroupFromAlgorithm(algorithm string, variant testVariant) wycheproofTes | |||
2847 | } | 2831 | } |
2848 | } | 2832 | } |
2849 | 2833 | ||
2850 | func runTestVectors(path string, variant testVariant, version wycheproofVersion) bool { | 2834 | func runTestVectors(path string, variant testVariant) bool { |
2851 | var algorithm string | 2835 | var algorithm string |
2852 | var testGroups []json.RawMessage | 2836 | var testGroups []json.RawMessage |
2853 | b, err := ioutil.ReadFile(path) | 2837 | b, err := ioutil.ReadFile(path) |
2854 | if err != nil { | 2838 | if err != nil { |
2855 | log.Fatalf("Failed to read test vectors: %v", err) | 2839 | log.Fatalf("Failed to read test vectors: %v", err) |
2856 | } | 2840 | } |
2857 | if version == v0 { | 2841 | wtv := &wycheproofTestVectorsV1{} |
2858 | wtv := &wycheproofTestVectors{} | 2842 | if err := json.Unmarshal(b, wtv); err != nil { |
2859 | if err := json.Unmarshal(b, wtv); err != nil { | 2843 | log.Fatalf("Failed to unmarshal JSON: %v", err) |
2860 | log.Fatalf("Failed to unmarshal JSON: %v", err) | ||
2861 | } | ||
2862 | algorithm = wtv.Algorithm | ||
2863 | testGroups = wtv.TestGroups | ||
2864 | fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) | ||
2865 | } else { | ||
2866 | wtv := &wycheproofTestVectorsV1{} | ||
2867 | if err := json.Unmarshal(b, wtv); err != nil { | ||
2868 | log.Fatalf("Failed to unmarshal JSON: %v", err) | ||
2869 | } | ||
2870 | algorithm = wtv.Algorithm | ||
2871 | testGroups = wtv.TestGroups | ||
2872 | fmt.Printf("Loaded Wycheproof v1 test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) | ||
2873 | } | 2844 | } |
2845 | algorithm = wtv.Algorithm | ||
2846 | testGroups = wtv.TestGroups | ||
2847 | fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) | ||
2874 | 2848 | ||
2875 | success := true | 2849 | success := true |
2876 | for _, tg := range testGroups { | 2850 | for _, tg := range testGroups { |
@@ -2931,42 +2905,42 @@ func (tc *testCoordinator) shutdown() { | |||
2931 | } | 2905 | } |
2932 | 2906 | ||
2933 | func main() { | 2907 | func main() { |
2934 | if _, err := os.Stat(testVectorPath); os.IsNotExist(err) { | 2908 | path := testVectorPath |
2909 | if _, err := os.Stat(path); os.IsNotExist(err) { | ||
2935 | fmt.Printf("package wycheproof-testvectors is required for this regress\n") | 2910 | fmt.Printf("package wycheproof-testvectors is required for this regress\n") |
2936 | fmt.Printf("SKIPPED\n") | 2911 | fmt.Printf("SKIPPED\n") |
2937 | os.Exit(0) | 2912 | os.Exit(0) |
2938 | } | 2913 | } |
2939 | 2914 | ||
2940 | tests := []struct { | 2915 | tests := []struct { |
2941 | version wycheproofVersion | ||
2942 | name string | 2916 | name string |
2943 | pattern string | 2917 | pattern string |
2944 | variant testVariant | 2918 | variant testVariant |
2945 | }{ | 2919 | }{ |
2946 | {v1, "AES", "aes_[cg]*[^xv]_test.json", Normal}, // Skip AES-EAX, AES-GCM-SIV and AES-SIV-CMAC. | 2920 | {"AES", "aes_[cg]*[^xv]_test.json", Normal}, // Skip AES-EAX, AES-GCM-SIV and AES-SIV-CMAC. |
2947 | {v1, "AES-WRAP", "aes_wrap_test.json", Normal}, | 2921 | {"AES-WRAP", "aes_wrap_test.json", Normal}, |
2948 | {v1, "ChaCha20-Poly1305", "chacha20_poly1305_test.json", Normal}, | 2922 | {"ChaCha20-Poly1305", "chacha20_poly1305_test.json", Normal}, |
2949 | {v1, "DSA", "dsa_*test.json", Normal}, | 2923 | {"DSA", "dsa_*test.json", Normal}, |
2950 | {v1, "DSA", "dsa_*_p1363_test.json", P1363}, | 2924 | {"DSA", "dsa_*_p1363_test.json", P1363}, |
2951 | {v1, "EcCurveTest", "ec_prime_order_curves_test.json", Normal}, | 2925 | {"EcCurveTest", "ec_prime_order_curves_test.json", Normal}, |
2952 | {v1, "ECDH", "ecdh_[^w_]*_test.json", Normal}, | 2926 | {"ECDH", "ecdh_[^w_]*_test.json", Normal}, |
2953 | {v1, "ECDH EcPoint", "ecdh_*_ecpoint_test.json", EcPoint}, | 2927 | {"ECDH EcPoint", "ecdh_*_ecpoint_test.json", EcPoint}, |
2954 | {v1, "ECDH webcrypto", "ecdh_*_webcrypto_test.json", Webcrypto}, | 2928 | {"ECDH webcrypto", "ecdh_*_webcrypto_test.json", Webcrypto}, |
2955 | {v1, "ECDSA", "ecdsa_[^w]*test.json", Normal}, | 2929 | {"ECDSA", "ecdsa_[^w]*test.json", Normal}, |
2956 | {v1, "ECDSA P1363", "ecdsa_*_sha[1-9][1-9][1-9]_p1363_test.json", P1363}, | 2930 | {"ECDSA P1363", "ecdsa_*_sha[1-9][1-9][1-9]_p1363_test.json", P1363}, |
2957 | {v1, "ECDSA webcrypto", "ecdsa_*_webcrypto_test.json", Webcrypto}, | 2931 | {"ECDSA webcrypto", "ecdsa_*_webcrypto_test.json", Webcrypto}, |
2958 | {v1, "ECDSA shake", "ecdsa_*_shake*_test.json", Skip}, | 2932 | {"ECDSA shake", "ecdsa_*_shake*_test.json", Skip}, |
2959 | {v1, "EDDSA", "ed25519_test.json", Normal}, | 2933 | {"EDDSA", "ed25519_test.json", Normal}, |
2960 | {v1, "ED448", "ed448_test.json", Skip}, | 2934 | {"ED448", "ed448_test.json", Skip}, |
2961 | {v1, "HKDF", "hkdf_sha*_test.json", Normal}, | 2935 | {"HKDF", "hkdf_sha*_test.json", Normal}, |
2962 | {v1, "HMAC", "hmac_sha*_test.json", Normal}, | 2936 | {"HMAC", "hmac_sha*_test.json", Normal}, |
2963 | {v1, "Primality test", "primality_test.json", Normal}, | 2937 | {"Primality test", "primality_test.json", Normal}, |
2964 | {v1, "RSA", "rsa_*test.json", Normal}, | 2938 | {"RSA", "rsa_*test.json", Normal}, |
2965 | {v1, "X25519", "x25519_test.json", Normal}, | 2939 | {"X25519", "x25519_test.json", Normal}, |
2966 | {v1, "X25519 ASN", "x25519_asn_test.json", Skip}, | 2940 | {"X25519 ASN", "x25519_asn_test.json", Skip}, |
2967 | {v1, "X25519 JWK", "x25519_jwk_test.json", Skip}, | 2941 | {"X25519 JWK", "x25519_jwk_test.json", Skip}, |
2968 | {v1, "X25519 PEM", "x25519_pem_test.json", Skip}, | 2942 | {"X25519 PEM", "x25519_pem_test.json", Skip}, |
2969 | {v1, "XCHACHA20-POLY1305", "xchacha20_poly1305_test.json", Normal}, | 2943 | {"XCHACHA20-POLY1305", "xchacha20_poly1305_test.json", Normal}, |
2970 | } | 2944 | } |
2971 | 2945 | ||
2972 | success := true | 2946 | success := true |
@@ -2984,10 +2958,6 @@ func main() { | |||
2984 | skipNormal := regexp.MustCompile(`_(ecpoint|webcrypto|pem|bitcoin|shake\d{3}|gmac|p1363|sect\d{3}[rk]1|secp(160|192))_`) | 2958 | skipNormal := regexp.MustCompile(`_(ecpoint|webcrypto|pem|bitcoin|shake\d{3}|gmac|p1363|sect\d{3}[rk]1|secp(160|192))_`) |
2985 | 2959 | ||
2986 | for _, test := range tests { | 2960 | for _, test := range tests { |
2987 | path := testVectorPath | ||
2988 | if test.version == v1 { | ||
2989 | path = path + "_v1" | ||
2990 | } | ||
2991 | tvs, err := filepath.Glob(filepath.Join(path, test.pattern)) | 2961 | tvs, err := filepath.Glob(filepath.Join(path, test.pattern)) |
2992 | if err != nil { | 2962 | if err != nil { |
2993 | log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) | 2963 | log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) |
@@ -3002,15 +2972,15 @@ func main() { | |||
3002 | } | 2972 | } |
3003 | wg.Add(1) | 2973 | wg.Add(1) |
3004 | <-vectorsRateLimitCh | 2974 | <-vectorsRateLimitCh |
3005 | go func(tv string, variant testVariant, version wycheproofVersion) { | 2975 | go func(tv string, variant testVariant) { |
3006 | select { | 2976 | select { |
3007 | case resultCh <- runTestVectors(tv, variant, version): | 2977 | case resultCh <- runTestVectors(tv, variant): |
3008 | default: | 2978 | default: |
3009 | log.Fatal("result channel is full") | 2979 | log.Fatal("result channel is full") |
3010 | } | 2980 | } |
3011 | vectorsRateLimitCh <- true | 2981 | vectorsRateLimitCh <- true |
3012 | wg.Done() | 2982 | wg.Done() |
3013 | }(tv, test.variant, test.version) | 2983 | }(tv, test.variant) |
3014 | } | 2984 | } |
3015 | } | 2985 | } |
3016 | 2986 | ||