summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-04-25 15:56:56 +0000
committertb <>2023-04-25 15:56:56 +0000
commit3e0ee65ba3ad76b2e0c8dd558a7f75c44bf51f56 (patch)
tree43cf635acdba08d76b2ee023c097c628174eb0c4 /src
parentd7b4ec4854b7d888ef6a51ad555989a9a9e0339d (diff)
downloadopenbsd-3e0ee65ba3ad76b2e0c8dd558a7f75c44bf51f56.tar.gz
openbsd-3e0ee65ba3ad76b2e0c8dd558a7f75c44bf51f56.tar.bz2
openbsd-3e0ee65ba3ad76b2e0c8dd558a7f75c44bf51f56.zip
Update Wycheproof.go to exercise truncated SHA-2 and SHA-3
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index b0485d27d6..18786d45ac 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.144 2023/04/17 15:11:00 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.145 2023/04/25 15:56:56 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>
@@ -550,6 +550,12 @@ var nids = map[string]int{
550 "SHA-256": C.NID_sha256, 550 "SHA-256": C.NID_sha256,
551 "SHA-384": C.NID_sha384, 551 "SHA-384": C.NID_sha384,
552 "SHA-512": C.NID_sha512, 552 "SHA-512": C.NID_sha512,
553 "SHA-512/224": C.NID_sha512_224,
554 "SHA-512/256": C.NID_sha512_256,
555 "SHA3-224": C.NID_sha3_224,
556 "SHA3-256": C.NID_sha3_256,
557 "SHA3-384": C.NID_sha3_384,
558 "SHA3-512": C.NID_sha3_512,
553} 559}
554 560
555func nidFromString(ns string) (int, error) { 561func nidFromString(ns string) (int, error) {
@@ -572,6 +578,18 @@ func hashEvpMdFromString(hs string) (*C.EVP_MD, error) {
572 return C.EVP_sha384(), nil 578 return C.EVP_sha384(), nil
573 case "SHA-512": 579 case "SHA-512":
574 return C.EVP_sha512(), nil 580 return C.EVP_sha512(), nil
581 case "SHA-512/224":
582 return C.EVP_sha512_224(), nil
583 case "SHA-512/256":
584 return C.EVP_sha512_256(), nil
585 case "SHA3-224":
586 return C.EVP_sha3_224(), nil
587 case "SHA3-256":
588 return C.EVP_sha3_256(), nil
589 case "SHA3-384":
590 return C.EVP_sha3_384(), nil
591 case "SHA3-512":
592 return C.EVP_sha3_512(), nil
575 default: 593 default:
576 return nil, fmt.Errorf("unknown hash %q", hs) 594 return nil, fmt.Errorf("unknown hash %q", hs)
577 } 595 }
@@ -2141,7 +2159,11 @@ func runHmacTest(md *C.EVP_MD, tagBytes int, wt *wycheproofTestHmac) bool {
2141 2159
2142func runHmacTestGroup(algorithm string, wtg *wycheproofTestGroupHmac) bool { 2160func runHmacTestGroup(algorithm string, wtg *wycheproofTestGroupHmac) bool {
2143 fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.KeySize, wtg.TagSize) 2161 fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.KeySize, wtg.TagSize)
2144 md, err := hashEvpMdFromString("SHA-" + strings.TrimPrefix(algorithm, "HMACSHA")) 2162 prefix := "SHA-"
2163 if strings.HasPrefix(algorithm, "HMACSHA3-") {
2164 prefix = "SHA"
2165 }
2166 md, err := hashEvpMdFromString(prefix + strings.TrimPrefix(algorithm, "HMACSHA"))
2145 if err != nil { 2167 if err != nil {
2146 log.Fatalf("Failed to get hash: %v", err) 2168 log.Fatalf("Failed to get hash: %v", err)
2147 } 2169 }
@@ -2783,7 +2805,7 @@ func runTestVectors(path string, variant testVariant) bool {
2783 wtg = &wycheproofTestGroupEdDSA{} 2805 wtg = &wycheproofTestGroupEdDSA{}
2784 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512": 2806 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512":
2785 wtg = &wycheproofTestGroupHkdf{} 2807 wtg = &wycheproofTestGroupHkdf{}
2786 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512": 2808 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512", "HMACSHA3-224", "HMACSHA3-256", "HMACSHA3-384", "HMACSHA3-512":
2787 wtg = &wycheproofTestGroupHmac{} 2809 wtg = &wycheproofTestGroupHmac{}
2788 case "KW": 2810 case "KW":
2789 wtg = &wycheproofTestGroupKW{} 2811 wtg = &wycheproofTestGroupKW{}
@@ -2838,7 +2860,7 @@ func runTestVectors(path string, variant testVariant) bool {
2838 return runEdDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupEdDSA)) 2860 return runEdDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupEdDSA))
2839 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512": 2861 case "HKDF-SHA-1", "HKDF-SHA-256", "HKDF-SHA-384", "HKDF-SHA-512":
2840 return runHkdfTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupHkdf)) 2862 return runHkdfTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupHkdf))
2841 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512": 2863 case "HMACSHA1", "HMACSHA224", "HMACSHA256", "HMACSHA384", "HMACSHA512", "HMACSHA3-224", "HMACSHA3-256", "HMACSHA3-384", "HMACSHA3-512":
2842 return runHmacTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupHmac)) 2864 return runHmacTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupHmac))
2843 case "KW": 2865 case "KW":
2844 return runKWTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupKW)) 2866 return runKWTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupKW))
@@ -2956,7 +2978,7 @@ func main() {
2956 2978
2957 testc = newTestCoordinator() 2979 testc = newTestCoordinator()
2958 2980
2959 skipNormal := regexp.MustCompile(`_(ecpoint|p1363|sha3|sha512_(224|256)|sect\d{3}[rk]1)_`) 2981 skipNormal := regexp.MustCompile(`_(ecpoint|p1363|sect\d{3}[rk]1)_`)
2960 2982
2961 for _, test := range tests { 2983 for _, test := range tests {
2962 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) 2984 tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern))