Leancrypto 1.6.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_x509_generator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 - 2025, 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
50
72int lc_x509_cert_encode(const struct lc_x509_certificate *x509, uint8_t *data,
73 size_t *avail_datalen);
74
91int lc_x509_sk_encode(const struct lc_x509_key_data *gendata, uint8_t *data,
92 size_t *avail_datalen);
93
104 const struct lc_x509_key_data *keys);
105
116 size_t *siglen, const struct lc_x509_certificate *cert);
117
140int lc_x509_signature_gen(uint8_t *sig_data, size_t *siglen,
141 const struct lc_x509_key_data *keys, const uint8_t *m,
142 size_t mlen, const struct lc_hash *prehash_algo);
143
158int lc_x509_keypair_gen(struct lc_x509_certificate *cert,
159 struct lc_x509_key_data *keys,
160 enum lc_sig_types create_keypair_algo);
161
181int lc_x509_keypair_load(struct lc_x509_certificate *cert,
182 const struct lc_x509_key_data *keys);
183
204int lc_x509_cert_set_signer(struct lc_x509_certificate *signed_x509,
205 const struct lc_x509_key_data *signer_key_data,
206 const struct lc_x509_certificate *signer_x509);
207
221int lc_x509_cert_set_eku(struct lc_x509_certificate *cert, const char *name);
222
232int lc_x509_cert_set_eku_val(struct lc_x509_certificate *cert, uint16_t val);
233
247int lc_x509_cert_set_keyusage(struct lc_x509_certificate *cert,
248 const char *name);
249
259int lc_x509_cert_set_keyusage_val(struct lc_x509_certificate *cert,
260 uint16_t val);
261
276int lc_x509_cert_set_ca(struct lc_x509_certificate *cert);
277
290int lc_x509_cert_set_san_dns(struct lc_x509_certificate *cert,
291 const char *san_dns_name);
292
306int lc_x509_cert_set_san_ip(struct lc_x509_certificate *cert,
307 const uint8_t *san_ip, size_t san_ip_len);
308
320int lc_x509_enc_san_ip(struct lc_x509_certificate *cert, char *ip_name,
321 uint8_t *ip, size_t *ip_len);
322
339int lc_x509_cert_set_skid(struct lc_x509_certificate *cert, const uint8_t *skid,
340 size_t skidlen);
341
360int lc_x509_cert_set_akid(struct lc_x509_certificate *cert, const uint8_t *akid,
361 size_t akidlen);
362
372int lc_x509_cert_set_valid_from(struct lc_x509_certificate *cert,
373 time64_t time_since_epoch);
374
384int lc_x509_cert_set_valid_to(struct lc_x509_certificate *cert,
385 time64_t time_since_epoch);
386
404int lc_x509_cert_set_subject_cn(struct lc_x509_certificate *cert,
405 const char *string, size_t len);
406
424int lc_x509_cert_set_subject_email(struct lc_x509_certificate *cert,
425 const char *string, size_t len);
426
444int lc_x509_cert_set_subject_ou(struct lc_x509_certificate *cert,
445 const char *string, size_t len);
446
464int lc_x509_cert_set_subject_o(struct lc_x509_certificate *cert,
465 const char *string, size_t len);
466
484int lc_x509_cert_set_subject_st(struct lc_x509_certificate *cert,
485 const char *string, size_t len);
486
504int lc_x509_cert_set_subject_c(struct lc_x509_certificate *cert,
505 const char *string, size_t len);
506
524int lc_x509_cert_set_issuer_cn(struct lc_x509_certificate *cert,
525 const char *string, size_t len);
526
544int lc_x509_cert_set_issuer_email(struct lc_x509_certificate *cert,
545 const char *string, size_t len);
546
564int lc_x509_cert_set_issuer_ou(struct lc_x509_certificate *cert,
565 const char *string, size_t len);
566
584int lc_x509_cert_set_issuer_o(struct lc_x509_certificate *cert,
585 const char *string, size_t len);
586
604int lc_x509_cert_set_issuer_st(struct lc_x509_certificate *cert,
605 const char *string, size_t len);
606
624int lc_x509_cert_set_issuer_c(struct lc_x509_certificate *cert,
625 const char *string, size_t len);
626
640int lc_x509_cert_set_serial(struct lc_x509_certificate *cert,
641 const uint8_t *serial, size_t serial_len);
642
656 enum lc_sig_types *pkey_algo);
657
670int lc_x509_name_to_hash(const char *hash_name,
671 const struct lc_hash **hash_algo);
672
683int lc_x509_hash_to_name(const struct lc_hash *hash_algo,
684 const char **hash_name);
698int lc_x509_name_to_keyusage(const char *name, uint16_t *keyusage);
699
713int lc_x509_name_to_eku(const char *name, uint16_t *eku);
714
715#ifdef __cplusplus
716}
717#endif
718
719#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_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_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_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_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_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_enc_san_ip(struct lc_x509_certificate *cert, char *ip_name, uint8_t *ip, size_t *ip_len)
Helper to convert the human IP address value into binary form.
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.