]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/CyaSSL/cyassl/ctaocrypt/asn_public.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS-Plus / CyaSSL / cyassl / ctaocrypt / asn_public.h
1 /* asn_public.h
2  *
3  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
4  *
5  * This file is part of CyaSSL.
6  *
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.
11  *
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.
16  *
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
20  */
21
22
23 #ifndef CTAO_CRYPT_ASN_PUBLIC_H
24 #define CTAO_CRYPT_ASN_PUBLIC_H
25
26 #include <cyassl/ctaocrypt/types.h>
27 #ifdef CYASSL_CERT_GEN
28     #include <cyassl/ctaocrypt/rsa.h>
29 #endif
30
31
32 #ifdef __cplusplus
33     extern "C" {
34 #endif
35
36
37 /* Certificate file Type */
38 enum CertType {
39     CERT_TYPE       = 0, 
40     PRIVATEKEY_TYPE,
41     DH_PARAM_TYPE,
42     CRL_TYPE,
43     CA_TYPE
44 };
45
46
47 /* Signature type, by OID sum */
48 enum Ctc_SigType {
49     CTC_SHAwDSA      = 517,
50     CTC_MD2wRSA      = 646,
51     CTC_MD5wRSA      = 648,
52     CTC_SHAwRSA      = 649,
53     CTC_SHAwECDSA    = 520,
54     CTC_SHA256wRSA   = 655,
55     CTC_SHA256wECDSA = 524,
56     CTC_SHA384wRSA   = 656,
57     CTC_SHA384wECDSA = 525,
58     CTC_SHA512wRSA   = 657,
59     CTC_SHA512wECDSA = 526
60 };
61
62
63 #ifdef CYASSL_CERT_GEN
64
65 enum Ctc_Misc {
66     CTC_NAME_SIZE    =   64,
67     CTC_DATE_SIZE    =   32,
68     CTC_MAX_ALT_SIZE = 8192,    /* may be huge */
69     CTC_SERIAL_SIZE  =    8
70 };
71
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 !!!! */
81 } CertName;
82
83
84 /* for user to fill for certificate generation */
85 typedef struct Cert {
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 */
104 #endif
105 } Cert;
106
107
108
109
110 /* Initialize and Set Certficate defaults:
111    version    = 3 (0x2)
112    serial     = 0 (Will be randomly generated)
113    sigType    = SHA_WITH_RSA
114    issuer     = blank
115    daysValid  = 500
116    selfSigned = 1 (true) use subject as issuer
117    subject    = blank
118    isCA       = 0 (false)
119    keyType    = RSA_KEY (default)
120 */
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*,
125                              RNG*);
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*);
130 #endif
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);
135
136     #ifdef HAVE_NTRU
137         CYASSL_API int  MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
138                                      const byte* ntruKey, word16 keySz, RNG*);
139     #endif
140
141 #endif /* CYASSL_CERT_GEN */
142
143
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);
147 #endif
148
149
150 #ifdef __cplusplus
151     } /* extern "C" */
152 #endif
153
154 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */
155