Description
RSA public keys can be represented using ASN.1/DER RSAPublicKey
in #233. However, there is a concern that potential implementers may consider this a legacy format: w3c-ccg/did-key-spec#41 (comment). Addressing this could be an opportunity to find a more compact encoding, as there is some overhead with the RSAPublicKey
DER encoding, as it encodes a data structure format that is not really needed here, as the data structure may be understood from the context (multiformats/multicodec and the particular multicodec entry): we just need to represent two positive integers.
In Example 1 in #233 (comment), a RSA public key is represented in 270 bytes, that is 256 bytes for the 2048-bit modulus, 3 bytes for the (public) exponent, 1 byte for the (sometimes needed) leading zero in the modulus, and 10 remaining bytes for the data structure.
@expede and @b5, how would you feel about approaching a more compact representation?
I think this may be more work for some implementers, do to wide support of RSAPublicKey in ASN.1/DER; but I think @dlongley is right that new implementations might not in fact have such support.
Is anyone aware of an appropriate encoding here? As we are in the context multiformats/multicodec, I would think to reuse varint
. However some implementations of multicodec (and did:key
) might not actually have varint
implemented, as they may rely on the static encoded types. The readme lists only two implementations: https://github.com/multiformats/unsigned-varint#implementations. Perhaps a simpler format may be preferable? On the other hand, as an implementer I believe I could work with that, using the Rust implementation.
If a simpler format is preferred, unless there is some existing standard compact and canonical representation for this key type, I would propose the following: one byte for the length of the exponent, followed by the exponent, followed by the modulus.
As integers, the exponent and modulus would be encoded the same as in ASN.1 (after dropping the leading zero where appropriate) and as in JWK (before Base64Url encoding). I think it is the same in OpenSSH public key format as well.