EcdsaSignatureCodec

Converts ECDSA signatures between the raw r || s of CryptoBackend.sign and CryptoBackend.verify (COSE, RFC 9053 §2.1) and the DER ECDSA-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER } of X.509 and TLS (RFC 3279 §2.2.3, RFC 8422 §5.4).

DTLS signs its handshake through CryptoBackend.sign and converts the result with toDer, and turns a peer's DER signature into the raw form with fromDer before it verifies. A backend on a platform that signs in DER, such as JCA, the Android KeyStore or Apple's SecKey, converts the other way to implement CryptoBackend.sign for SignatureAlgorithm.ES256 and SignatureAlgorithm.ES384.

Functions

Link copied to clipboard

The raw r || s of the DER signature der, each half as long as a coordinate of the curve of algorithm, or null when der is not exactly one DER ECDSA-Sig-Value whose r and s are positive and fit that length. Peer input never makes it throw: a malformed signature is one that does not verify.

Link copied to clipboard
fun toDer(algorithm: SignatureAlgorithm, signature: ByteArray): ByteArray

The DER encoding of the raw signature signature, r || s with each half as long as a coordinate of the curve of algorithm.