3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
5 * This file is part of CyaSSL.
7 * CyaSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * CyaSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 #ifndef CTAO_CRYPT_ASN_PUBLIC_H
24 #define CTAO_CRYPT_ASN_PUBLIC_H
26 #include <cyassl/ctaocrypt/types.h>
27 #ifdef CYASSL_CERT_GEN
28 #include <cyassl/ctaocrypt/rsa.h>
37 /* Certificate file Type */
47 /* Signature type, by OID sum */
55 CTC_SHA256wECDSA = 524,
57 CTC_SHA384wECDSA = 525,
59 CTC_SHA512wECDSA = 526
63 #ifdef CYASSL_CERT_GEN
68 CTC_MAX_ALT_SIZE = 8192, /* may be huge */
72 typedef struct CertName {
73 char country[CTC_NAME_SIZE];
74 char state[CTC_NAME_SIZE];
75 char locality[CTC_NAME_SIZE];
76 char sur[CTC_NAME_SIZE];
77 char org[CTC_NAME_SIZE];
78 char unit[CTC_NAME_SIZE];
79 char commonName[CTC_NAME_SIZE];
80 char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
84 /* for user to fill for certificate generation */
86 int version; /* x509 version */
87 byte serial[CTC_SERIAL_SIZE]; /* serial number */
88 int sigType; /* signature algo type */
89 CertName issuer; /* issuer info */
90 int daysValid; /* validity days */
91 int selfSigned; /* self signed flag */
92 CertName subject; /* subject info */
93 int isCA; /* is this going to be a CA */
94 /* internal use only */
95 int bodySz; /* pre sign total size */
96 int keyType; /* public key type of subject */
97 #ifdef CYASSL_ALT_NAMES
98 byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
99 int altNamesSz; /* altNames size in bytes */
100 byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
101 int beforeDateSz; /* size of copy */
102 byte afterDate[CTC_DATE_SIZE]; /* after date copy */
103 int afterDateSz; /* size of copy */
110 /* Initialize and Set Certficate defaults:
112 serial = 0 (Will be randomly generated)
113 sigType = SHA_WITH_RSA
116 selfSigned = 1 (true) use subject as issuer
119 keyType = RSA_KEY (default)
121 CYASSL_API void InitCert(Cert*);
122 CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
123 CYASSL_API int SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
124 CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
126 CYASSL_API int SetIssuer(Cert*, const char*);
127 CYASSL_API int SetSubject(Cert*, const char*);
128 #ifdef CYASSL_ALT_NAMES
129 CYASSL_API int SetAltNames(Cert*, const char*);
131 CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int);
132 CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int);
133 CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int);
134 CYASSL_API int SetDatesBuffer(Cert*, const byte*, int);
137 CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
138 const byte* ntruKey, word16 keySz, RNG*);
141 #endif /* CYASSL_CERT_GEN */
144 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
145 CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
146 word32 outputSz, int type);
154 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */