diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 3e21227ef6..cd95f32ff1 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.62 2018/09/22 06:06:36 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.63 2018/09/22 11:00:25 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 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> |
@@ -53,11 +53,15 @@ import ( | |||
53 | "log" | 53 | "log" |
54 | "os" | 54 | "os" |
55 | "path/filepath" | 55 | "path/filepath" |
56 | "sort" | ||
56 | "unsafe" | 57 | "unsafe" |
57 | ) | 58 | ) |
58 | 59 | ||
59 | const testVectorPath = "/usr/local/share/wycheproof/testvectors" | 60 | const testVectorPath = "/usr/local/share/wycheproof/testvectors" |
61 | |||
60 | var acceptableAudit = false | 62 | var acceptableAudit = false |
63 | var acceptableComments map[string]int | ||
64 | var acceptableFlags map[string]int | ||
61 | 65 | ||
62 | type wycheproofTestGroupAesCbcPkcs5 struct { | 66 | type wycheproofTestGroupAesCbcPkcs5 struct { |
63 | IVSize int `json:"ivSize"` | 67 | IVSize int `json:"ivSize"` |
@@ -279,6 +283,47 @@ var nids = map[string]int{ | |||
279 | "SHA-512": C.NID_sha512, | 283 | "SHA-512": C.NID_sha512, |
280 | } | 284 | } |
281 | 285 | ||
286 | func gatherAcceptableStatistics(testcase int, comment string, flags []string) { | ||
287 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", testcase, comment, flags) | ||
288 | |||
289 | if comment == "" { | ||
290 | acceptableComments["No comment"]++ | ||
291 | } else { | ||
292 | acceptableComments[comment]++ | ||
293 | } | ||
294 | |||
295 | if len(flags) == 0 { | ||
296 | acceptableFlags["NoFlag"]++ | ||
297 | } else { | ||
298 | for _, flag := range flags { | ||
299 | acceptableFlags[flag]++ | ||
300 | } | ||
301 | } | ||
302 | } | ||
303 | |||
304 | func printAcceptableStatistics() { | ||
305 | fmt.Printf("\nComment statistics:\n") | ||
306 | |||
307 | var comments []string | ||
308 | for comment := range acceptableComments { | ||
309 | comments = append(comments, comment) | ||
310 | } | ||
311 | sort.Strings(comments) | ||
312 | for _, comment := range comments { | ||
313 | fmt.Printf("%-45v %5d\n", comment, acceptableComments[comment]) | ||
314 | } | ||
315 | |||
316 | fmt.Printf("\nFlag statistics:\n") | ||
317 | var flags []string | ||
318 | for flag := range acceptableFlags { | ||
319 | flags = append(flags, flag) | ||
320 | } | ||
321 | sort.Strings(flags) | ||
322 | for _, flag := range flags { | ||
323 | fmt.Printf("%-45v %5d\n", flag, acceptableFlags[flag]) | ||
324 | } | ||
325 | } | ||
326 | |||
282 | func nidFromString(ns string) (int, error) { | 327 | func nidFromString(ns string) (int, error) { |
283 | nid, ok := nids[ns] | 328 | nid, ok := nids[ns] |
284 | if ok { | 329 | if ok { |
@@ -372,7 +417,7 @@ func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen i | |||
372 | if bytes.Equal(openedMsg, out) || wt.Result == "invalid" { | 417 | if bytes.Equal(openedMsg, out) || wt.Result == "invalid" { |
373 | success = true | 418 | success = true |
374 | if acceptableAudit && wt.Result == "acceptable" { | 419 | if acceptableAudit && wt.Result == "acceptable" { |
375 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 420 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
376 | } | 421 | } |
377 | } else { | 422 | } else { |
378 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - msg match: %t; want %v\n", wt.TCID, wt.Comment, action, wt.Flags, bytes.Equal(openedMsg, out), wt.Result) | 423 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - msg match: %t; want %v\n", wt.TCID, wt.Comment, action, wt.Flags, bytes.Equal(openedMsg, out), wt.Result) |
@@ -584,7 +629,7 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key [] | |||
584 | success = false | 629 | success = false |
585 | } | 630 | } |
586 | if acceptableAudit && bytes.Equal(tagOut, tag) && wt.Result == "acceptable" { | 631 | if acceptableAudit && bytes.Equal(tagOut, tag) && wt.Result == "acceptable" { |
587 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 632 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
588 | } | 633 | } |
589 | } | 634 | } |
590 | return success | 635 | return success |
@@ -1144,7 +1189,7 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | |||
1144 | } | 1189 | } |
1145 | if wt.Result == "acceptable" { | 1190 | if wt.Result == "acceptable" { |
1146 | if acceptableAudit { | 1191 | if acceptableAudit { |
1147 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 1192 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
1148 | } | 1193 | } |
1149 | return true | 1194 | return true |
1150 | } | 1195 | } |
@@ -1244,7 +1289,7 @@ func runECDSATest(ecKey *C.EC_KEY, nid int, h hash.Hash, wt *wycheproofTestECDSA | |||
1244 | success = false | 1289 | success = false |
1245 | } | 1290 | } |
1246 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | 1291 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { |
1247 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 1292 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
1248 | } | 1293 | } |
1249 | return success | 1294 | return success |
1250 | } | 1295 | } |
@@ -1348,7 +1393,7 @@ func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLe | |||
1348 | success := false | 1393 | success := false |
1349 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { | 1394 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { |
1350 | if acceptableAudit && wt.Result == "acceptable" { | 1395 | if acceptableAudit && wt.Result == "acceptable" { |
1351 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 1396 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
1352 | } | 1397 | } |
1353 | success = true | 1398 | success = true |
1354 | } else if ret == 0 && (wt.Result == "invalid" || wt.Result == "acceptable") { | 1399 | } else if ret == 0 && (wt.Result == "invalid" || wt.Result == "acceptable") { |
@@ -1436,7 +1481,7 @@ func runRSATest(rsa *C.RSA, nid int, h hash.Hash, wt *wycheproofTestRSA) bool { | |||
1436 | success = false | 1481 | success = false |
1437 | } | 1482 | } |
1438 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | 1483 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { |
1439 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 1484 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
1440 | } | 1485 | } |
1441 | return success | 1486 | return success |
1442 | } | 1487 | } |
@@ -1510,7 +1555,7 @@ func runX25519Test(wt *wycheproofTestX25519) bool { | |||
1510 | success = false | 1555 | success = false |
1511 | } | 1556 | } |
1512 | if acceptableAudit && result && wt.Result == "acceptable" { | 1557 | if acceptableAudit && result && wt.Result == "acceptable" { |
1513 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags) | 1558 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) |
1514 | } | 1559 | } |
1515 | return success | 1560 | return success |
1516 | } | 1561 | } |
@@ -1632,6 +1677,9 @@ func main() { | |||
1632 | 1677 | ||
1633 | flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases") | 1678 | flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases") |
1634 | flag.Parse() | 1679 | flag.Parse() |
1680 | |||
1681 | acceptableComments = make(map[string]int) | ||
1682 | acceptableFlags = make(map[string]int) | ||
1635 | 1683 | ||
1636 | tests := []struct { | 1684 | tests := []struct { |
1637 | name string | 1685 | name string |
@@ -1663,6 +1711,10 @@ func main() { | |||
1663 | } | 1711 | } |
1664 | } | 1712 | } |
1665 | 1713 | ||
1714 | if acceptableAudit { | ||
1715 | printAcceptableStatistics() | ||
1716 | } | ||
1717 | |||
1666 | if !success { | 1718 | if !success { |
1667 | os.Exit(1) | 1719 | os.Exit(1) |
1668 | } | 1720 | } |