You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to RFD 5656, an ecdsa_signature_blob is a pair of mpint values (r, s).
The encoding for mpint is specified in RFC 4251. Here's a notable requirement:
Unnecessary leading bytes with the value 0 or 255 MUST NOT be included.
This means that it's possible to see "short" mpint values, e.g. this is a valid ecdsa_signature_blob for the p256 curve (which normally has 32-byte coordinates):
ssh_key::Signature::decode does not currently handle short mpint values, returning encoding::Error::Length.
I haven't managed to generate such signatures when using ssh_key::PrivateKey::sign (not sure why!), but they can be generated using ssh-agent, e.g. when using a Yubikey to sign things.
I have an example program at mkeeter/ssh-agent-test which repeatedly signs random blobs using ssh-agent. It fails about 0.7% percent of the time, which is almost exactly the probability that at least one of the mpint values has a leading 0 byte (1 - (255/256)**2 = 0.0077).
Looking through the code, there are two places where things go wrong:
ecdsa_sig_size checks that the mpint be exactly the curve length; it should also accept shorter values
p256_signature_from_openssh_bytes (and equivalent) calls p256::FieldBytes::try_from(..) on Mpint::positive_bytes, which fails if the Mpint is short; it should instead pad with leading zeros
The text was updated successfully, but these errors were encountered:
Leading zeros must be stripped from mpint values (per RFC 4251), meaning it's
possible to see "short" `mpint` values when using them to construct signatures.
These values must be padded with leading zeros before being used in
`pXYZ::ecdsa::Signature`, which expect exact-size arrays.
See #290 for details.
According to RFD 5656, an
ecdsa_signature_blob
is a pair ofmpint
values(r, s)
.The encoding for
mpint
is specified in RFC 4251. Here's a notable requirement:This means that it's possible to see "short"
mpint
values, e.g. this is a validecdsa_signature_blob
for thep256
curve (which normally has 32-byte coordinates):ssh_key::Signature::decode
does not currently handle shortmpint
values, returningencoding::Error::Length
.I haven't managed to generate such signatures when using
ssh_key::PrivateKey::sign
(not sure why!), but they can be generated usingssh-agent
, e.g. when using a Yubikey to sign things.I have an example program at
mkeeter/ssh-agent-test
which repeatedly signs random blobs usingssh-agent
. It fails about 0.7% percent of the time, which is almost exactly the probability that at least one of thempint
values has a leading 0 byte (1 - (255/256)**2 = 0.0077
).Looking through the code, there are two places where things go wrong:
ecdsa_sig_size
checks that thempint
be exactly the curve length; it should also accept shorter valuesp256_signature_from_openssh_bytes
(and equivalent) callsp256::FieldBytes::try_from(..)
onMpint::positive_bytes
, which fails if theMpint
is short; it should instead pad with leading zerosThe text was updated successfully, but these errors were encountered: