Skip to content

Commit

Permalink
Fix expected output argument to Transact
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Dec 18, 2024
1 parent b9ecf31 commit 3b76c32
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions util/fipstools/acvp/acvptool/subprocess/ml_dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (*mlDsa) Process(vectorSet []byte, m Transactable) (interface{}, error) {
case strings.EqualFold(vs.Mode, "sigGen"):
return processMlDsaSigGen(vs.TestGroups, m)
case strings.EqualFold(vs.Mode, "sigVer"):
return processMlDsaSigVer(vs.TestGroups, m)
return processMlDsaSigVer(vs.TestGroups, m)
}

return nil, fmt.Errorf("unknown ML-DSA mode: %v", vs.Mode)
Expand All @@ -38,8 +38,8 @@ type mlDsaKeyGenTestGroup struct {
Type string `json:"testType"`
ParameterSet string `json:"parameterSet"`
Tests []struct {
ID uint64 `json:"tcId"`
SEED hexEncodedByteString `json:"seed"`
ID uint64 `json:"tcId"`
SEED hexEncodedByteString `json:"seed"`
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func processMlDsaKeyGen(vectors json.RawMessage, m Transactable) (interface{}, e
}

for _, test := range group.Tests {
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/keyGen", 1, test.SEED)
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/keyGen", 2, test.SEED)
if err != nil {
return nil, err
}
Expand All @@ -95,27 +95,26 @@ func processMlDsaKeyGen(vectors json.RawMessage, m Transactable) (interface{}, e
}

type mlDsaSigGenTestGroup struct {
ID uint64 `json:"tgId"`
Type string `json:"testType"`
ParameterSet string `json:"parameterSet"`
Deterministic bool `json:"deterministic"`
ID uint64 `json:"tgId"`
Type string `json:"testType"`
ParameterSet string `json:"parameterSet"`
Deterministic bool `json:"deterministic"`
Tests []struct {
ID uint64 `json:"tcId"`
MESSAGE hexEncodedByteString `json:"message"`
Message hexEncodedByteString `json:"message"`
SK hexEncodedByteString `json:"sk"`
RND hexEncodedByteString `json:"rnd"`
}
}


type mlDsaSigGenTestGroupResponse struct {
ID uint64 `json:"tgId"`
Tests []mlDsaSigGenTestCaseResponse `json:"tests"`
ID uint64 `json:"tgId"`
Tests []mlDsaSigGenTestCaseResponse `json:"tests"`
}

type mlDsaSigGenTestCaseResponse struct {
ID uint64 `json:"tcId"`
SIGNATURE hexEncodedByteString `json:"signature"`
ID uint64 `json:"tcId"`
Signature hexEncodedByteString `json:"signature"`
}

func processMlDsaSigGen(vectors json.RawMessage, m Transactable) (interface{}, error) {
Expand All @@ -132,21 +131,21 @@ func processMlDsaSigGen(vectors json.RawMessage, m Transactable) (interface{}, e
return nil, fmt.Errorf("unsupported sigGen test type: %v", group.Type)
}

response := mlDsaSigGenTestGroupResponse{
ID: group.ID,
}
response := mlDsaSigGenTestGroupResponse{
ID: group.ID,
}

for _, test := range group.Tests {
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/sigGen", 3, test.SK, test.MESSAGE, test.RND)
if err != nil {
return nil, err
}
for _, test := range group.Tests {
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/sigGen", 1, test.SK, test.Message, test.RND)
if err != nil {
return nil, err
}

signature := results[0]
signature := results[0]

response.Tests = append(response.Tests, mlDsaSigGenTestCaseResponse{
ID: test.ID,
SIGNATURE: signature,
ID: test.ID,
Signature: signature,
})
}

Expand All @@ -156,28 +155,27 @@ func processMlDsaSigGen(vectors json.RawMessage, m Transactable) (interface{}, e
}

type mlDsaSigVerTestGroup struct {
ID uint64 `json:"tgId"`
Type string `json:"testType"`
ParameterSet string `json:"parameterSet"`
PK hexEncodedByteString `json:"pk"`
Tests []struct {
ID uint64 `json:"tgId"`
Type string `json:"testType"`
ParameterSet string `json:"parameterSet"`
PK hexEncodedByteString `json:"pk"`
Tests []struct {
ID uint64 `json:"tcId"`
MESSAGE hexEncodedByteString `json:"message"`
SIGNATURE hexEncodedByteString `json:"signature"`
Message hexEncodedByteString `json:"message"`
Signature hexEncodedByteString `json:"signature"`
}
}

type mlDsaSigVerTestGroupResponse struct {
ID uint64 `json:"tgId"`
Tests []mlDsaSigVerTestCaseResponse `json:"tests"`
ID uint64 `json:"tgId"`
Tests []mlDsaSigVerTestCaseResponse `json:"tests"`
}

type mlDsaSigVerTestCaseResponse struct {
ID uint64 `json:"tcId"`
TESTPASSED *bool `json:"testPassed"`
ID uint64 `json:"tcId"`
TestPassed *bool `json:"testPassed"`
}


func processMlDsaSigVer(vectors json.RawMessage, m Transactable) (interface{}, error) {
var groups []mlDsaSigVerTestGroup

Expand All @@ -192,25 +190,25 @@ func processMlDsaSigVer(vectors json.RawMessage, m Transactable) (interface{}, e
return nil, fmt.Errorf("unsupported sigVer test type: %v", group.Type)
}

response := mlDsaSigVerTestGroupResponse{
ID: group.ID,
}
response := mlDsaSigVerTestGroupResponse{
ID: group.ID,
}

for _, test := range group.Tests {
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/sigVer", 3, test.SIGNATURE, group.PK, test.MESSAGE)
if err != nil {
return nil, err
}
for _, test := range group.Tests {
results, err := m.Transact("ML-DSA/"+group.ParameterSet+"/sigVer", 1, test.Signature, group.PK, test.Message)
if err != nil {
return nil, err
}

var passed *bool
if len(results[0]) == 1 {
val := results[0][0] == 1
passed = &val
}
var passed *bool
if len(results[0]) == 1 {
val := results[0][0] == 1
passed = &val
}

response.Tests = append(response.Tests, mlDsaSigVerTestCaseResponse{
ID: test.ID,
TESTPASSED: passed,
ID: test.ID,
TestPassed: passed,
})
}

Expand Down

0 comments on commit 3b76c32

Please sign in to comment.