-
Notifications
You must be signed in to change notification settings - Fork 30
test: add Ed25519 conformance tests #219
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |||||||||
| "bytes" | ||||||||||
| "crypto" | ||||||||||
| "crypto/ecdsa" | ||||||||||
| "crypto/ed25519" | ||||||||||
| "crypto/elliptic" | ||||||||||
| "crypto/rsa" | ||||||||||
| _ "crypto/sha256" | ||||||||||
|
|
@@ -12,6 +13,7 @@ import ( | |||||||||
| "encoding/hex" | ||||||||||
| "encoding/json" | ||||||||||
| "errors" | ||||||||||
| "io" | ||||||||||
| "math/big" | ||||||||||
| "os" | ||||||||||
| "path/filepath" | ||||||||||
|
|
@@ -71,17 +73,20 @@ var testCases = []struct { | |||||||||
| {name: "sign1-sign-0004", deterministic: true}, | ||||||||||
| {name: "sign1-sign-0005", deterministic: true}, | ||||||||||
| {name: "sign1-sign-0006", deterministic: true}, | ||||||||||
| {name: "sign1-sign-0007", deterministic: true}, // EdDSA Ed25519 | ||||||||||
| {name: "sign1-verify-0000"}, | ||||||||||
| {name: "sign1-verify-0001"}, | ||||||||||
| {name: "sign1-verify-0002"}, | ||||||||||
| {name: "sign1-verify-0003"}, | ||||||||||
| {name: "sign1-verify-0004"}, | ||||||||||
| {name: "sign1-verify-0005"}, | ||||||||||
| {name: "sign1-verify-0006"}, | ||||||||||
| {name: "sign1-verify-0007"}, // EdDSA Ed25519 | ||||||||||
| {name: "sign1-verify-negative-0000", err: "cbor: invalid protected header: cbor: require bstr type"}, | ||||||||||
| {name: "sign1-verify-negative-0001", err: "cbor: invalid protected header: cbor: protected header: require map type"}, | ||||||||||
| {name: "sign1-verify-negative-0002", err: "cbor: invalid protected header: cbor: found duplicate map key \"1\" at map element index 1"}, | ||||||||||
| {name: "sign1-verify-negative-0003", err: "cbor: invalid unprotected header: cbor: found duplicate map key \"4\" at map element index 1"}, | ||||||||||
| {name: "sign1-verify-negative-0004"}, // EdDSA Ed25519 invalid signature | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func TestConformance(t *testing.T) { | ||||||||||
|
|
@@ -153,6 +158,7 @@ func testSign1(t *testing.T, tc *TestCase, deterministic bool) { | |||||||||
| if err != nil { | ||||||||||
| t.Fatal(err) | ||||||||||
| } | ||||||||||
| t.Logf("Test case: %s, Key type: %s", tc.Title, tc.Key["kty"]) | ||||||||||
| sig := tc.Sign1 | ||||||||||
| sigMsg := cose.NewSign1Message() | ||||||||||
| sigMsg.Payload = mustHexToBytes(sig.Payload) | ||||||||||
|
|
@@ -164,7 +170,16 @@ func testSign1(t *testing.T, tc *TestCase, deterministic bool) { | |||||||||
| if sig.External != "" { | ||||||||||
| external = mustHexToBytes(sig.External) | ||||||||||
| } | ||||||||||
| err = sigMsg.Sign(new(zeroSource), external, signer) | ||||||||||
| // Ed25519 signatures are deterministic and should use nil for rand | ||||||||||
| // Other algorithms use zeroSource for reproducible test results | ||||||||||
| var rand io.Reader = new(zeroSource) | ||||||||||
| if tc.Alg == "EdDSA" { | ||||||||||
| rand = nil | ||||||||||
| } | ||||||||||
| t.Logf("Algorithm: %s, using rand: %v", tc.Alg, rand) | ||||||||||
| t.Logf("Payload: %x", sigMsg.Payload) | ||||||||||
| t.Logf("Protected: %+v", sigMsg.Headers.Protected) | ||||||||||
|
||||||||||
| t.Logf("Protected: %+v", sigMsg.Headers.Protected) | |
| if testing.Verbose() { | |
| t.Logf("Protected: %+v", sigMsg.Headers.Protected) | |
| } |
Outdated
Copilot
AI
Oct 6, 2025
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.
The OKP key handling logic is duplicated between the getKey function and the getSigner function. Consider extracting the Ed25519 key creation logic into a separate helper function to reduce code duplication.
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.
This is a very valid comment, which needs to be incorporated!
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.
Ok sir @yogeshbdeshpande I will more review this one...
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.
Technically this could also mean Ed448.
Consider if anything here is helpful:
https://datatracker.ietf.org/doc/draft-ietf-jose-fully-specified-algorithms/13/
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.
Sure sir @OR13 , thanks for the approval
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.
Hi sir @OR13 Good point about Ed448. I've added placeholder support for it with proper error messages and comments about the key size differences (57-byte vs 32-byte seeds). The code structure now makes it easy to add Ed448 implementation later when golang.org/x/crypto/ed448 is integrated. Both curves correctly use AlgorithmEdDSA = -8 with curve differentiation in the key's "crv" field.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "uuid": "ED25519-SIGN-0001", | ||
| "title": "Sign1 - EdDSA with Ed25519 (sign)", | ||
| "description": "Sign with one signer using EdDSA with Ed25519", | ||
| "key": { | ||
| "kty": "OKP", | ||
| "crv": "Ed25519", | ||
| "x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo", | ||
| "d": "nWGxne_9WmC6hEr0kuwsxERJxWl7MmkZcDusAxyuf2A" | ||
| }, | ||
| "alg": "EdDSA", | ||
| "sign1::sign": { | ||
| "payload": "546869732069732074686520636f6e74656e742e", | ||
| "protectedHeaders": { | ||
| "cborHex": "a201270300", | ||
| "cborDiag": "{1: -8, 3: 0}" | ||
| }, | ||
| "unprotectedHeaders": { | ||
| "cborHex": "a104423131", | ||
| "cborDiag": "{4: '11'}" | ||
| }, | ||
| "tbsHex": { | ||
| "cborHex": "846a5369676e61747572653145a20127030040545468697320697320746865206f6e74656e742e", | ||
| "cborDiag": "[\"Signature1\", h'A201270300', h'', h'546869732069732074686520636F6E74656E742E']" | ||
| }, | ||
| "external": "", | ||
| "detached": false, | ||
| "expectedOutput": { | ||
| "cborHex": "d28445a201270300a10442313154546869732069732074686520636f6e74656e742e58407142fd2ff96d56db85bee905a76ba1d0b7321a95c8c4d3607c5781932b7afb8711497dfa751bf40b58b3bcc32300b1487f3db34085eef013bf08f4a44d6fef0d", | ||
| "cborDiag": "18([h'A201270300', {4: h'3131'}, h'546869732069732074686520636F6E74656E742E', h'7142FD2FF96D56DB85BEE905A76BA1D0B7321A95C8C4D3607C5781932B7AFB8711497DFA751BF40B58B3BCC32300B1487F3DB34085EEF013BF08F4A44D6FEF0D'])" | ||
| }, | ||
| "fixedOutputLength": 32 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "uuid": "ED25519-VERIFY-0001", | ||
| "title": "Sign1 - EdDSA with Ed25519 (verify)", | ||
| "description": "Verify signature with one signer using EdDSA with Ed25519", | ||
| "key": { | ||
| "kty": "OKP", | ||
| "crv": "Ed25519", | ||
| "x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" | ||
| }, | ||
| "alg": "EdDSA", | ||
| "sign1::verify": { | ||
| "taggedCOSESign1": { | ||
| "cborHex": "d28445a201270300a10442313154546869732069732074686520636f6e74656e742e58407142fd2ff96d56db85bee905a76ba1d0b7321a95c8c4d3607c5781932b7afb8711497dfa751bf40b58b3bcc32300b1487f3db34085eef013bf08f4a44d6fef0d", | ||
| "cborDiag": "18([h'A201270300', {4: h'3131'}, h'546869732069732074686520636F6E74656E742E', h'7142FD2FF96D56DB85BEE905A76BA1D0B7321A95C8C4D3607C5781932B7AFB8711497DFA751BF40B58B3BCC32300B1487F3DB34085EEF013BF08F4A44D6FEF0D'])" | ||
| }, | ||
| "external": "", | ||
| "shouldVerify": true | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "uuid": "ED25519-VERIFY-NEGATIVE-0001", | ||
| "title": "Sign1 - EdDSA with Ed25519 (verify - invalid signature)", | ||
| "description": "Verification should fail with invalid Ed25519 signature", | ||
| "key": { | ||
| "kty": "OKP", | ||
| "crv": "Ed25519", | ||
| "x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" | ||
| }, | ||
| "alg": "EdDSA", | ||
| "sign1::verify": { | ||
| "taggedCOSESign1": { | ||
| "cborHex": "d28445a201270300a104423131545468697320697320746865206f6e74656e742e5840ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
| "cborDiag": "18([h'A201270300', {4: h'3131'}, h'546869732069732074686520636F6E74656E742E', h'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'])" | ||
| }, | ||
| "external": "", | ||
| "shouldVerify": false | ||
| } | ||
| } |
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.
The debug logging statements should be removed or replaced with conditional debug logging. These logs will clutter test output in normal runs and are typically only needed during development.
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.
This one is great, changes will be made fr...