-/* $OpenBSD: wycheproof.go,v 1.62 2018/09/22 06:06:36 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.63 2018/09/22 11:00:25 tb Exp $ */
/*
* Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
"log"
"os"
"path/filepath"
+ "sort"
"unsafe"
)
const testVectorPath = "/usr/local/share/wycheproof/testvectors"
+
var acceptableAudit = false
+var acceptableComments map[string]int
+var acceptableFlags map[string]int
type wycheproofTestGroupAesCbcPkcs5 struct {
IVSize int `json:"ivSize"`
"SHA-512": C.NID_sha512,
}
+func gatherAcceptableStatistics(testcase int, comment string, flags []string) {
+ fmt.Printf("AUDIT: Test case %d (%q) %v\n", testcase, comment, flags)
+
+ if comment == "" {
+ acceptableComments["No comment"]++
+ } else {
+ acceptableComments[comment]++
+ }
+
+ if len(flags) == 0 {
+ acceptableFlags["NoFlag"]++
+ } else {
+ for _, flag := range flags {
+ acceptableFlags[flag]++
+ }
+ }
+}
+
+func printAcceptableStatistics() {
+ fmt.Printf("\nComment statistics:\n")
+
+ var comments []string
+ for comment := range acceptableComments {
+ comments = append(comments, comment)
+ }
+ sort.Strings(comments)
+ for _, comment := range comments {
+ fmt.Printf("%-45v %5d\n", comment, acceptableComments[comment])
+ }
+
+ fmt.Printf("\nFlag statistics:\n")
+ var flags []string
+ for flag := range acceptableFlags {
+ flags = append(flags, flag)
+ }
+ sort.Strings(flags)
+ for _, flag := range flags {
+ fmt.Printf("%-45v %5d\n", flag, acceptableFlags[flag])
+ }
+}
+
func nidFromString(ns string) (int, error) {
nid, ok := nids[ns]
if ok {
if bytes.Equal(openedMsg, out) || wt.Result == "invalid" {
success = true
if acceptableAudit && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
} else {
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)
success = false
}
if acceptableAudit && bytes.Equal(tagOut, tag) && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
}
return success
}
if wt.Result == "acceptable" {
if acceptableAudit {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
return true
}
success = false
}
if acceptableAudit && ret == 1 && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
return success
}
success := false
if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") {
if acceptableAudit && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
success = true
} else if ret == 0 && (wt.Result == "invalid" || wt.Result == "acceptable") {
success = false
}
if acceptableAudit && ret == 1 && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
return success
}
success = false
}
if acceptableAudit && result && wt.Result == "acceptable" {
- fmt.Printf("AUDIT: Test case %d (%q) %v\n", wt.TCID, wt.Comment, wt.Flags)
+ gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags)
}
return success
}
flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases")
flag.Parse()
+
+ acceptableComments = make(map[string]int)
+ acceptableFlags = make(map[string]int)
tests := []struct {
name string
}
}
+ if acceptableAudit {
+ printAcceptableStatistics()
+ }
+
if !success {
os.Exit(1)
}