|
Leancrypto 1.7.2
Post-Quantum Cryptographic Library
|
Macros | |
| #define | LC_PKCS8_MSG_ON_STACK(name) |
| Allocate memory for struct lc_pkcs8_message holding given number of preallocated sinfo members. More... | |
Functions | |
| int | lc_pkcs8_decode (struct lc_pkcs8_message *pkcs8, const uint8_t *data, size_t datalen) |
| Decode a PKCS#8 message. More... | |
| int | lc_pkcs8_set_privkey (struct lc_pkcs8_message *pkcs8, struct lc_x509_key_data *privkey) |
| Set the private key for the PKCS8 message. More... | |
| void | lc_pkcs8_message_clear (struct lc_pkcs8_message *pkcs8) |
| Clear the resources used by the PKCS#8 message parsing state. More... | |
| int | lc_pkcs8_signature_gen (uint8_t *sig_data, size_t *siglen, const struct lc_pkcs8_message *pkcs8, const uint8_t *m, size_t mlen, const struct lc_hash *prehash_algo) |
| Generate signature over user-supplied data. More... | |
Concept of PKCS#8 parsing in leancrypto
The leancrypto library provides a PKCS#8 parser which can read and understand PKCS#8 messages. To appropriately use the PKCS#8 parser, please consider the following rules:
pkcs8_message is provided as part of the official header file. But it is NOT considered to be an API. I.e. member variables or the structure format may change between versions of leancrypto without announcement. The reason for providing the data structure in the official header file is to support stack-only clients. Aas a PKCS#8 message may contain an arbitrary amount of X.509 certificates and signer information sections, the macro LC_PKCS8_MSG_ON_STACK is provided to allocate stack memory for a given number of signers and X.509 certificates. If more certificates or signers are found, heap is transparently allocated.pkcs8_message data structure.The PKCS#8 message parser currently only covers signature verification to support use cases of secure boot.
For performing a proper PKCS#8 validation, execute the following steps:
Initialize and load the certificate trust store by executing the following sub tasks. This assumes that each trusted public key is represented as an X.509 certificate which implies the set of sub steps must be executed for each certificate that shall be part of the trust store.
a. Load the X.509 data blob with lc_x509_certificate_parse
b. Register the certificate in the PKCS#8 trust store with lc_pkcs8_trust_anchor_add
lc_pkcs8_message_parse.lc_pkcs8_verify. | #define LC_PKCS8_MSG_ON_STACK | ( | name | ) |
Allocate memory for struct lc_pkcs8_message holding given number of preallocated sinfo members.
This allocation allows the PKCS8 parsing to avoid allocate memory and keep all operations on stack. In case more signers than num_sinfo or more X.509 certificates than num_x509 are parsed from the PKCS8 message, then first all pre-allocated structures are used and then new ones are allocated.
When not using this macro, which is perfectly legal, an simply allocating struct lc_pkcs8_message on stack, then for all parsed signers and X.509 certificates, a new memory entry is allocated.
| [in] | name | Name of stack variable |
Definition at line 78 of file lc_pkcs8_common.h.
| int lc_pkcs8_decode | ( | struct lc_pkcs8_message * | pkcs8, |
| const uint8_t * | data, | ||
| size_t | datalen | ||
| ) |
Decode a PKCS#8 message.
The function parses a PKCS#8 data buffer into a data structure that allows accessing the various data points of the PKCS#8 message.
pkcs8 data structure will contain pointers to the data buffer. I.e. the message parsing analyzes data and finds all relevant data in the raw X.509 data blob. The caller MUST therefore keep the data pointer constant as long as the pkcs8 pointer is valid.This API offers parsing of:
| [in,out] | pkcs8 | The data structure that is filled with all parameters from the PKCS#8 message data buffer. The buffer must have been allocated by the caller. It is permissible to keep it on the stack. |
| [in] | data | Raw PKCS#8 data blob following RFC5652 |
| [in] | datalen | Length of the raw PKCS#8 message buffer |
| void lc_pkcs8_message_clear | ( | struct lc_pkcs8_message * | pkcs8 | ) |
Clear the resources used by the PKCS#8 message parsing state.
| [in] | pkcs8 | Certificate structure to be cleared |
| int lc_pkcs8_set_privkey | ( | struct lc_pkcs8_message * | pkcs8, |
| struct lc_x509_key_data * | privkey | ||
| ) |
Set the private key for the PKCS8 message.
The function sets the pointers to the private key in the PKCS#8 message correctly. For encoding, the private key is read, for decoding, the private key buffer is filled by the parser.
| [in,out] | pkcs8 | The PKCS#8 data structure that shall receive the private key. |
| [in] | privkey | Raw private key data |
| int lc_pkcs8_signature_gen | ( | uint8_t * | sig_data, |
| size_t * | siglen, | ||
| const struct lc_pkcs8_message * | pkcs8, | ||
| const uint8_t * | m, | ||
| size_t | mlen, | ||
| const struct lc_hash * | prehash_algo | ||
| ) |
Generate signature over user-supplied data.
This is the PKCS#8 equivalent to lc_x509_signature_gen.
| [out] | sig_data | Caller-supplied buffer with signature (it needs to be at least as large as reported by lc_x509_get_signature_size_from_sk or lc_x509_get_signature_size_from_cert) |
| [in,out] | siglen | Length of the sig_data buffer, the value will be updated such that it reflects the length of the signature. |
| [in] | pkcs8 | The PKCS#8 message holding the private key |
| [in] | m | Message to be signed |
| [in] | mlen | Length of message |
| [in] | prehash_algo | It is permissible that the message is prehashed. If so, it is indicated by this parameter which points to the used message digest the caller used to generate the prehashed message digest. This forces the use of the Hash[ML|SLH]-DSA. |