2017-04-28 17:00:03 +01:00
|
|
|
// run_cavp.go processes CAVP input files and generates suitable response
|
|
|
|
// files, optionally comparing the results against the provided FAX files.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2017-05-04 00:34:42 +01:00
|
|
|
"runtime"
|
2017-04-28 17:00:03 +01:00
|
|
|
"strings"
|
2017-05-04 00:34:42 +01:00
|
|
|
"sync"
|
|
|
|
"time"
|
2017-04-28 17:00:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-03 22:12:39 +01:00
|
|
|
oraclePath = flag.String("oracle-bin", "", "Path to the oracle binary")
|
|
|
|
suiteDir = flag.String("suite-dir", "", "Base directory containing the CAVP test suite")
|
2017-05-17 18:08:26 +01:00
|
|
|
noFAX = flag.Bool("no-fax", false, "Skip comparing against FAX files")
|
2018-01-05 17:28:00 +00:00
|
|
|
niap = flag.Bool("niap", false, "Perform NIAP tests rather than FIPS tests")
|
2017-04-28 17:00:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// test describes a single request file.
|
|
|
|
type test struct {
|
|
|
|
// inFile is the base of the filename without an extension, i.e.
|
|
|
|
// “ECBMCT128”.
|
|
|
|
inFile string
|
|
|
|
// args are the arguments (not including the input filename) to the
|
|
|
|
// oracle binary.
|
2017-04-28 22:08:45 +01:00
|
|
|
args []string
|
2017-04-28 17:00:03 +01:00
|
|
|
// noFAX, if true, indicates that the output cannot be compared against
|
|
|
|
// the FAX file. (E.g. because the primitive is non-deterministic.)
|
|
|
|
noFAX bool
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:50:35 +00:00
|
|
|
// nextLineState can be used by FAX next-line function to store state.
|
|
|
|
type nextLineState struct {
|
2018-01-05 17:28:00 +00:00
|
|
|
// State used by the KAS test.
|
|
|
|
nextIsIUTHash bool
|
2018-01-05 17:50:35 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 17:00:03 +01:00
|
|
|
// testSuite describes a series of tests that are handled by a single oracle
|
|
|
|
// binary.
|
|
|
|
type testSuite struct {
|
|
|
|
// directory is the name of the directory in the CAVP input, i.e. “AES”.
|
|
|
|
directory string
|
2017-05-03 22:12:39 +01:00
|
|
|
// suite names the test suite to pass as the first command-line argument.
|
|
|
|
suite string
|
2018-01-05 17:50:35 +00:00
|
|
|
// nextLineFunc, if not nil, is the function used to read the next line
|
|
|
|
// from the FAX file. This can be used to skip lines and/or mutate them
|
|
|
|
// as needed. The second argument can be used by the scanner to store
|
|
|
|
// state, if needed. If isWildcard is true on return then line is not
|
|
|
|
// meaningful and any line from the response file should be accepted.
|
|
|
|
nextLineFunc func(*bufio.Scanner, *nextLineState) (line string, isWildcard, ok bool)
|
|
|
|
tests []test
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 22:21:58 +01:00
|
|
|
func (t *testSuite) getDirectory() string {
|
|
|
|
return filepath.Join(*suiteDir, t.directory)
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:00:03 +01:00
|
|
|
var aesGCMTests = testSuite{
|
|
|
|
"AES_GCM",
|
2017-05-03 22:12:39 +01:00
|
|
|
"aes_gcm",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 17:00:03 +01:00
|
|
|
[]test{
|
|
|
|
{"gcmDecrypt128", []string{"dec", "aes-128-gcm"}, false},
|
|
|
|
{"gcmDecrypt256", []string{"dec", "aes-256-gcm"}, false},
|
2017-05-30 19:43:25 +01:00
|
|
|
{"gcmEncryptExtIV128", []string{"enc", "aes-128-gcm"}, false},
|
|
|
|
{"gcmEncryptExtIV256", []string{"enc", "aes-256-gcm"}, false},
|
2017-04-28 17:00:03 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var aesTests = testSuite{
|
|
|
|
"AES",
|
2017-05-03 22:12:39 +01:00
|
|
|
"aes",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 17:00:03 +01:00
|
|
|
[]test{
|
2017-04-28 22:21:58 +01:00
|
|
|
{"CBCGFSbox128", []string{"kat", "aes-128-cbc"}, false},
|
|
|
|
{"CBCGFSbox192", []string{"kat", "aes-192-cbc"}, false},
|
|
|
|
{"CBCGFSbox256", []string{"kat", "aes-256-cbc"}, false},
|
|
|
|
{"CBCKeySbox128", []string{"kat", "aes-128-cbc"}, false},
|
|
|
|
{"CBCKeySbox192", []string{"kat", "aes-192-cbc"}, false},
|
|
|
|
{"CBCKeySbox256", []string{"kat", "aes-256-cbc"}, false},
|
|
|
|
{"CBCMMT128", []string{"kat", "aes-128-cbc"}, false},
|
|
|
|
{"CBCMMT192", []string{"kat", "aes-192-cbc"}, false},
|
|
|
|
{"CBCMMT256", []string{"kat", "aes-256-cbc"}, false},
|
|
|
|
{"CBCVarKey128", []string{"kat", "aes-128-cbc"}, false},
|
|
|
|
{"CBCVarKey192", []string{"kat", "aes-192-cbc"}, false},
|
|
|
|
{"CBCVarKey256", []string{"kat", "aes-256-cbc"}, false},
|
|
|
|
{"CBCVarTxt128", []string{"kat", "aes-128-cbc"}, false},
|
|
|
|
{"CBCVarTxt192", []string{"kat", "aes-192-cbc"}, false},
|
|
|
|
{"CBCVarTxt256", []string{"kat", "aes-256-cbc"}, false},
|
|
|
|
{"ECBGFSbox128", []string{"kat", "aes-128-ecb"}, false},
|
|
|
|
{"ECBGFSbox192", []string{"kat", "aes-192-ecb"}, false},
|
|
|
|
{"ECBGFSbox256", []string{"kat", "aes-256-ecb"}, false},
|
|
|
|
{"ECBKeySbox128", []string{"kat", "aes-128-ecb"}, false},
|
|
|
|
{"ECBKeySbox192", []string{"kat", "aes-192-ecb"}, false},
|
|
|
|
{"ECBKeySbox256", []string{"kat", "aes-256-ecb"}, false},
|
|
|
|
{"ECBMMT128", []string{"kat", "aes-128-ecb"}, false},
|
|
|
|
{"ECBMMT192", []string{"kat", "aes-192-ecb"}, false},
|
|
|
|
{"ECBMMT256", []string{"kat", "aes-256-ecb"}, false},
|
|
|
|
{"ECBVarKey128", []string{"kat", "aes-128-ecb"}, false},
|
|
|
|
{"ECBVarKey192", []string{"kat", "aes-192-ecb"}, false},
|
|
|
|
{"ECBVarKey256", []string{"kat", "aes-256-ecb"}, false},
|
|
|
|
{"ECBVarTxt128", []string{"kat", "aes-128-ecb"}, false},
|
|
|
|
{"ECBVarTxt192", []string{"kat", "aes-192-ecb"}, false},
|
|
|
|
{"ECBVarTxt256", []string{"kat", "aes-256-ecb"}, false},
|
|
|
|
// AES Monte-Carlo tests
|
|
|
|
{"ECBMCT128", []string{"mct", "aes-128-ecb"}, false},
|
|
|
|
{"ECBMCT192", []string{"mct", "aes-192-ecb"}, false},
|
|
|
|
{"ECBMCT256", []string{"mct", "aes-256-ecb"}, false},
|
|
|
|
{"CBCMCT128", []string{"mct", "aes-128-cbc"}, false},
|
|
|
|
{"CBCMCT192", []string{"mct", "aes-192-cbc"}, false},
|
|
|
|
{"CBCMCT256", []string{"mct", "aes-256-cbc"}, false},
|
2017-04-28 17:00:03 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-01 19:56:22 +01:00
|
|
|
var ecdsa2KeyPairTests = testSuite{
|
|
|
|
"ECDSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"ecdsa2_keypair",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-05-01 19:56:22 +01:00
|
|
|
[]test{{"KeyPair", nil, true}},
|
|
|
|
}
|
|
|
|
|
2017-04-28 22:08:45 +01:00
|
|
|
var ecdsa2PKVTests = testSuite{
|
|
|
|
"ECDSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"ecdsa2_pkv",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 22:08:45 +01:00
|
|
|
[]test{{"PKV", nil, false}},
|
|
|
|
}
|
|
|
|
|
2017-04-30 19:37:16 +01:00
|
|
|
var ecdsa2SigGenTests = testSuite{
|
|
|
|
"ECDSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"ecdsa2_siggen",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-30 19:37:16 +01:00
|
|
|
[]test{
|
|
|
|
{"SigGen", []string{"SigGen"}, true},
|
|
|
|
{"SigGenComponent", []string{"SigGenComponent"}, true},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-28 22:41:28 +01:00
|
|
|
var ecdsa2SigVerTests = testSuite{
|
|
|
|
"ECDSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"ecdsa2_sigver",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 22:41:28 +01:00
|
|
|
[]test{{"SigVer", nil, false}},
|
|
|
|
}
|
|
|
|
|
2017-05-03 16:23:27 +01:00
|
|
|
var rsa2KeyGenTests = testSuite{
|
|
|
|
"RSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"rsa2_keygen",
|
2017-05-03 16:23:27 +01:00
|
|
|
nil,
|
|
|
|
[]test{
|
|
|
|
{"KeyGen_RandomProbablyPrime3_3", nil, true},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-02 16:32:13 +01:00
|
|
|
var rsa2SigGenTests = testSuite{
|
|
|
|
"RSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"rsa2_siggen",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-05-02 16:32:13 +01:00
|
|
|
[]test{
|
|
|
|
{"SigGen15_186-3", []string{"pkcs15"}, true},
|
2017-05-02 20:02:01 +01:00
|
|
|
{"SigGenPSS_186-3", []string{"pss"}, true},
|
2017-05-02 16:32:13 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var rsa2SigVerTests = testSuite{
|
|
|
|
"RSA2",
|
2017-05-03 22:12:39 +01:00
|
|
|
"rsa2_sigver",
|
2018-01-05 17:50:35 +00:00
|
|
|
func(s *bufio.Scanner, state *nextLineState) (string, bool, bool) {
|
2017-05-02 20:34:47 +01:00
|
|
|
for {
|
|
|
|
if !s.Scan() {
|
2018-01-05 17:50:35 +00:00
|
|
|
return "", false, false
|
2017-05-02 20:34:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
line := s.Text()
|
|
|
|
if strings.HasPrefix(line, "p = ") || strings.HasPrefix(line, "d = ") || strings.HasPrefix(line, "SaltVal = ") || strings.HasPrefix(line, "EM with ") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(line, "q = ") {
|
|
|
|
// Skip the "q = " line and an additional blank line.
|
2018-01-05 17:50:35 +00:00
|
|
|
if !s.Scan() ||
|
|
|
|
len(strings.TrimSpace(s.Text())) > 0 {
|
|
|
|
return "", false, false
|
2017-05-02 20:34:47 +01:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2018-01-05 17:50:35 +00:00
|
|
|
return line, false, true
|
2017-05-02 20:34:47 +01:00
|
|
|
}
|
|
|
|
},
|
2017-05-02 16:32:13 +01:00
|
|
|
[]test{
|
2017-05-02 20:34:47 +01:00
|
|
|
{"SigVer15_186-3", []string{"pkcs15"}, false},
|
|
|
|
{"SigVerPSS_186-3", []string{"pss"}, false},
|
2017-05-02 16:32:13 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-01 22:02:01 +01:00
|
|
|
var hmacTests = testSuite{
|
|
|
|
"HMAC",
|
2017-05-03 22:12:39 +01:00
|
|
|
"hmac",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-05-01 22:02:01 +01:00
|
|
|
[]test{{"HMAC", nil, false}},
|
|
|
|
}
|
|
|
|
|
2017-04-28 21:17:54 +01:00
|
|
|
var shaTests = testSuite{
|
|
|
|
"SHA",
|
2017-05-03 22:12:39 +01:00
|
|
|
"sha",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 21:17:54 +01:00
|
|
|
[]test{
|
|
|
|
{"SHA1LongMsg", []string{"SHA1"}, false},
|
|
|
|
{"SHA1ShortMsg", []string{"SHA1"}, false},
|
|
|
|
{"SHA224LongMsg", []string{"SHA224"}, false},
|
|
|
|
{"SHA224ShortMsg", []string{"SHA224"}, false},
|
|
|
|
{"SHA256LongMsg", []string{"SHA256"}, false},
|
|
|
|
{"SHA256ShortMsg", []string{"SHA256"}, false},
|
|
|
|
{"SHA384LongMsg", []string{"SHA384"}, false},
|
|
|
|
{"SHA384ShortMsg", []string{"SHA384"}, false},
|
|
|
|
{"SHA512LongMsg", []string{"SHA512"}, false},
|
|
|
|
{"SHA512ShortMsg", []string{"SHA512"}, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var shaMonteTests = testSuite{
|
|
|
|
"SHA",
|
2017-05-03 22:12:39 +01:00
|
|
|
"sha_monte",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-04-28 21:17:54 +01:00
|
|
|
[]test{
|
|
|
|
{"SHA1Monte", []string{"SHA1"}, false},
|
|
|
|
{"SHA224Monte", []string{"SHA224"}, false},
|
|
|
|
{"SHA256Monte", []string{"SHA256"}, false},
|
|
|
|
{"SHA384Monte", []string{"SHA384"}, false},
|
|
|
|
{"SHA512Monte", []string{"SHA512"}, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:54:03 +01:00
|
|
|
var ctrDRBGTests = testSuite{
|
|
|
|
"DRBG800-90A",
|
2017-05-03 22:12:39 +01:00
|
|
|
"ctr_drbg",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-05-01 18:54:03 +01:00
|
|
|
[]test{{"CTR_DRBG", nil, false}},
|
|
|
|
}
|
|
|
|
|
2017-05-01 19:56:43 +01:00
|
|
|
var tdesTests = testSuite{
|
|
|
|
"TDES",
|
2017-05-03 22:12:39 +01:00
|
|
|
"tdes",
|
2017-05-02 20:34:47 +01:00
|
|
|
nil,
|
2017-05-01 19:56:43 +01:00
|
|
|
[]test{
|
2017-05-01 23:31:43 +01:00
|
|
|
{"TCBCMMT2", []string{"kat", "des-ede-cbc"}, false},
|
|
|
|
{"TCBCMMT3", []string{"kat", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCMonte2", []string{"mct", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCMonte3", []string{"mct", "des-ede3-cbc"}, false},
|
2017-05-01 19:56:43 +01:00
|
|
|
{"TCBCinvperm", []string{"kat", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCpermop", []string{"kat", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCsubtab", []string{"kat", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCvarkey", []string{"kat", "des-ede3-cbc"}, false},
|
|
|
|
{"TCBCvartext", []string{"kat", "des-ede3-cbc"}, false},
|
2017-05-01 23:31:43 +01:00
|
|
|
{"TECBMMT2", []string{"kat", "des-ede"}, false},
|
|
|
|
{"TECBMMT3", []string{"kat", "des-ede3"}, false},
|
|
|
|
{"TECBMonte2", []string{"mct", "des-ede3"}, false},
|
|
|
|
{"TECBMonte3", []string{"mct", "des-ede3"}, false},
|
2017-05-01 19:56:43 +01:00
|
|
|
{"TECBinvperm", []string{"kat", "des-ede3"}, false},
|
|
|
|
{"TECBpermop", []string{"kat", "des-ede3"}, false},
|
|
|
|
{"TECBsubtab", []string{"kat", "des-ede3"}, false},
|
|
|
|
{"TECBvarkey", []string{"kat", "des-ede3"}, false},
|
|
|
|
{"TECBvartext", []string{"kat", "des-ede3"}, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-03 19:17:50 +01:00
|
|
|
var keyWrapTests = testSuite{
|
|
|
|
"KeyWrap38F",
|
2017-05-03 22:12:39 +01:00
|
|
|
"keywrap",
|
2017-05-03 19:17:50 +01:00
|
|
|
nil,
|
|
|
|
[]test{
|
|
|
|
{"KW_AD_128", []string{"dec", "128"}, false},
|
|
|
|
{"KW_AD_256", []string{"dec", "256"}, false},
|
|
|
|
{"KW_AE_128", []string{"enc", "128"}, false},
|
|
|
|
{"KW_AE_256", []string{"enc", "256"}, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:28:00 +00:00
|
|
|
var kasTests = testSuite{
|
|
|
|
"KAS",
|
|
|
|
"kas",
|
|
|
|
func(s *bufio.Scanner, state *nextLineState) (line string, isWildcard, ok bool) {
|
|
|
|
for {
|
|
|
|
// If the response file will include the IUT hash next,
|
|
|
|
// return a wildcard signal because this cannot be
|
|
|
|
// matched against the FAX file.
|
|
|
|
if state.nextIsIUTHash {
|
|
|
|
state.nextIsIUTHash = false
|
|
|
|
return "", true, true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !s.Scan() {
|
|
|
|
return "", false, false
|
|
|
|
}
|
|
|
|
|
|
|
|
line := s.Text()
|
|
|
|
if strings.HasPrefix(line, "deCAVS = ") || strings.HasPrefix(line, "Z = ") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(line, "CAVSHashZZ = ") {
|
|
|
|
state.nextIsIUTHash = true
|
|
|
|
}
|
|
|
|
return line, false, true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[]test{
|
|
|
|
{"KASFunctionTest_ECCEphemeralUnified_NOKC_ZZOnly_init", []string{"function"}, true},
|
|
|
|
{"KASFunctionTest_ECCEphemeralUnified_NOKC_ZZOnly_resp", []string{"function"}, true},
|
|
|
|
{"KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_init", []string{"validity"}, false},
|
|
|
|
{"KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_resp", []string{"validity"}, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-01-05 21:59:09 +00:00
|
|
|
var tlsKDFTests = testSuite{
|
|
|
|
"KDF135",
|
|
|
|
"tlskdf",
|
|
|
|
nil,
|
|
|
|
[]test{
|
|
|
|
{"tls", nil, false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:28:00 +00:00
|
|
|
var fipsTestSuites = []*testSuite{
|
2017-04-28 17:00:03 +01:00
|
|
|
&aesGCMTests,
|
|
|
|
&aesTests,
|
2017-05-01 18:54:03 +01:00
|
|
|
&ctrDRBGTests,
|
2017-05-01 19:56:22 +01:00
|
|
|
&ecdsa2KeyPairTests,
|
2017-04-28 22:08:45 +01:00
|
|
|
&ecdsa2PKVTests,
|
2017-04-30 19:37:16 +01:00
|
|
|
&ecdsa2SigGenTests,
|
2017-04-28 22:41:28 +01:00
|
|
|
&ecdsa2SigVerTests,
|
2017-05-03 19:17:50 +01:00
|
|
|
&hmacTests,
|
|
|
|
&keyWrapTests,
|
2017-05-03 16:23:27 +01:00
|
|
|
&rsa2KeyGenTests,
|
2017-05-02 16:32:13 +01:00
|
|
|
&rsa2SigGenTests,
|
|
|
|
&rsa2SigVerTests,
|
2017-04-28 21:17:54 +01:00
|
|
|
&shaTests,
|
|
|
|
&shaMonteTests,
|
2017-05-01 19:56:43 +01:00
|
|
|
&tdesTests,
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 17:28:00 +00:00
|
|
|
var niapTestSuites = []*testSuite{
|
|
|
|
&kasTests,
|
2018-01-05 21:59:09 +00:00
|
|
|
&tlsKDFTests,
|
2018-01-05 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 00:34:42 +01:00
|
|
|
// testInstance represents a specific test in a testSuite.
|
|
|
|
type testInstance struct {
|
|
|
|
suite *testSuite
|
|
|
|
testIndex int
|
|
|
|
}
|
|
|
|
|
|
|
|
func worker(wg *sync.WaitGroup, work <-chan testInstance) {
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
for ti := range work {
|
|
|
|
test := ti.suite.tests[ti.testIndex]
|
|
|
|
|
|
|
|
if err := doTest(ti.suite, test); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:08:26 +01:00
|
|
|
if !*noFAX && !test.noFAX {
|
2017-05-04 00:34:42 +01:00
|
|
|
if err := compareFAX(ti.suite, test); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
|
|
os.Exit(3)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:00:03 +01:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2017-05-03 22:12:39 +01:00
|
|
|
if len(*oraclePath) == 0 {
|
|
|
|
fmt.Fprintf(os.Stderr, "Must give -oracle-bin\n")
|
2017-04-28 17:00:03 +01:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2017-05-04 00:34:42 +01:00
|
|
|
work := make(chan testInstance)
|
|
|
|
var wg sync.WaitGroup
|
2017-04-28 17:00:03 +01:00
|
|
|
|
2017-05-04 00:34:42 +01:00
|
|
|
for i := 0; i < runtime.NumCPU(); i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go worker(&wg, work)
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:28:00 +00:00
|
|
|
testSuites := fipsTestSuites
|
|
|
|
if *niap {
|
|
|
|
testSuites = niapTestSuites
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, suite := range testSuites {
|
2017-05-04 00:34:42 +01:00
|
|
|
for i := range suite.tests {
|
|
|
|
work <- testInstance{suite, i}
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-04 00:34:42 +01:00
|
|
|
|
|
|
|
close(work)
|
|
|
|
wg.Wait()
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func doTest(suite *testSuite, test test) error {
|
2017-05-03 22:12:39 +01:00
|
|
|
args := []string{suite.suite}
|
2017-04-28 17:00:03 +01:00
|
|
|
args = append(args, test.args...)
|
2017-04-28 22:21:58 +01:00
|
|
|
args = append(args, filepath.Join(suite.getDirectory(), "req", test.inFile+".req"))
|
2017-04-28 17:00:03 +01:00
|
|
|
|
2017-06-08 01:34:56 +01:00
|
|
|
respDir := filepath.Join(suite.getDirectory(), "resp")
|
|
|
|
if err := os.Mkdir(respDir, 0755); err != nil && !os.IsExist(err) {
|
|
|
|
return fmt.Errorf("cannot create resp directory: %s", err)
|
|
|
|
}
|
|
|
|
outPath := filepath.Join(respDir, test.inFile+".rsp")
|
2017-04-28 17:00:03 +01:00
|
|
|
outFile, err := os.OpenFile(outPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
|
|
|
if err != nil {
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("cannot open output file for %q %q: %s", suite.getDirectory(), test.inFile, err)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
defer outFile.Close()
|
|
|
|
|
2017-05-03 22:12:39 +01:00
|
|
|
cmd := exec.Command(*oraclePath, args...)
|
2017-04-28 17:00:03 +01:00
|
|
|
cmd.Stdout = outFile
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
2017-05-03 22:12:39 +01:00
|
|
|
cmdLine := strings.Join(append([]string{*oraclePath}, args...), " ")
|
2017-05-04 00:34:42 +01:00
|
|
|
startTime := time.Now()
|
2017-04-28 17:00:03 +01:00
|
|
|
if err := cmd.Run(); err != nil {
|
2017-05-03 22:12:39 +01:00
|
|
|
return fmt.Errorf("cannot run command for %q %q (%s): %s", suite.getDirectory(), test.inFile, cmdLine, err)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 00:34:42 +01:00
|
|
|
fmt.Printf("%s (%ds)\n", cmdLine, int(time.Since(startTime).Seconds()))
|
|
|
|
|
2017-04-28 17:00:03 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-04-28 22:08:45 +01:00
|
|
|
func canonicalizeLine(in string) string {
|
|
|
|
if strings.HasPrefix(in, "Result = P (") {
|
|
|
|
return "Result = P"
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(in, "Result = F (") {
|
|
|
|
return "Result = F"
|
|
|
|
}
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:00:03 +01:00
|
|
|
func compareFAX(suite *testSuite, test test) error {
|
2018-01-05 17:50:35 +00:00
|
|
|
nextLineFunc := suite.nextLineFunc
|
|
|
|
if nextLineFunc == nil {
|
|
|
|
nextLineFunc = func(s *bufio.Scanner, state *nextLineState) (string, bool, bool) {
|
|
|
|
if !s.Scan() {
|
|
|
|
return "", false, false
|
|
|
|
}
|
|
|
|
return s.Text(), false, true
|
|
|
|
}
|
2017-05-02 20:34:47 +01:00
|
|
|
}
|
|
|
|
|
2017-05-03 21:35:47 +01:00
|
|
|
respPath := filepath.Join(suite.getDirectory(), "resp", test.inFile+".rsp")
|
2017-04-28 17:00:03 +01:00
|
|
|
respFile, err := os.Open(respPath)
|
|
|
|
if err != nil {
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("cannot read output of %q %q: %s", suite.getDirectory(), test.inFile, err)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
defer respFile.Close()
|
|
|
|
|
2017-04-28 22:21:58 +01:00
|
|
|
faxPath := filepath.Join(suite.getDirectory(), "fax", test.inFile+".fax")
|
2017-04-28 17:00:03 +01:00
|
|
|
faxFile, err := os.Open(faxPath)
|
|
|
|
if err != nil {
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("cannot open fax file for %q %q: %s", suite.getDirectory(), test.inFile, err)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
defer faxFile.Close()
|
|
|
|
|
|
|
|
respScanner := bufio.NewScanner(respFile)
|
|
|
|
faxScanner := bufio.NewScanner(faxFile)
|
2018-01-05 17:50:35 +00:00
|
|
|
var nextLineState nextLineState
|
2017-04-28 17:00:03 +01:00
|
|
|
|
|
|
|
lineNo := 0
|
|
|
|
inHeader := true
|
|
|
|
|
|
|
|
for respScanner.Scan() {
|
|
|
|
lineNo++
|
|
|
|
respLine := respScanner.Text()
|
|
|
|
var faxLine string
|
2018-01-05 17:50:35 +00:00
|
|
|
var isWildcard, ok bool
|
2017-04-28 17:00:03 +01:00
|
|
|
|
|
|
|
if inHeader && (len(respLine) == 0 || respLine[0] == '#') {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
haveFaxLine := false
|
|
|
|
|
|
|
|
if inHeader {
|
2018-01-05 17:50:35 +00:00
|
|
|
for {
|
|
|
|
if faxLine, isWildcard, ok = nextLineFunc(faxScanner, &nextLineState); !ok {
|
|
|
|
break
|
|
|
|
}
|
2017-04-28 17:00:03 +01:00
|
|
|
if len(faxLine) != 0 && faxLine[0] != '#' {
|
|
|
|
haveFaxLine = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inHeader = false
|
|
|
|
} else {
|
2018-01-05 17:50:35 +00:00
|
|
|
faxLine, isWildcard, haveFaxLine = nextLineFunc(faxScanner, &nextLineState)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !haveFaxLine {
|
2017-05-01 22:02:01 +01:00
|
|
|
// Ignore blank lines at the end of the generated file.
|
|
|
|
if len(respLine) == 0 {
|
|
|
|
break
|
|
|
|
}
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("resp file is longer than fax for %q %q", suite.getDirectory(), test.inFile)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(faxLine, " (Reason: ") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-01-05 17:50:35 +00:00
|
|
|
if isWildcard || canonicalizeLine(faxLine) == canonicalizeLine(respLine) {
|
2017-04-28 17:00:03 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("resp and fax differ at line %d for %q %q: %q vs %q", lineNo, suite.getDirectory(), test.inFile, respLine, faxLine)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 17:50:35 +00:00
|
|
|
if _, _, ok := nextLineFunc(faxScanner, &nextLineState); ok {
|
2017-04-28 22:21:58 +01:00
|
|
|
return fmt.Errorf("fax file is longer than resp for %q %q", suite.getDirectory(), test.inFile)
|
2017-04-28 17:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|