Leancrypto 1.7.2
Post-Quantum Cryptographic Library
lc_x509_generator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 - 2026, Stephan Mueller <smueller@chronox.de>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef LC_X509_GENERATOR_H
21#define LC_X509_GENERATOR_H
22
23#include "lc_x509_common.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
70int lc_x509_sufficient_size(size_t *avail_datalen, size_t requested_len);
71
93int lc_x509_cert_encode(const struct lc_x509_certificate *x509, uint8_t *data,
94 size_t *avail_datalen);
95
116int lc_x509_sk_encode(const struct lc_x509_key_data *gendata, uint8_t *data,
117 size_t *avail_datalen);
118
129 const struct lc_x509_key_data *keys);
130
141 size_t *siglen, const struct lc_x509_certificate *cert);
142
165int lc_x509_signature_gen(uint8_t *sig_data, size_t *siglen,
166 const struct lc_x509_key_data *keys, const uint8_t *m,
167 size_t mlen, const struct lc_hash *prehash_algo);
168
187int lc_x509_keypair_gen(struct lc_x509_certificate *cert,
188 struct lc_x509_key_data *keys,
189 enum lc_sig_types create_keypair_algo);
190
210int lc_x509_keypair_load(struct lc_x509_certificate *cert,
211 const struct lc_x509_key_data *keys);
212
233int lc_x509_cert_set_signer(struct lc_x509_certificate *signed_x509,
234 const struct lc_x509_key_data *signer_key_data,
235 const struct lc_x509_certificate *signer_x509);
236
250int lc_x509_cert_set_eku(struct lc_x509_certificate *cert, const char *name);
251
261int lc_x509_cert_set_eku_val(struct lc_x509_certificate *cert, uint16_t val);
262
276int lc_x509_cert_set_keyusage(struct lc_x509_certificate *cert,
277 const char *name);
278
288int lc_x509_cert_set_keyusage_val(struct lc_x509_certificate *cert,
289 uint16_t val);
290
305int lc_x509_cert_set_ca(struct lc_x509_certificate *cert);
306
319int lc_x509_cert_set_ca_pathlen(struct lc_x509_certificate *cert,
320 unsigned int ca_pathlen);
321
335int lc_x509_cert_check_issuer_ca(struct lc_x509_certificate *cert);
336
349int lc_x509_cert_set_san_email(struct lc_x509_certificate *cert,
350 const char *san_email_name);
351
364int lc_x509_cert_set_san_dns(struct lc_x509_certificate *cert,
365 const char *san_dns_name);
366
380int lc_x509_cert_set_san_ip(struct lc_x509_certificate *cert,
381 const uint8_t *san_ip, size_t san_ip_len);
382
399int lc_x509_cert_set_skid(struct lc_x509_certificate *cert, const uint8_t *skid,
400 size_t skidlen);
401
420int lc_x509_cert_set_akid(struct lc_x509_certificate *cert, const uint8_t *akid,
421 size_t akidlen);
422
432int lc_x509_cert_set_valid_from(struct lc_x509_certificate *cert,
433 time64_t time_since_epoch);
434
444int lc_x509_cert_set_valid_to(struct lc_x509_certificate *cert,
445 time64_t time_since_epoch);
446
464int lc_x509_cert_set_subject_cn(struct lc_x509_certificate *cert,
465 const char *string, size_t len);
466
484int lc_x509_cert_set_subject_email(struct lc_x509_certificate *cert,
485 const char *string, size_t len);
486
504int lc_x509_cert_set_subject_ou(struct lc_x509_certificate *cert,
505 const char *string, size_t len);
506
524int lc_x509_cert_set_subject_o(struct lc_x509_certificate *cert,
525 const char *string, size_t len);
526
544int lc_x509_cert_set_subject_st(struct lc_x509_certificate *cert,
545 const char *string, size_t len);
546
564int lc_x509_cert_set_subject_c(struct lc_x509_certificate *cert,
565 const char *string, size_t len);
566
584int lc_x509_cert_set_issuer_cn(struct lc_x509_certificate *cert,
585 const char *string, size_t len);
586
604int lc_x509_cert_set_issuer_email(struct lc_x509_certificate *cert,
605 const char *string, size_t len);
606
624int lc_x509_cert_set_issuer_ou(struct lc_x509_certificate *cert,
625 const char *string, size_t len);
626
644int lc_x509_cert_set_issuer_o(struct lc_x509_certificate *cert,
645 const char *string, size_t len);
646
664int lc_x509_cert_set_issuer_st(struct lc_x509_certificate *cert,
665 const char *string, size_t len);
666
684int lc_x509_cert_set_issuer_c(struct lc_x509_certificate *cert,
685 const char *string, size_t len);
686
700int lc_x509_cert_set_serial(struct lc_x509_certificate *cert,
701 const uint8_t *serial, size_t serial_len);
702
716 enum lc_sig_types *pkey_algo);
717
730int lc_x509_name_to_hash(const char *hash_name,
731 const struct lc_hash **hash_algo);
732
743int lc_x509_hash_to_name(const struct lc_hash *hash_algo,
744 const char **hash_name);
758int lc_x509_name_to_keyusage(const char *name, uint16_t *keyusage);
759
773int lc_x509_name_to_eku(const char *name, uint16_t *eku);
774
784int lc_x509_hash_to_oid(const struct lc_hash *hash_algo, enum OID *oid);
785
786#ifdef __cplusplus
787}
788#endif
789
790#endif /* LC_X509_GENERATOR_H */
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
int lc_x509_cert_set_eku(struct lc_x509_certificate *cert, const char *name)
Set the extended key usage from human readable form.
int lc_x509_pkey_name_to_algorithm(const char *name, enum lc_sig_types *pkey_algo)
Helper to convert the human readable name of a public key algorithm to its internal representation.
int lc_x509_cert_set_issuer_st(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer ST field tp the certificate.
int lc_x509_cert_set_valid_to(struct lc_x509_certificate *cert, time64_t time_since_epoch)
Set the valid-to data to the certificate.
int lc_x509_cert_set_issuer_email(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer email field tp the certificate.
int lc_x509_cert_set_subject_email(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject email field tp the certificate.
int lc_x509_cert_set_subject_cn(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject CN field tp the certificate.
int lc_x509_sufficient_size(size_t *avail_datalen, size_t requested_len)
Helper function for checking available buffer space.
int lc_x509_cert_set_akid(struct lc_x509_certificate *cert, const uint8_t *akid, size_t akidlen)
Set the AKID value.
int lc_x509_cert_set_skid(struct lc_x509_certificate *cert, const uint8_t *skid, size_t skidlen)
Set the SKID value.
int lc_x509_keypair_load(struct lc_x509_certificate *cert, const struct lc_x509_key_data *keys)
Load key pair it to the X.509 certificate.
int lc_x509_cert_set_issuer_ou(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer OU field tp the certificate.
int lc_x509_sk_encode(const struct lc_x509_key_data *gendata, uint8_t *data, size_t *avail_datalen)
Encode a private key DER structure.
int lc_x509_cert_set_san_email(struct lc_x509_certificate *cert, const char *san_email_name)
Get the Email DNS name.
int lc_x509_signature_gen(uint8_t *sig_data, size_t *siglen, const struct lc_x509_key_data *keys, const uint8_t *m, size_t mlen, const struct lc_hash *prehash_algo)
Generate signature over user-supplied data.
int lc_x509_cert_set_subject_st(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject ST field tp the certificate.
int lc_x509_cert_set_ca(struct lc_x509_certificate *cert)
Mark the certificate to bear the basicConstraint CA.
int lc_x509_hash_to_oid(const struct lc_hash *hash_algo, enum OID *oid)
Helper to convert the a hash reference to an OID.
int lc_x509_hash_to_name(const struct lc_hash *hash_algo, const char **hash_name)
Helper to convert the internal representation of a hash algorithm to its human readable form.
int lc_x509_cert_set_san_ip(struct lc_x509_certificate *cert, const uint8_t *san_ip, size_t san_ip_len)
Get the SAN IP value.
int lc_x509_name_to_hash(const char *hash_name, const struct lc_hash **hash_algo)
Helper to convert the human readable name of a hash algorithm to its internal representation.
int lc_x509_cert_check_issuer_ca(struct lc_x509_certificate *cert)
Check and set issuer to subject for CA.
int lc_x509_cert_set_issuer_c(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer C field tp the certificate.
int lc_x509_cert_set_subject_o(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject O field tp the certificate.
int lc_x509_name_to_eku(const char *name, uint16_t *eku)
Helper to convert the human readable name of a EKU to its internal representation.
int lc_x509_cert_set_issuer_cn(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer CN field tp the certificate.
int lc_x509_cert_set_san_dns(struct lc_x509_certificate *cert, const char *san_dns_name)
Get the SAN DNS name.
int lc_x509_cert_set_serial(struct lc_x509_certificate *cert, const uint8_t *serial, size_t serial_len)
Set the serial number of the certificate.
int lc_x509_get_signature_size_from_sk(size_t *siglen, const struct lc_x509_key_data *keys)
Return signature size derived from private key information.
int lc_x509_cert_set_ca_pathlen(struct lc_x509_certificate *cert, unsigned int ca_pathlen)
Set the path length for the CA certificate.
int lc_x509_cert_set_eku_val(struct lc_x509_certificate *cert, uint16_t val)
Set the extended key usage in integer form.
int lc_x509_cert_set_valid_from(struct lc_x509_certificate *cert, time64_t time_since_epoch)
Set the valid-from data to the certificate.
int lc_x509_name_to_keyusage(const char *name, uint16_t *keyusage)
Helper to convert the human readable name of a keyusage to its internal representation.
int lc_x509_cert_encode(const struct lc_x509_certificate *x509, uint8_t *data, size_t *avail_datalen)
Encode an X.509 certificate.
int lc_x509_keypair_gen(struct lc_x509_certificate *cert, struct lc_x509_key_data *keys, enum lc_sig_types create_keypair_algo)
Generate keypair and set it to the X.509 certificate.
int lc_x509_cert_set_issuer_o(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the issuer O field tp the certificate.
int lc_x509_cert_set_signer(struct lc_x509_certificate *signed_x509, const struct lc_x509_key_data *signer_key_data, const struct lc_x509_certificate *signer_x509)
Set the signer X.509 certificate for a X.509 certificate.
int lc_x509_cert_set_subject_ou(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject OU field tp the certificate.
int lc_x509_get_signature_size_from_cert(size_t *siglen, const struct lc_x509_certificate *cert)
Return signature size derived from certificate information.
int lc_x509_cert_set_keyusage_val(struct lc_x509_certificate *cert, uint16_t val)
Set the key usage in integer form.
int lc_x509_cert_set_keyusage(struct lc_x509_certificate *cert, const char *name)
Set the key usage from human readable form.
int lc_x509_cert_set_subject_c(struct lc_x509_certificate *cert, const char *string, size_t len)
Set the subject C field tp the certificate.
OID
Definition: lc_asn1.h:44