Skip to content
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 Implementation Guidance to Recommend Compressed Point Encoding #117

Merged
merged 8 commits into from
Feb 7, 2024

Conversation

frankhinek
Copy link
Contributor

@frankhinek frankhinek commented Feb 5, 2024

Summary

This PR will:

  • Add implementation guidance that recommends using compressed point encoding to nearly halve the payload space occupied by each EC public key (e.g., secp256k1, secp256r1).
  • Updates test vector to demonstrate a DID Document containing a secp256k1 key optimally encoded as a DNS packet.
  • Fix two minor typos in § Services and the accompanying example.

Context

Elliptic-curve points (e.g., secp256k1, secp256r1) can be encoded as either the x-coordinate and y-coordinate or the x-coordinate and a sign bit for the y-coordinate. The latter encoding, called compressed point encoding, can be used to shrink the size of the DNS packet encoded representation of a DID DHT document by nearly half (65 -> 33 bytes). It also serves to align the payload size of Ed25519 (32 bytes) and secp256k1/secp256r1 (33 bytes) keys.

It's also worth noting that the public keys are unpadded Base64URL-encoded such that the each uncompressed secp256k1/secp256r1 key actually consumes 87 bytes in the DNS packet. Using compressed point encoding decreases the size to 44 bytes.

The added note includes guidance that the DID Document representation must include the x- and y-coordinate pair for all EC JWKs. As noted in RFC 8812:

...a compressed point encoding representation is not defined for JWK elliptic curve points, the uncompressed point encoding defined there MUST be used.

Prior Art

Compressed point encoding has also been used in:

Additional References

spec/spec.md Outdated Show resolved Hide resolved
spec/spec.md Outdated Show resolved Hide resolved
- DID Document representations ****SHOULD**** always use fully qualified identifiers (e.g. `did:dht:uodqi99wuzxsz6yx445zxkp8ddwj9q54ocbcg8yifsqru45x63kj#0` as opposed to `0` or `#0`)
- [[ref:DID Document]] representations of elliptic curve (EC) keys ****MUST**** include the x- and y-coordinate pair.
To conserve space in the DNS packet representation, compressed point encoding ****MUST**** be used to transmit the
x-coordinate and a sign bit for the y-coordinate. This practice reduces each public key's size from 65 to 33 bytes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this true for all key types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@decentralgabe it is true for all EC key types. In terms of current key types in the DID DHT Registry, that includes secp256k1 and secp256r1.

It is not relevant for OKP keys such as Ed25519 since compressed encoding (only the 32-byte x-coordinate) is always used.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two small ones feel free to merge

@frankhinek frankhinek merged commit e4bf577 into main Feb 7, 2024
3 checks passed
@frankhinek frankhinek deleted the spec-compressed-keys branch February 7, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants