Leancrypto 1.7.2
Post-Quantum Cryptographic Library
Functions
PKCS#8 Message Generate Handling

Functions

int lc_pkcs8_encode (const struct lc_pkcs8_message *pkcs8, uint8_t *data, size_t *avail_datalen)
 Encode a PKCS#8 message. More...
 

Detailed Description

Concept of PKCS#8 message generation handling in leancrypto

The leancrypto library provides an PKCS#8 generator which can create PKCS#8 messages. The generator does not enforce any PKCS#8 limitations and thus allows the caller to generate any combination of field offered by the PKCS#8 specification. To appropriately use the PKCS#8 parser, please consider the following rules:

  1. The generated PKCS#8 data blob is independent of the original PKCS#8 certificate data structure.
  2. The generator does not allocate any memory. All memory MUST be provided by the caller. Thus, if the caller provides insufficient memory, the generator will return -EOVERFLOW.
  3. Before invoking the PKCS#8 generator, the caller must allocate an lc_pkcs8_message data structure (e.g. on stack) and fill it with the numerous setter functions to add data.
  4. The pkcs8_message data structure should be released at the end of the operation with lc_pkcs8_message_clear.

Function Documentation

◆ lc_pkcs8_encode()

int lc_pkcs8_encode ( const struct lc_pkcs8_message *  pkcs8,
uint8_t *  data,
size_t *  avail_datalen 
)

Encode a PKCS#8 message.

The function generates a PKCS#8 data blob from the filled PKCS#8 data structure.

The signature of the data using the signer is created within this call.

This API offers generation of PKCS#8 messages with:

  • ML-DSA expanded key (i.e. full ML-DSA key) following RFC 9881 chapter 6. This is enabled by generating a new key pair as seed with lc_x509_keypair_gen.
  • ML-DSA seed which is expanded into the full ML-DSA key during parsing following RFC 9881 chapter 6. This is enabled by generating a new key pair without defining it as seed using lc_x509_keypair_gen.
  • For all other algorithms, the common key type
Parameters
[in]pkcs8The data structure that is filled by the caller before this invocation using the various setter functions.
[in,out]dataRaw PKCS#8 data blob in DER / BER format - the caller must provide the memory
[in,out]avail_datalenLength of the raw PKCS#8 certificate buffer that is free (the input value must be equal to the data buffer size, the output refers to how many bytes are unused)
Returns
0 on success or < 0 on error