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

X.509 private key encoding and PEM conversion interface. More...

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

Go to the source code of this file.

Macros

#define QSC_X509_KEY_WRITE_MAX   16384U
 The maximum number of octets used by key writer scratch and output buffers.

Functions

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_sec1_der (const qsc_x509_private_key *key, bool includeparameters, bool includepublickey, uint8_t *output, size_t *outputlen)
 Encode a normalized private key object as SEC 1 DER.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_sec1_pem (const qsc_x509_private_key *key, bool includeparameters, bool includepublickey, char *output, size_t *outputlen)
 Encode a normalized private key object as SEC 1 PEM.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_der (const qsc_x509_private_key *key, bool includepublickey, uint8_t *output, size_t *outputlen)
 Encode a normalized private key object as PKCS #8 DER.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_pem (const qsc_x509_private_key *key, bool includepublickey, char *output, size_t *outputlen)
 Encode a normalized private key object as PKCS #8 PEM.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_der_ex (const qsc_x509_algorithm_identifier *algorithm, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, uint8_t *output, size_t *outputlen)
 Encode raw private key material as PKCS #8 DER.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_pem_ex (const qsc_x509_algorithm_identifier *algorithm, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, char *output, size_t *outputlen)
 Encode raw private key material as PKCS #8 PEM.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_dsa_der (qsc_x509_pqc_parameter_set parameter, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, uint8_t *output, size_t *outputlen)
 Encode an ML-DSA private key as PKCS #8 DER.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_dsa_pem (qsc_x509_pqc_parameter_set parameter, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, char *output, size_t *outputlen)
 Encode an ML-DSA private key as PKCS #8 PEM.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_kem_der (qsc_x509_pqc_parameter_set parameter, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, uint8_t *output, size_t *outputlen)
 Encode an ML-KEM private key as PKCS #8 DER.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_kem_pem (qsc_x509_pqc_parameter_set parameter, const uint8_t *privatekey, size_t privatekeylen, const uint8_t *publickey, size_t publickeylen, bool publickeypresent, char *output, size_t *outputlen)
 Encode an ML-KEM private key as PKCS #8 PEM.

Detailed Description

X.509 private key encoding and PEM conversion interface.

This header defines the public interface used to encode normalized private key objects into SEC 1 and PKCS #8 representations in both DER and PEM forms. The interface supports generic encoding from a qsc_x509_private_key container, caller-supplied raw key material and algorithm identifiers, and convenience wrappers for ML-DSA and ML-KEM parameter-set specific PKCS #8 emission. For EC keys, the PKCS #8 encoder normalizes the AlgorithmIdentifier parameters to a namedCurve OID when the caller supplies only the curve selector.

The PKCS #8 helpers support optional inclusion of the embedded public key when the underlying format and algorithm permit its representation. The SEC 1 helpers additionally provide control over whether algorithm parameters and public key fields are emitted.

Function Documentation

◆ qsc_x509_private_key_encode_pkcs8_der()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_der ( const qsc_x509_private_key * key,
bool includepublickey,
uint8_t * output,
size_t * outputlen )

Encode a normalized private key object as PKCS #8 DER.

Serializes the supplied private-key container to DER encoded PKCS #8 format. The caller may request inclusion of the optional embedded public key.

Parameters
key[const][struct] The source private-key container.
includepublickeyIncludes the optional embedded public key when set to true.
outputThe destination buffer receiving the DER encoding.
outputlenThe input capacity of the output buffer and, on success, the number of bytes written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_der_ex()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_der_ex ( const qsc_x509_algorithm_identifier * algorithm,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
uint8_t * output,
size_t * outputlen )

Encode raw private key material as PKCS #8 DER.

Serializes caller-supplied private key bytes, algorithm identifier, and optional public key bytes to DER encoded PKCS #8 format without requiring a qsc_x509_private_key container.

Parameters
algorithm[const][struct] The algorithm identifier to encode.
privatekey[const] The raw private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination buffer receiving the DER encoding.
outputlenThe input capacity of the output buffer and, on success, the number of bytes written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_ml_dsa_der()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_dsa_der ( qsc_x509_pqc_parameter_set parameter,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
uint8_t * output,
size_t * outputlen )

Encode an ML-DSA private key as PKCS #8 DER.

Serializes caller-supplied ML-DSA private key material using the selected ML-DSA parameter set and emits DER encoded PKCS #8 output.

Parameters
parameter[enum] The ML-DSA parameter set identifier.
privatekey[const] The raw ML-DSA private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw ML-DSA public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination buffer receiving the DER encoding.
outputlenThe input capacity of the output buffer and, on success, the number of bytes written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_ml_dsa_pem()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_dsa_pem ( qsc_x509_pqc_parameter_set parameter,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
char * output,
size_t * outputlen )

Encode an ML-DSA private key as PKCS #8 PEM.

Serializes caller-supplied ML-DSA private key material using the selected ML-DSA parameter set and converts the resulting PKCS #8 object to PEM text.

Parameters
parameter[enum] The ML-DSA parameter set identifier.
privatekey[const] The raw ML-DSA private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw ML-DSA public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination character buffer receiving the PEM text.
outputlenThe input capacity of the output buffer and, on success, the number of characters written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_ml_kem_der()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_kem_der ( qsc_x509_pqc_parameter_set parameter,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
uint8_t * output,
size_t * outputlen )

Encode an ML-KEM private key as PKCS #8 DER.

Serializes caller-supplied ML-KEM private key material using the selected ML-KEM parameter set and emits DER encoded PKCS #8 output.

Parameters
parameter[enum] The ML-KEM parameter set identifier.
privatekey[const] The raw ML-KEM private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw ML-KEM public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination buffer receiving the DER encoding.
outputlenThe input capacity of the output buffer and, on success, the number of bytes written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_ml_kem_pem()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_ml_kem_pem ( qsc_x509_pqc_parameter_set parameter,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
char * output,
size_t * outputlen )

Encode an ML-KEM private key as PKCS #8 PEM.

Serializes caller-supplied ML-KEM private key material using the selected ML-KEM parameter set and converts the resulting PKCS #8 object to PEM text.

Parameters
parameter[enum] The ML-KEM parameter set identifier.
privatekey[const] The raw ML-KEM private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw ML-KEM public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination character buffer receiving the PEM text.
outputlenThe input capacity of the output buffer and, on success, the number of characters written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_pem()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_pem ( const qsc_x509_private_key * key,
bool includepublickey,
char * output,
size_t * outputlen )

Encode a normalized private key object as PKCS #8 PEM.

Serializes the supplied private-key container to PKCS #8 DER and converts the result to PEM text form.

Parameters
key[const][struct] The source private-key container.
includepublickeyIncludes the optional embedded public key when set to true.
outputThe destination character buffer receiving the PEM text.
outputlenThe input capacity of the output buffer and, on success, the number of characters written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_pkcs8_pem_ex()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_pkcs8_pem_ex ( const qsc_x509_algorithm_identifier * algorithm,
const uint8_t * privatekey,
size_t privatekeylen,
const uint8_t * publickey,
size_t publickeylen,
bool publickeypresent,
char * output,
size_t * outputlen )

Encode raw private key material as PKCS #8 PEM.

Serializes caller-supplied private key bytes, algorithm identifier, and optional public key bytes to PKCS #8 DER and converts the result to PEM text form.

Parameters
algorithm[const][struct] The algorithm identifier to encode.
privatekey[const] The raw private key bytes.
privatekeylenThe length of the private key in bytes.
publickey[const] The optional raw public key bytes.
publickeylenThe length of the public key in bytes.
publickeypresentIndicates whether the public key input is present.
outputThe destination character buffer receiving the PEM text.
outputlenThe input capacity of the output buffer and, on success, the number of characters written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_sec1_der()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_sec1_der ( const qsc_x509_private_key * key,
bool includeparameters,
bool includepublickey,
uint8_t * output,
size_t * outputlen )

Encode a normalized private key object as SEC 1 DER.

Serializes the supplied private-key container to DER encoded SEC 1 format. The caller may request inclusion of algorithm parameters and an embedded public key when supported by the underlying key representation.

Parameters
key[const][struct] The source private-key container.
includeparametersIncludes algorithm parameters when set to true.
includepublickeyIncludes the optional embedded public key when set to true.
outputThe destination buffer receiving the DER encoding.
outputlenThe input capacity of the output buffer and, on success, the number of bytes written.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_private_key_encode_sec1_pem()

QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_encode_sec1_pem ( const qsc_x509_private_key * key,
bool includeparameters,
bool includepublickey,
char * output,
size_t * outputlen )

Encode a normalized private key object as SEC 1 PEM.

Serializes the supplied private-key container to SEC 1 DER and converts the result to PEM text form.

Parameters
key[const][struct] The source private-key container.
includeparametersIncludes algorithm parameters when set to true.
includepublickeyIncludes the optional embedded public key when set to true.
outputThe destination character buffer receiving the PEM text.
outputlenThe input capacity of the output buffer and, on success, the number of characters written.
Returns
[enum] Returns a qsc_asn1_status code.