-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ED25519 ACVP Testing #1818
Merged
Merged
Add ED25519 ACVP Testing #1818
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,308 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR ISC | ||
|
||
package subprocess | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// NIST ACVP EDDSA Schema: https://pages.nist.gov/ACVP/draft-celi-acvp-eddsa.html | ||
type eddsa struct{} | ||
|
||
func (e *eddsa) Process(vectorSet []byte, m Transactable) (interface{}, error) { | ||
var vs struct { | ||
Mode string `json:"mode"` | ||
TestGroups json.RawMessage `json:"testGroups"` | ||
} | ||
|
||
if err := json.Unmarshal(vectorSet, &vs); err != nil { | ||
return nil, err | ||
} | ||
|
||
var processTestGroups func(json.RawMessage, Transactable) (interface{}, error) | ||
|
||
switch { | ||
case strings.EqualFold(vs.Mode, "keyGen"): | ||
processTestGroups = processEddsaKeyGenTestGroup | ||
case strings.EqualFold(vs.Mode, "keyVer"): | ||
processTestGroups = processEddsaKeyVerTestGroup | ||
case strings.EqualFold(vs.Mode, "sigGen"): | ||
processTestGroups = processEddsaSigGenTestGroup | ||
case strings.EqualFold(vs.Mode, "sigVer"): | ||
processTestGroups = processEddsaSigVerTestGroup | ||
default: | ||
return nil, fmt.Errorf("unsupported EDDSA mode %q", vs.Mode) | ||
} | ||
|
||
return processTestGroups(vs.TestGroups, m) | ||
} | ||
|
||
func processEddsaKeyGenTestGroup(testGroups json.RawMessage, m Transactable) (interface{}, error) { | ||
var groups []eddsaKeyGenTestGroup | ||
if err := json.Unmarshal(testGroups, &groups); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret []eddsaKeyGenTestGroupResponse | ||
|
||
for _, group := range groups { | ||
response := eddsaKeyGenTestGroupResponse{ | ||
ID: group.ID, | ||
} | ||
|
||
if group.Type != "AFT" { | ||
return nil, fmt.Errorf("unsupported test type %q", group.Type) | ||
} | ||
|
||
for _, test := range group.Tests { | ||
result, err := m.Transact("EDDSA/"+string(group.Curve)+"/keyGen", 2) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response.Tests = append(response.Tests, eddsaKeyGenTestCaseResponse{ | ||
ID: test.ID, | ||
D: result[0], | ||
Q: result[1], | ||
}) | ||
} | ||
|
||
ret = append(ret, response) | ||
} | ||
|
||
return ret, nil | ||
} | ||
|
||
func processEddsaKeyVerTestGroup(testGroups json.RawMessage, m Transactable) (interface{}, error) { | ||
var groups []eddsaKeyVerTestGroup | ||
if err := json.Unmarshal(testGroups, &groups); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret []eddsaKeyVerTestGroupResponse | ||
|
||
for _, group := range groups { | ||
if group.Type != "AFT" { | ||
return nil, fmt.Errorf("unsupported test type %q", group.Type) | ||
} | ||
|
||
response := eddsaKeyVerTestGroupResponse{ | ||
ID: group.ID, | ||
} | ||
|
||
for _, test := range group.Tests { | ||
results, err := m.Transact("EDDSA/"+string(group.Curve)+"/keyVer", 1, test.Q) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var passed *bool | ||
if len(results[0]) == 1 { | ||
val := results[0][0] == 1 | ||
passed = &val | ||
} | ||
|
||
response.Tests = append(response.Tests, eddsaKeyVerTestCaseResponse{ | ||
ID: test.ID, | ||
Passed: passed, | ||
}) | ||
} | ||
|
||
ret = append(ret, response) | ||
} | ||
|
||
return ret, nil | ||
} | ||
|
||
func processEddsaSigGenTestGroup(testGroups json.RawMessage, m Transactable) (interface{}, error) { | ||
var groups []eddsaSigGenTestGroup | ||
if err := json.Unmarshal(testGroups, &groups); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret []eddsaSigGenTestGroupResponse | ||
|
||
for _, group := range groups { | ||
if group.Type != "AFT" && group.Type != "BFT" { | ||
return nil, fmt.Errorf("unsupported test type %q", group.Type) | ||
} | ||
|
||
results, err := m.Transact("EDDSA/"+string(group.Curve)+"/keyGen", 2) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
seed := results[0] | ||
|
||
response := eddsaSigGenTestGroupResponse{ | ||
ID: group.ID, | ||
Q: results[1], | ||
} | ||
|
||
for _, test := range group.Tests { | ||
results, err := m.Transact("EDDSA/"+string(group.Curve)+"/sigGen", 1, seed, test.Message) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response.Tests = append(response.Tests, eddsaSigGenTestCaseResponse{ | ||
ID: test.ID, | ||
Signature: results[0], | ||
}) | ||
} | ||
|
||
ret = append(ret, response) | ||
} | ||
|
||
return ret, nil | ||
} | ||
|
||
func processEddsaSigVerTestGroup(testGroups json.RawMessage, m Transactable) (interface{}, error) { | ||
var groups []eddsaSigVerTestGroup | ||
if err := json.Unmarshal(testGroups, &groups); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret []eddsaSigVerTestGroupResponse | ||
|
||
for _, group := range groups { | ||
if group.Type != "AFT" { | ||
return nil, fmt.Errorf("unsupported test type %q", group.Type) | ||
} | ||
|
||
response := eddsaSigVerTestGroupResponse{ | ||
ID: group.ID, | ||
} | ||
|
||
for _, test := range group.Tests { | ||
results, err := m.Transact("EDDSA/"+string(group.Curve)+"/sigVer", 1, test.Message, test.Q, test.Signature) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var passed *bool | ||
if len(results[0]) == 1 { | ||
val := results[0][0] == 1 | ||
passed = &val | ||
} | ||
|
||
response.Tests = append(response.Tests, eddsaSigVerTestCaseResponse{ | ||
ID: test.ID, | ||
Passed: passed, | ||
}) | ||
} | ||
|
||
ret = append(ret, response) | ||
} | ||
|
||
return ret, nil | ||
} | ||
|
||
const Ed25519 EDDSACurve = "ED-25519" | ||
|
||
type EDDSACurve string | ||
|
||
func (e *EDDSACurve) UnmarshalJSON(v []byte) error { | ||
var str string | ||
|
||
if err := json.Unmarshal(v, &str); err != nil { | ||
return err | ||
} | ||
|
||
switch { | ||
case strings.EqualFold(str, "ED-25519"): | ||
*e = Ed25519 | ||
default: | ||
return fmt.Errorf("unsupported EDDSA curve: %q", str) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type eddsaKeyGenTestGroup struct { | ||
ID uint64 `json:"tgId"` | ||
Curve EDDSACurve `json:"curve"` | ||
Type string `json:"testType"` | ||
Tests []struct { | ||
ID uint64 `json:"tcId"` | ||
} | ||
} | ||
|
||
type eddsaKeyVerTestGroup struct { | ||
ID uint64 `json:"tgId"` | ||
Curve EDDSACurve `json:"curve"` | ||
Type string `json:"testType"` | ||
Tests []struct { | ||
ID uint64 `json:"tcId"` | ||
Q hexEncodedByteString `json:"q"` | ||
} | ||
} | ||
|
||
type eddsaSigGenTestGroup struct { | ||
ID uint64 `json:"tgId"` | ||
Curve EDDSACurve `json:"curve"` | ||
Prehash bool `json:"prehash"` | ||
Type string `json:"testType"` | ||
Tests []struct { | ||
ID uint64 `json:"tcId"` | ||
Message hexEncodedByteString `json:"message"` | ||
} | ||
} | ||
|
||
type eddsaSigVerTestGroup struct { | ||
ID uint64 `json:"tgId"` | ||
Curve EDDSACurve `json:"curve"` | ||
Prehash bool `json:"prehash"` | ||
Type string `json:"testType"` | ||
Tests []struct { | ||
ID uint64 `json:"tcId"` | ||
Message hexEncodedByteString `json:"message"` | ||
Q hexEncodedByteString `json:"q"` | ||
Signature hexEncodedByteString `json:"signature"` | ||
} | ||
} | ||
|
||
type eddsaKeyGenTestGroupResponse struct { | ||
ID uint64 `json:"tgId"` | ||
Tests []eddsaKeyGenTestCaseResponse `json:"tests"` | ||
} | ||
|
||
type eddsaKeyGenTestCaseResponse struct { | ||
ID uint64 `json:"tcId"` | ||
D hexEncodedByteString `json:"d"` | ||
Q hexEncodedByteString `json:"q"` | ||
} | ||
|
||
type eddsaKeyVerTestGroupResponse struct { | ||
ID uint64 `json:"tgId"` | ||
Tests []eddsaKeyVerTestCaseResponse `json:"tests"` | ||
} | ||
|
||
type eddsaKeyVerTestCaseResponse struct { | ||
ID uint64 `json:"tcId"` | ||
Passed *bool `json:"testPassed"` | ||
} | ||
|
||
type eddsaSigGenTestGroupResponse struct { | ||
ID uint64 `json:"tgId"` | ||
Q hexEncodedByteString `json:"q"` | ||
Tests []eddsaSigGenTestCaseResponse `json:"tests"` | ||
} | ||
|
||
type eddsaSigGenTestCaseResponse struct { | ||
ID uint64 `json:"tcId"` | ||
Signature hexEncodedByteString `json:"signature"` | ||
} | ||
|
||
type eddsaSigVerTestGroupResponse struct { | ||
ID uint64 `json:"tgId"` | ||
Tests []eddsaSigVerTestCaseResponse `json:"tests"` | ||
} | ||
|
||
type eddsaSigVerTestCaseResponse struct { | ||
ID uint64 `json:"tcId"` | ||
Passed *bool `json:"testPassed"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both expected responses for SigVer and KeyVer are false in this file. Should we include 2 Passed:true tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me pull the demo vectors again, I'm pretty sure there were truthy test cases but the test trim tool might have pruned them out since it's agnostic to the tests themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, but the trim vectors tool intent is to only leave one ACVP test per ACVP test group. So this is currently an expected outcome behavior that this trimming is exhaustive regardless of the perceived of the test. It would appear this level of ACVP testing in the repository is more to confirm the functionality of the tool, but may not be an exhaustive representation of the full suite of tests you would get from NIST in this format.
Long-term it would be nice to have something similar to our crypfuzz framework where we stash/keep a much larger set of ACVP vectors and use that it do additional exhaustive testing of our algorithms. Maybe a future intern project?
For now I confirmed that the vectors I validated with the NIST demo server had the variants in question that you referenced and successfully passed.