QSC Post Quantum Cryptographic Library 1.3.0.0 (C1)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
tlsecdsader.h File Reference

RFC 8446 section 4.2.3 ECDSA-Sig-Value DER encoding. More...

#include "qsccommon.h"
#include "tlserrors.h"

Go to the source code of this file.

Functions

QSC_EXPORT_API qsc_tls_status qsc_tls_ecdsa_der_encode (const uint8_t *rs, size_t componentsize, uint8_t *output, size_t outlen, size_t *written)
 DER-encode a raw r||s ECDSA signature.
QSC_EXPORT_API qsc_tls_status qsc_tls_ecdsa_der_decode (const uint8_t *der, size_t derlen, size_t componentsize, uint8_t *output, size_t outlen)
 Decode a DER-encoded ECDSA signature into raw r||s form.

Detailed Description

RFC 8446 section 4.2.3 ECDSA-Sig-Value DER encoding.

TLS 1.3 ECDSA signatures on the wire are DER-encoded as: ECDSA-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER } QSC's ecdsa primitive produces raw r||s of fixed width. These helpers convert between the two representations. INTEGER encoding rules (X.690):

  • Shortest-form length.
  • If the MSB of the first content byte is 1, a leading 0x00 must be prepended to distinguish positive from negative.
  • Leading 0x00 bytes that are not required for disambiguation are stripped (shortest form).

Function Documentation

◆ qsc_tls_ecdsa_der_decode()

QSC_EXPORT_API qsc_tls_status qsc_tls_ecdsa_der_decode ( const uint8_t * der,
size_t derlen,
size_t componentsize,
uint8_t * output,
size_t outlen )

Decode a DER-encoded ECDSA signature into raw r||s form.

Parameters
der[const uint8_t*] DER-encoded signature.
derlen[size_t] DER signature length.
componentsize[size_t] Expected size of each component (defines output width).
output[uint8_t*] Destination r||s buffer; must be at least 2*componentsize bytes.
outlen[size_t] Capacity of output.

◆ qsc_tls_ecdsa_der_encode()

QSC_EXPORT_API qsc_tls_status qsc_tls_ecdsa_der_encode ( const uint8_t * rs,
size_t componentsize,
uint8_t * output,
size_t outlen,
size_t * written )

DER-encode a raw r||s ECDSA signature.

Parameters
rs[const uint8_t*] Raw r||s buffer, each component width bytes long.
componentsize[size_t] Size of each component in bytes (32 for P-256, 48 for P-384, 66 for P-521).
output[uint8_t*] Destination buffer for DER-encoded signature.
outlen[size_t] Capacity of output.
written[size_t*] On success, receives the DER length (variable, typically 70-72 for P-256).