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

X.509 signature algorithm and signature value helpers. More...

#include "qsccommon.h"
#include "x509types.h"

Go to the source code of this file.

Data Structures

struct  qsc_x509_ecdsa_signature_t
 The decoded ECDSA signature value. More...

Macros

#define QSC_X509_MAX_SIGNATURE_COMPONENT_SIZE   66U
 The maximum size in bytes of an ECDSA signature component.

Typedefs

typedef struct qsc_x509_ecdsa_signature_t qsc_x509_ecdsa_signature
 The decoded ECDSA signature value.

Functions

QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_algorithm_decode (const qsc_encoding_ber_element *element, qsc_x509_algorithm_identifier *algorithm)
 Decodes a signature AlgorithmIdentifier structure.
QSC_EXPORT_API bool qsc_x509_signature_algorithm_equal (const qsc_x509_algorithm_identifier *left, const qsc_x509_algorithm_identifier *right)
 Compares two decoded algorithm identifiers for semantic equality.
QSC_EXPORT_API bool qsc_x509_signature_algorithm_is_ecdsa (qsc_x509_signature_algorithm algorithm)
 Tests whether a decoded signature algorithm is an ECDSA variant.
QSC_EXPORT_API bool qsc_x509_signature_algorithm_is_ml_dsa (qsc_x509_signature_algorithm algorithm)
 Tests whether a decoded signature algorithm is an ML-DSA variant.
QSC_EXPORT_API bool qsc_x509_signature_algorithm_matches_spki (qsc_x509_signature_algorithm algorithm, const qsc_x509_subject_public_key_info *spki)
 Tests whether a decoded signature algorithm is compatible with the supplied subject public key information.
QSC_EXPORT_API size_t qsc_x509_signature_expected_size (qsc_x509_signature_algorithm algorithm, qsc_x509_named_curve curve)
 Gets the expected raw signature size in octets for a signature algorithm.
QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_value_decode_raw (const qsc_encoding_ber_element *element, uint8_t *signature, size_t signaturelen, size_t *outlen)
 Decodes a certificate signature BIT STRING as a raw octet sequence.
QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_value_decode_ecdsa (const qsc_encoding_ber_element *element, qsc_x509_named_curve curve, qsc_x509_ecdsa_signature *signature)
 Decodes a certificate ECDSA signature BIT STRING.
QSC_EXPORT_API size_t qsc_x509_signature_component_size (qsc_x509_named_curve curve)
 Gets the expected maximum signature component size in octets for a named curve.

Detailed Description

X.509 signature algorithm and signature value helpers.

This header defines the public API used to decode certificate, CRL, and CSR signature AlgorithmIdentifier structures, compare decoded signature algorithms, classify supported signature families, and decode signature values from the BIT STRING form used in DER encoded X.509 objects.

The module supports the classical ECDSA families used elsewhere in the QSC tree and the pure ML-DSA signature identifiers used by the post-quantum path. ECDSA signatures are decoded from the DER SEQUENCE of INTEGER values into fixed-width big-endian component arrays. ML-DSA signatures are treated as raw opaque octet strings carried directly in the BIT STRING payload. The helper routines in this module are validation-oriented and do not allocate memory or retain references into caller-owned ASN.1 buffers.

Typedef Documentation

◆ qsc_x509_ecdsa_signature

The decoded ECDSA signature value.

Remarks
The r and s arrays are stored as unsigned big-endian integers, left padded with zero octets to the width implied by the named curve.

Function Documentation

◆ qsc_x509_signature_algorithm_decode()

QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_algorithm_decode ( const qsc_encoding_ber_element * element,
qsc_x509_algorithm_identifier * algorithm )

Decodes a signature AlgorithmIdentifier structure.

Parameters
element[const qsc_encoding_ber_element*] The ASN.1 SEQUENCE element containing the AlgorithmIdentifier structure.
algorithm[qsc_x509_algorithm_identifier*] Receives the decoded algorithm identifier.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_x509_signature_algorithm_equal()

QSC_EXPORT_API bool qsc_x509_signature_algorithm_equal ( const qsc_x509_algorithm_identifier * left,
const qsc_x509_algorithm_identifier * right )

Compares two decoded algorithm identifiers for semantic equality.

Parameters
left[const qsc_x509_algorithm_identifier*] The left algorithm value.
right[const qsc_x509_algorithm_identifier*] The right algorithm value.
Returns
[bool] Returns true if the two algorithm identifiers are equivalent.

◆ qsc_x509_signature_algorithm_is_ecdsa()

QSC_EXPORT_API bool qsc_x509_signature_algorithm_is_ecdsa ( qsc_x509_signature_algorithm algorithm)

Tests whether a decoded signature algorithm is an ECDSA variant.

Parameters
algorithm[qsc_x509_signature_algorithm] The decoded signature algorithm.
Returns
[bool] Returns true for ECDSA-with-SHA1/SHA256/SHA384/SHA512.

◆ qsc_x509_signature_algorithm_is_ml_dsa()

QSC_EXPORT_API bool qsc_x509_signature_algorithm_is_ml_dsa ( qsc_x509_signature_algorithm algorithm)

Tests whether a decoded signature algorithm is an ML-DSA variant.

Parameters
algorithm[qsc_x509_signature_algorithm] The decoded signature algorithm.
Returns
[bool] Returns true for ML-DSA-44, ML-DSA-65, or ML-DSA-87.

◆ qsc_x509_signature_algorithm_matches_spki()

QSC_EXPORT_API bool qsc_x509_signature_algorithm_matches_spki ( qsc_x509_signature_algorithm algorithm,
const qsc_x509_subject_public_key_info * spki )

Tests whether a decoded signature algorithm is compatible with the supplied subject public key information.

Parameters
algorithm[qsc_x509_signature_algorithm] The decoded signature algorithm.
spki[const qsc_x509_subject_public_key_info*] The public key information.
Returns
[bool] Returns true if the signature algorithm and SPKI describe a compatible signing primitive and parameter set.

◆ qsc_x509_signature_component_size()

QSC_EXPORT_API size_t qsc_x509_signature_component_size ( qsc_x509_named_curve curve)

Gets the expected maximum signature component size in octets for a named curve.

Parameters
curve[qsc_x509_named_curve] The named curve identifier.
Returns
[size_t] Returns the signature component size in octets, or zero if the curve is not recognized.

◆ qsc_x509_signature_expected_size()

QSC_EXPORT_API size_t qsc_x509_signature_expected_size ( qsc_x509_signature_algorithm algorithm,
qsc_x509_named_curve curve )

Gets the expected raw signature size in octets for a signature algorithm.

For ECDSA this returns the size of the raw concatenated r || s form used by the internal QSC verification path. For ML-DSA this returns the compiled signature size when available. For unknown or unsupported algorithms, zero is returned.

Parameters
algorithm[qsc_x509_signature_algorithm] The decoded signature algorithm.
curve[qsc_x509_named_curve] The named curve for ECDSA signatures.
Returns
[size_t] Returns the expected raw signature size in octets, or zero.

◆ qsc_x509_signature_value_decode_ecdsa()

QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_value_decode_ecdsa ( const qsc_encoding_ber_element * element,
qsc_x509_named_curve curve,
qsc_x509_ecdsa_signature * signature )

Decodes a certificate ECDSA signature BIT STRING.

Parameters
element[const qsc_encoding_ber_element*] The BIT STRING element containing the DER encoded ECDSA signature value.
curve[qsc_x509_named_curve] The named curve associated with the signing key.
signature[qsc_x509_ecdsa_signature*] Receives the decoded signature components.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_x509_signature_value_decode_raw()

QSC_EXPORT_API qsc_asn1_status qsc_x509_signature_value_decode_raw ( const qsc_encoding_ber_element * element,
uint8_t * signature,
size_t signaturelen,
size_t * outlen )

Decodes a certificate signature BIT STRING as a raw octet sequence.

Parameters
element[const qsc_encoding_ber_element*] The BIT STRING element containing the signature value.
signature[uint8_t*] Receives the raw signature octets.
signaturelen[size_t] The size of the output array in octets.
outlen[size_t*] Receives the number of octets written.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.