pub struct Signature {
pub r: Vec<u8>,
pub s: Vec<u8>,
}Expand description
ECDSA signature (r, s) as big-endian byte arrays.
Each component is felem_bytes octets long for the curve
(32 / 48 / 64 / 66 depending on the curve).
Fields§
§r: Vec<u8>r component of the signature, big-endian.
s: Vec<u8>s component of the signature, big-endian.
Implementations§
Source§impl Signature
impl Signature
Sourcepub fn to_der(&self) -> Vec<u8> ⓘ
pub fn to_der(&self) -> Vec<u8> ⓘ
Encode as ASN.1 DER (RFC 5480 / X.509 standard form):
ECDSA-Sig-Value ::= SEQUENCE {
r INTEGER,
s INTEGER
}Uses the strict canonical DER encoding:
- Lengths use the shortest form (single byte < 128,
81 xxup to 255,82 hi loabove). - INTEGERs strip leading zero octets, and prepend one
00octet if the high bit of the first octet would otherwise be set (which would make the number look negative in two’s complement).
This is the format used by X.509 certificates, TLS, S/MIME, CMS,
JWS ES256-DER, and virtually every OpenSSL-derived tool.
Sourcepub fn from_der(der: &[u8]) -> Option<Self>
pub fn from_der(der: &[u8]) -> Option<Self>
Parse an ASN.1 DER encoding (strict). Returns None if the input
is not a valid canonical DER encoding of an ECDSA signature.
Rejected inputs include (for defence against signature malleability and parser-differential attacks):
- Any input whose length does not exactly match the advertised SEQUENCE length.
- Non-minimal length encodings (e.g.
81 10where10would do, or82 00 10where10would do). - INTEGERs with superfluous leading zero octets, or with the high bit set (which would be a negative number).
- r or s equal to zero.
The returned Signature has r and s stripped of their DER
padding (so they may be shorter than LIMBS * 8 bytes). This is
fine for Curve::verify, which interprets them via bits2int and
thus handles variable widths correctly.