3 ms·
> Indeed, here is Go's definition of ed25519.PublicKey […] Wouldn’t you need some sort of length restriction on that? Or are all byte sequences valid Ed25519 k
by runeks 6y ago
> Indeed, here is Go's definition of ed25519.PublicKey […]
Wouldn’t you need some sort of length restriction on that? Or are all byte sequences valid Ed25519 keys — e.g. the empty byte sequence and the byte sequence that comprises this[1] cat GIF?
https://i.pinimg.com/originals/c3/2b/fa/c32bfa16bcf864e478d3ddfe32440268.gif https://i.pinimg.com/originals/c3/2b/fa/c32bfa16bcf864e478d3...
- lawl 6y ago> Wouldn’t you need some sort of length restriction on that? https://github.com/golang/go/blob/master/src/crypto/ed25519/ed25519.go#L203 https://github.com/golang/go/blob/master/src/crypto/ed25519/... It seems it would indeed panic with an invalid size.
- madars 6y agoYup! From https://cr.yp.to/ecdh.html https://cr.yp.to/ecdh.html > How do I validate Curve25519 public keys? > Don't. The Curve25519 function was carefully designed to allow all 32-byte strings as Diffie-Hellman public keys. (minor exceptions follow)
- agwa 6y agoPublic keys are 32 bytes long, and private keys are 64 bytes long. The Ed25519 functions check to make sure the key is the correct length before using them: https://github.com/golang/go/blob/d4bfe006155ea0d9c2970e22fca5a027125c8a98/src/crypto/ed25519/ed25519.go#L204 https://github.com/golang/go/blob/d4bfe006155ea0d9c2970e22fc... The types would ideally use fixed-length arrays, but at the time the API was designed, Go didn't allow conversions between slices and array pointers, which would have made the API annoying to use: https://github.com/golang/go/issues/24376#issuecomment-372786394 https://github.com/golang/go/issues/24376#issuecomment-37278... Go is now adding support for such conversions, but the Ed25519 API can't be changed due to backwards compatibility guarantees.