MPDC: Multi Party Domain Cryptosystem 1.0.0.0b (A0)
MPDC Interior protocol
|
MPDC Certificate Handling Functions. More...
#include "mpdc.h"
Go to the source code of this file.
Functions | |
MPDC_EXPORT_API mpdc_configuration_sets | mpdc_certificate_algorithm_decode (const char *name) |
Decode the string algorithm-set number to the enumerated representation. | |
MPDC_EXPORT_API bool | mpdc_certificate_algorithm_enabled (mpdc_configuration_sets conf) |
Test if the specified protocol-set is enabled on this system. | |
MPDC_EXPORT_API void | mpdc_certificate_algorithm_encode (char *name, mpdc_configuration_sets conf) |
Encode the protocol-set enumerator into its string form. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_are_equal (const mpdc_child_certificate *a, const mpdc_child_certificate *b) |
Compare two child certificates for equivalence. | |
MPDC_EXPORT_API void | mpdc_certificate_child_copy (mpdc_child_certificate *output, const mpdc_child_certificate *input) |
Copy a child certificate structure. | |
MPDC_EXPORT_API void | mpdc_certificate_child_create (mpdc_child_certificate *child, const uint8_t *pubkey, const mpdc_certificate_expiration *expiration, const char *issuer, mpdc_network_designations designation) |
Create a child certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_decode (mpdc_child_certificate *child, const char enck[MPDC_CHILD_CERTIFICATE_STRING_SIZE]) |
Decode a child certificate string into a certificate structure. | |
MPDC_EXPORT_API void | mpdc_certificate_child_deserialize (mpdc_child_certificate *child, const uint8_t *input) |
Deserialize a child certificate from a byte array. | |
MPDC_EXPORT_API size_t | mpdc_certificate_child_encode (char enck[MPDC_CHILD_CERTIFICATE_STRING_SIZE], const mpdc_child_certificate *child) |
Encode a public child certificate into a human-readable string. | |
MPDC_EXPORT_API void | mpdc_certificate_child_erase (mpdc_child_certificate *child) |
Delete (erase) a child certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_file_to_struct (const char *fpath, mpdc_child_certificate *child) |
Copy a serialized certificate from a file into a child certificate structure. | |
MPDC_EXPORT_API void | mpdc_certificate_child_hash (uint8_t *output, const mpdc_child_certificate *child) |
Compute the cryptographic hash of a child certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_is_valid (const mpdc_child_certificate *child) |
Test a child certificate for a valid format and expiration. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_message_verify (uint8_t *message, size_t *msglen, const uint8_t *signature, size_t siglen, const mpdc_child_certificate *child) |
Verify a message signature using a child certificate. | |
MPDC_EXPORT_API void | mpdc_certificate_child_serialize (uint8_t *output, const mpdc_child_certificate *child) |
Serialize a child certificate into a contiguous byte array. | |
MPDC_EXPORT_API bool | mpdc_certificate_signature_hash_verify (const uint8_t *signature, size_t siglen, const uint8_t *message, size_t msglen, const mpdc_child_certificate *lcert) |
Verify that a signature hash matches a computed message hash using a child certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_child_struct_to_file (const char *fpath, const mpdc_child_certificate *child) |
Write a child certificate structure to a file. | |
MPDC_EXPORT_API mpdc_network_designations | mpdc_certificate_designation_decode (const char *sdsg) |
Decode the network-designation string to its enumerated representation. | |
MPDC_EXPORT_API size_t | mpdc_certificate_designation_encode (char *sdsg, mpdc_network_designations designation) |
Encode the network-designation enumerator into a string. | |
MPDC_EXPORT_API void | mpdc_certificate_expiration_set_days (mpdc_certificate_expiration *expiration, uint16_t start, uint16_t duration) |
Set the expiration days on a certificate expiration structure. | |
MPDC_EXPORT_API void | mpdc_certificate_expiration_set_seconds (mpdc_certificate_expiration *expiration, uint64_t start, uint64_t period) |
Set the expiration seconds on a certificate expiration structure. | |
MPDC_EXPORT_API bool | mpdc_certificate_expiration_time_verify (const mpdc_certificate_expiration *expiration) |
Verify the expiration time against the current UTC time. | |
MPDC_EXPORT_API size_t | mpdc_certificate_message_hash_sign (uint8_t *signature, const uint8_t *sigkey, const uint8_t *message, size_t msglen) |
Hash a message and sign the hash. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_compare (const mpdc_root_certificate *a, const mpdc_root_certificate *b) |
Compare two root certificates for equivalence. | |
MPDC_EXPORT_API void | mpdc_certificate_root_create (mpdc_root_certificate *root, const uint8_t *pubkey, const mpdc_certificate_expiration *expiration, const char *issuer) |
Create a root certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_decode (mpdc_root_certificate *root, const char *enck) |
Decode a root certificate string into a certificate structure. | |
MPDC_EXPORT_API void | mpdc_certificate_root_deserialize (mpdc_root_certificate *root, const uint8_t *input) |
Deserialize a root certificate from a byte array. | |
MPDC_EXPORT_API size_t | mpdc_certificate_root_encode (char *enck, const mpdc_root_certificate *root) |
Encode a public root certificate into a human-readable string. | |
MPDC_EXPORT_API void | mpdc_certificate_root_erase (mpdc_root_certificate *root) |
Delete (erase) a root certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_file_to_struct (const char *fpath, mpdc_root_certificate *root) |
Copy a serialized root certificate from a file into a root certificate structure. | |
MPDC_EXPORT_API void | mpdc_certificate_root_hash (uint8_t *output, const mpdc_root_certificate *root) |
Compute the cryptographic hash of a root certificate. | |
MPDC_EXPORT_API void | mpdc_certificate_root_serialize (uint8_t *output, const mpdc_root_certificate *root) |
Serialize a root certificate into a contiguous byte array. | |
MPDC_EXPORT_API size_t | mpdc_certificate_root_sign (mpdc_child_certificate *child, const mpdc_root_certificate *root, const uint8_t *rsigkey) |
Sign a child certificate with the root certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_signature_verify (const mpdc_child_certificate *child, const mpdc_root_certificate *root) |
Verify a child certificate against a root certificate. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_struct_to_file (const char *fpath, const mpdc_root_certificate *root) |
Write a root certificate structure to a file. | |
MPDC_EXPORT_API bool | mpdc_certificate_root_is_valid (const mpdc_root_certificate *root) |
Validate a root certificate. | |
MPDC_EXPORT_API void | mpdc_certificate_signature_generate_keypair (mpdc_signature_keypair *keypair) |
Generate and encode an asymmetric signature scheme keypair. | |
MPDC_EXPORT_API size_t | mpdc_certificate_signature_sign_message (uint8_t *signature, const uint8_t *message, size_t msglen, const uint8_t *prikey) |
Sign a message using the asymmetric signature scheme. | |
MPDC_EXPORT_API bool | mpdc_certificate_signature_verify_message (const uint8_t *message, size_t msglen, const uint8_t *signature, size_t siglen, const uint8_t *pubkey) |
Verify a message signature using the asymmetric signature scheme. | |
MPDC Certificate Handling Functions.
This header defines the functions for managing and processing certificates used by the Multi-Party Domain Cryptosystem (MPDC). The certificate module is responsible for creating, encoding, decoding, serializing, deserializing, signing, and verifying both child (device) and root (trust anchor) certificates. These certificates carry critical information such as:
The functions provided in this module allow conversion between protocol-set strings and their enumerated representations, as well as conversion of network-designation values between string and enumerated forms. They also perform cryptographic operations such as hashing and digital signing, using the underlying QSC cryptographic primitives.
These tests help ensure that the certificate operations function as expected in real-world use.
MPDC_EXPORT_API mpdc_configuration_sets mpdc_certificate_algorithm_decode | ( | const char * | name | ) |
Decode the string algorithm-set number to the enumerated representation.
name | [in, const] The protocol-set string (for example, "dilithium-s1_kyber-s1_rcs-256_sha3-256"). |
MPDC_EXPORT_API bool mpdc_certificate_algorithm_enabled | ( | mpdc_configuration_sets | conf | ) |
Test if the specified protocol-set is enabled on this system.
conf | The protocol-set enumerator to test. |
MPDC_EXPORT_API void mpdc_certificate_algorithm_encode | ( | char * | name, |
mpdc_configuration_sets | conf ) |
Encode the protocol-set enumerator into its string form.
name | [out] The output buffer that will receive the protocol-set string. |
conf | The protocol-set enumerator to encode. |
MPDC_EXPORT_API bool mpdc_certificate_child_are_equal | ( | const mpdc_child_certificate * | a, |
const mpdc_child_certificate * | b ) |
Compare two child certificates for equivalence.
This function compares all the significant fields of two child certificate structures (including algorithm, version, designation, expiration, issuer, serial, signature, and public key).
a | [in, const] The first certificate. |
b | [in, const] The second certificate. |
MPDC_EXPORT_API void mpdc_certificate_child_copy | ( | mpdc_child_certificate * | output, |
const mpdc_child_certificate * | input ) |
Copy a child certificate structure.
This function performs a deep copy of the child certificate from the input
structure to the output
structure.
output | [out] The destination child certificate. |
input | [in, const] The source child certificate. |
MPDC_EXPORT_API void mpdc_certificate_child_create | ( | mpdc_child_certificate * | child, |
const uint8_t * | pubkey, | ||
const mpdc_certificate_expiration * | expiration, | ||
const char * | issuer, | ||
mpdc_network_designations | designation ) |
Create a child certificate.
This function initializes and populates a child certificate structure with the provided public key, expiration information, issuer string, and designation.
child | [out] A pointer to the empty child certificate to populate. |
pubkey | [in] A pointer to the public signature key. |
expiration | [in, const] The certificate expiration time structure. |
issuer | [in, const] The certificate issuer string. |
designation | The certificate designation type (e.g. agent, client, etc.). |
MPDC_EXPORT_API bool mpdc_certificate_child_decode | ( | mpdc_child_certificate * | child, |
const char | enck[MPDC_CHILD_CERTIFICATE_STRING_SIZE] ) |
Decode a child certificate string into a certificate structure.
This function decodes an encoded child certificate string (with a fixed maximum size) into its corresponding certificate structure.
child | [out] The pointer to the child certificate structure to populate. |
enck | [in] The encoded certificate string. |
MPDC_EXPORT_API void mpdc_certificate_child_deserialize | ( | mpdc_child_certificate * | child, |
const uint8_t * | input ) |
Deserialize a child certificate from a byte array.
This function converts a serialized child certificate (stored as a byte stream) into a certificate structure.
child | [out] The pointer to the child certificate structure to populate. |
input | [in, const] The input byte array containing the serialized certificate. |
MPDC_EXPORT_API size_t mpdc_certificate_child_encode | ( | char | enck[MPDC_CHILD_CERTIFICATE_STRING_SIZE], |
const mpdc_child_certificate * | child ) |
Encode a public child certificate into a human-readable string.
This function encodes the given child certificate into a formatted string representation.
enck | [out] The output buffer that will receive the encoded certificate string. |
child | [in, const] The child certificate to encode. |
MPDC_EXPORT_API void mpdc_certificate_child_erase | ( | mpdc_child_certificate * | child | ) |
Delete (erase) a child certificate.
This function securely erases all fields of a child certificate structure.
child | [in,out] A pointer to the child certificate to erase. |
MPDC_EXPORT_API bool mpdc_certificate_child_file_to_struct | ( | const char * | fpath, |
mpdc_child_certificate * | child ) |
Copy a serialized certificate from a file into a child certificate structure.
This function reads a file containing a serialized child certificate, deserializes it, and populates the provided certificate structure.
fpath | [in, const] The file path from which to load the certificate. |
child | [out] A pointer to the child certificate structure. |
MPDC_EXPORT_API void mpdc_certificate_child_hash | ( | uint8_t * | output, |
const mpdc_child_certificate * | child ) |
Compute the cryptographic hash of a child certificate.
The hash is computed over key fields such as algorithm, designation, version, expiration, issuer, serial, and public verification key.
output | [out] The output hash array (size: MPDC_CERTIFICATE_HASH_SIZE). |
child | [in, const] A pointer to the child certificate. |
MPDC_EXPORT_API bool mpdc_certificate_child_is_valid | ( | const mpdc_child_certificate * | child | ) |
Test a child certificate for a valid format and expiration.
This function checks that the certificate fields (including algorithm, designation, version, signature, serial, and public key) are nonzero and that the current time is within the expiration period.
child | [in, const] A pointer to the child certificate. |
MPDC_EXPORT_API bool mpdc_certificate_child_message_verify | ( | uint8_t * | message, |
size_t * | msglen, | ||
const uint8_t * | signature, | ||
size_t | siglen, | ||
const mpdc_child_certificate * | child ) |
Verify a message signature using a child certificate.
This function uses the public verification key from the child certificate to verify that a given signature correctly authenticates a message.
message | [out] The output buffer for the recovered message (if applicable). |
msglen | [in,out] A pointer to the length of the recovered message. |
signature | [in, const] A pointer to the signature. |
siglen | The length of the signature. |
child | [in, const] A pointer to the child certificate. |
MPDC_EXPORT_API void mpdc_certificate_child_serialize | ( | uint8_t * | output, |
const mpdc_child_certificate * | child ) |
Serialize a child certificate into a contiguous byte array.
output | [out] A pointer to the array receiving the serialized certificate (size: MPDC_CERTIFICATE_CHILD_SIZE). |
child | [in, const] The child certificate to serialize. |
MPDC_EXPORT_API bool mpdc_certificate_child_struct_to_file | ( | const char * | fpath, |
const mpdc_child_certificate * | child ) |
Write a child certificate structure to a file.
fpath | [in, const] The file path where the certificate will be stored. |
child | [in, const] A pointer to the child certificate structure. |
MPDC_EXPORT_API mpdc_network_designations mpdc_certificate_designation_decode | ( | const char * | sdsg | ) |
Decode the network-designation string to its enumerated representation.
sdsg | [in, const] The network-designation string. |
MPDC_EXPORT_API size_t mpdc_certificate_designation_encode | ( | char * | sdsg, |
mpdc_network_designations | designation ) |
Encode the network-designation enumerator into a string.
sdsg | [out] The output buffer that will receive the encoded network-designation string. |
designation | The certificate designation type. |
MPDC_EXPORT_API void mpdc_certificate_expiration_set_days | ( | mpdc_certificate_expiration * | expiration, |
uint16_t | start, | ||
uint16_t | duration ) |
Set the expiration days on a certificate expiration structure.
This function sets the from
and to
fields of the expiration structure using day intervals.
expiration | [in,out] A pointer to the expiration structure. |
start | The number of days until the certificate becomes valid. |
duration | The number of days the certificate remains valid. |
MPDC_EXPORT_API void mpdc_certificate_expiration_set_seconds | ( | mpdc_certificate_expiration * | expiration, |
uint64_t | start, | ||
uint64_t | period ) |
Set the expiration seconds on a certificate expiration structure.
expiration | [in,out] A pointer to the expiration structure. |
start | The number of seconds to delay before the certificate becomes valid. |
period | The number of seconds the certificate remains valid. |
MPDC_EXPORT_API bool mpdc_certificate_expiration_time_verify | ( | const mpdc_certificate_expiration * | expiration | ) |
Verify the expiration time against the current UTC time.
expiration | [in, const] A pointer to the expiration time structure. |
MPDC_EXPORT_API size_t mpdc_certificate_message_hash_sign | ( | uint8_t * | signature, |
const uint8_t * | sigkey, | ||
const uint8_t * | message, | ||
size_t | msglen ) |
Hash a message and sign the hash.
This function computes the SHA3-256 hash of the provided message and then signs that hash using the given private signature key.
signature | [out] The array receiving the signature (size: MPDC_ASYMMETRIC_SIGNATURE_SIZE). |
sigkey | [in, const] The private signature key. |
message | [in, const] The message to sign. |
msglen | The length of the message. |
MPDC_EXPORT_API bool mpdc_certificate_root_compare | ( | const mpdc_root_certificate * | a, |
const mpdc_root_certificate * | b ) |
Compare two root certificates for equivalence.
This function compares the key fields of two root certificates to determine if they are equal.
a | [in, const] The first root certificate. |
b | [in, const] The second root certificate. |
MPDC_EXPORT_API void mpdc_certificate_root_create | ( | mpdc_root_certificate * | root, |
const uint8_t * | pubkey, | ||
const mpdc_certificate_expiration * | expiration, | ||
const char * | issuer ) |
Create a root certificate.
This function creates a root certificate by populating its fields with the provided public key, expiration structure, and issuer name. The generated certificate serves as the trust anchor.
root | [out] A pointer to the empty root certificate to populate. |
pubkey | [in] A pointer to the public signature key. |
expiration | [in, const] The certificate expiration time structure. |
issuer | [in, const] The issuer name string. |
MPDC_EXPORT_API bool mpdc_certificate_root_decode | ( | mpdc_root_certificate * | root, |
const char * | enck ) |
Decode a root certificate string into a certificate structure.
This function decodes an encoded root certificate string into its corresponding root certificate structure.
root | [out] The pointer to the root certificate structure to populate. |
enck | [in, const] The encoded certificate string. |
MPDC_EXPORT_API void mpdc_certificate_root_deserialize | ( | mpdc_root_certificate * | root, |
const uint8_t * | input ) |
Deserialize a root certificate from a byte array.
root | [out] A pointer to the root certificate structure to populate. |
input | [in, const] A pointer to the input byte array (size: MPDC_CERTIFICATE_ROOT_SIZE). |
MPDC_EXPORT_API size_t mpdc_certificate_root_encode | ( | char * | enck, |
const mpdc_root_certificate * | root ) |
Encode a public root certificate into a human-readable string.
This function encodes the given root certificate into a formatted string.
enck | [out] The output buffer that will receive the encoded certificate string. |
root | [in, const] The root certificate to encode. |
MPDC_EXPORT_API void mpdc_certificate_root_erase | ( | mpdc_root_certificate * | root | ) |
Delete (erase) a root certificate.
This function securely erases all fields of a root certificate structure.
root | [in,out] A pointer to the root certificate to erase. |
MPDC_EXPORT_API bool mpdc_certificate_root_file_to_struct | ( | const char * | fpath, |
mpdc_root_certificate * | root ) |
Copy a serialized root certificate from a file into a root certificate structure.
fpath | [in, const] The file path from which to read the certificate. |
root | [out] A pointer to the root certificate structure to populate. |
MPDC_EXPORT_API void mpdc_certificate_root_hash | ( | uint8_t * | output, |
const mpdc_root_certificate * | root ) |
Compute the cryptographic hash of a root certificate.
The hash is computed over key fields such as algorithm, version, expiration times, issuer, serial, and public key.
output | [out] The output hash array. |
root | [in, const] A pointer to the root certificate. |
MPDC_EXPORT_API bool mpdc_certificate_root_is_valid | ( | const mpdc_root_certificate * | root | ) |
Validate a root certificate.
This function checks that the root certificate fields are nonzero and that the current time is within its expiration period.
root | [in, const] A pointer to the root certificate. |
MPDC_EXPORT_API void mpdc_certificate_root_serialize | ( | uint8_t * | output, |
const mpdc_root_certificate * | root ) |
Serialize a root certificate into a contiguous byte array.
output | [out] A pointer to the array receiving the serialized certificate (size: MPDC_CERTIFICATE_ROOT_SIZE). |
root | [in, const] The root certificate to serialize. |
MPDC_EXPORT_API size_t mpdc_certificate_root_sign | ( | mpdc_child_certificate * | child, |
const mpdc_root_certificate * | root, | ||
const uint8_t * | rsigkey ) |
Sign a child certificate with the root certificate.
This function hashes the child certificate, copies the root certificate serial number into the child, and then produces a digital signature over the child certificate hash using the provided root signing key.
child | [in,out] A pointer to the child certificate to sign. |
root | [in, const] A pointer to the root certificate. |
rsigkey | [in, const] A pointer to the root private signing key. |
MPDC_EXPORT_API bool mpdc_certificate_root_signature_verify | ( | const mpdc_child_certificate * | child, |
const mpdc_root_certificate * | root ) |
Verify a child certificate against a root certificate.
This function verifies that the digital signature on the child certificate (stored in its signed hash) was produced by the given root certificate.
child | [in, const] A pointer to the child certificate. |
root | [in, const] A pointer to the root certificate. |
MPDC_EXPORT_API bool mpdc_certificate_root_struct_to_file | ( | const char * | fpath, |
const mpdc_root_certificate * | root ) |
Write a root certificate structure to a file.
fpath | [in, const] The file path where the certificate will be written. |
root | [in, const] A pointer to the root certificate structure. |
MPDC_EXPORT_API void mpdc_certificate_signature_generate_keypair | ( | mpdc_signature_keypair * | keypair | ) |
Generate and encode an asymmetric signature scheme keypair.
This function generates a new keypair for the MPDC asymmetric signature scheme and populates the provided keypair container.
keypair | [out] A pointer to the keypair container. |
MPDC_EXPORT_API bool mpdc_certificate_signature_hash_verify | ( | const uint8_t * | signature, |
size_t | siglen, | ||
const uint8_t * | message, | ||
size_t | msglen, | ||
const mpdc_child_certificate * | lcert ) |
Verify that a signature hash matches a computed message hash using a child certificate.
This function first verifies the signature using the child certificate's public key and then compares the resulting hash to an independently computed hash of the message.
signature | [in, const] A pointer to the signed hash. |
siglen | The length of the signed hash. |
message | [in, const] A pointer to the message. |
msglen | The length of the message. |
lcert | [in, const] A pointer to the child certificate used for verification. |
MPDC_EXPORT_API size_t mpdc_certificate_signature_sign_message | ( | uint8_t * | signature, |
const uint8_t * | message, | ||
size_t | msglen, | ||
const uint8_t * | prikey ) |
Sign a message using the asymmetric signature scheme.
signature | [out] The array that will receive the signature (size: MPDC_ASYMMETRIC_SIGNATURE_SIZE). |
message | [in, const] The message to sign. |
msglen | The length of the message. |
prikey | [in] The private signature key. |
MPDC_EXPORT_API bool mpdc_certificate_signature_verify_message | ( | const uint8_t * | message, |
size_t | msglen, | ||
const uint8_t * | signature, | ||
size_t | siglen, | ||
const uint8_t * | pubkey ) |
Verify a message signature using the asymmetric signature scheme.
message | [in, const] The original message. |
msglen | The length of the message. |
signature | [in, const] The signature to verify. |
siglen | The length of the signature. |
pubkey | [in] The public signature verification key. |