x509_cert_create.h
Go to the documentation of this file.
1 /**
2  * @file x509_cert_create.h
3  * @brief X.509 certificate generation
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCrypto Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _X509_CERT_CREATE_H
32 #define _X509_CERT_CREATE_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_common.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 //X.509 related functions
44 error_t x509CreateCertificate(const PrngAlgo *prngAlgo, void *prngContext,
45  const X509CertRequestInfo *certReqInfo, const void *subjectPublicKey,
46  const X509CertificateInfo *issuerCertInfo, const X509SerialNumber *serialNumber,
47  const X509Validity *validity, const X509SignatureAlgoId *signatureAlgo,
48  const void *signerPrivateKey, uint8_t *output, size_t *written);
49 
50 error_t x509FormatTbsCertificate(const PrngAlgo *prngAlgo, void *prngContext,
51  const X509SerialNumber *serialNumber, const X509SignatureAlgoId *signatureAlgo,
52  const X509Name *issuer, const X509Validity *validity, const X509Name *subject,
53  const X509SubjectPublicKeyInfo *subjectPublicKeyInfo, const void *publicKey,
54  const X509Extensions *extensions, const X509AuthorityKeyId *authKeyId,
55  uint8_t *output, size_t *written);
56 
58  size_t *written);
59 
60 error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext,
61  const X509SerialNumber *serialNumber, uint8_t *output, size_t *written);
62 
63 error_t x509FormatName(const X509Name *name, uint8_t *output,
64  size_t *written);
65 
66 error_t x509FormatNameAttribute(uint_t type, const uint8_t *oid, size_t oidLen,
67  const char_t *value, size_t valueLen, uint8_t *output, size_t *written);
68 
69 error_t x509FormatValidity(const X509Validity *validity, uint8_t *output,
70  size_t *written);
71 
72 error_t x509FormatTime(const DateTime *dateTime, uint8_t *output,
73  size_t *written);
74 
76  const X509SubjectKeyId *subjectKeyId, const X509AuthorityKeyId *authKeyId,
77  uint8_t *output, size_t *written);
78 
80  uint8_t *output, size_t *written);
81 
82 error_t x509FormatKeyUsage(const X509KeyUsage *keyUsage, uint8_t *output,
83  size_t *written);
84 
86  uint8_t *output, size_t *written);
87 
89  uint8_t *output, size_t *written);
90 
92  uint8_t *output, size_t *written);
93 
95  uint8_t *output, size_t *written);
96 
98  uint8_t *output, size_t *written);
99 
100 error_t x509FormatSignatureValue(const PrngAlgo *prngAlgo, void *prngContext,
101  const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId,
102  const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey,
103  uint8_t *output, size_t *written);
104 
105 error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
106  const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId,
107  const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey,
108  uint8_t *output, size_t *written);
109 
110 //C++ guard
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif
error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
Format Name structure.
X.509 common definitions.
Common interface for pseudo-random number generators.
Definition: crypto.h:1168
Signature algorithm identifier.
Definition: x509_common.h:876
Validity.
Definition: x509_common.h:622
X.509 certificate.
Definition: x509_common.h:920
uint16_t version
Definition: dtls_misc.h:172
error_t x509FormatSignatureAlgo(const X509SignatureAlgoId *signatureAlgo, uint8_t *output, size_t *written)
Format SignatureAlgorithm structure.
char_t name[]
Subject key identifier.
Definition: x509_common.h:792
error_t x509FormatSignatureValue(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey, uint8_t *output, size_t *written)
Format SignatureValue field.
error_t x509FormatSubjectAltName(const X509SubjectAltName *subjectAltName, uint8_t *output, size_t *written)
Format SubjectAltName extension.
error_t x509FormatValidity(const X509Validity *validity, uint8_t *output, size_t *written)
Format Validity structure.
error_t x509CreateCertificate(const PrngAlgo *prngAlgo, void *prngContext, const X509CertRequestInfo *certReqInfo, const void *subjectPublicKey, const X509CertificateInfo *issuerCertInfo, const X509SerialNumber *serialNumber, const X509Validity *validity, const X509SignatureAlgoId *signatureAlgo, const void *signerPrivateKey, uint8_t *output, size_t *written)
Generate a X.509 certificate.
char_t type
error_t
Error codes.
Definition: error.h:42
error_t x509FormatNameAttribute(uint_t type, const uint8_t *oid, size_t oidLen, const char_t *value, size_t valueLen, uint8_t *output, size_t *written)
Format Name attribute.
error_t x509FormatKeyUsage(const X509KeyUsage *keyUsage, uint8_t *output, size_t *written)
Format KeyUsage extension.
X509Version
X.509 versions.
Definition: x509_common.h:390
error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext, const X509SerialNumber *serialNumber, uint8_t *output, size_t *written)
Format SerialNumber field.
General definitions for cryptographic algorithms.
uint8_t oid[1]
Definition: mib_common.h:186
error_t x509FormatNsCertType(const X509NsCertType *nsCertType, uint8_t *output, size_t *written)
Format NetscapeCertType extension.
Date and time representation.
Definition: date_time.h:46
CertificationRequestInfo structure.
Definition: x509_common.h:1131
Subject alternative name.
Definition: x509_common.h:778
Netscape certificate type.
Definition: x509_common.h:816
char char_t
Definition: compiler_port.h:43
error_t x509FormatBasicConstraints(const X509BasicConstraints *basicConstraints, uint8_t *output, size_t *written)
Format BasicConstraints extension.
Issuer or subject name.
Definition: x509_common.h:568
uint8_t extensions[]
Definition: tls13_misc.h:327
Subject public key information.
Definition: x509_common.h:694
error_t x509FormatTime(const DateTime *dateTime, uint8_t *output, size_t *written)
Format UTCTime or GeneralizedTime field.
error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *tbsCert, size_t tbsCertLen, const X509SignatureAlgoId *signatureAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const void *privateKey, uint8_t *output, size_t *written)
Certificate signature generation.
error_t x509FormatExtensions(const X509Extensions *extensions, const X509SubjectKeyId *subjectKeyId, const X509AuthorityKeyId *authKeyId, uint8_t *output, size_t *written)
Format Extensions structure.
Basic constraints.
Definition: x509_common.h:718
error_t x509FormatAuthorityKeyId(const X509AuthorityKeyId *authKeyId, uint8_t *output, size_t *written)
Format AuthorityKeyIdentifier extension.
X.509 certificate extensions.
Definition: x509_common.h:841
Serial number.
Definition: x509_common.h:557
uint8_t value[]
Definition: dtls_misc.h:150
unsigned int uint_t
Definition: compiler_port.h:45
error_t x509FormatVersion(X509Version version, uint8_t *output, size_t *written)
Format Version field.
error_t x509FormatSubjectKeyId(const X509SubjectKeyId *subjectKeyId, uint8_t *output, size_t *written)
Format SubjectKeyIdentifier extension.
Authority key identifier.
Definition: x509_common.h:804
error_t x509FormatTbsCertificate(const PrngAlgo *prngAlgo, void *prngContext, const X509SerialNumber *serialNumber, const X509SignatureAlgoId *signatureAlgo, const X509Name *issuer, const X509Validity *validity, const X509Name *subject, const X509SubjectPublicKeyInfo *subjectPublicKeyInfo, const void *publicKey, const X509Extensions *extensions, const X509AuthorityKeyId *authKeyId, uint8_t *output, size_t *written)
Format TBSCertificate structure.
Key usage.
Definition: x509_common.h:744