This is a port of cyaSSL 2.7.0.

Dependents:   CyaSSL_DTLS_Cellular CyaSSL_DTLS_Ethernet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers asn_public.h Source File

asn_public.h

00001 /* asn_public.h
00002  *
00003  * Copyright (C) 2006-2013 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 
00023 #ifndef CTAO_CRYPT_ASN_PUBLIC_H
00024 #define CTAO_CRYPT_ASN_PUBLIC_H
00025 
00026 #include <cyassl/ctaocrypt/types.h>
00027 #ifdef CYASSL_CERT_GEN
00028     #include <cyassl/ctaocrypt/rsa.h>
00029 #endif
00030 
00031 
00032 #ifdef __cplusplus
00033     extern "C" {
00034 #endif
00035 
00036 
00037 /* Certificate file Type */
00038 enum CertType {
00039     CERT_TYPE       = 0, 
00040     PRIVATEKEY_TYPE,
00041     DH_PARAM_TYPE,
00042     CRL_TYPE,
00043     CA_TYPE,
00044     ECC_PRIVATEKEY_TYPE
00045 };
00046 
00047 
00048 /* Signature type, by OID sum */
00049 enum Ctc_SigType {
00050     CTC_SHAwDSA      = 517,
00051     CTC_MD2wRSA      = 646,
00052     CTC_MD5wRSA      = 648,
00053     CTC_SHAwRSA      = 649,
00054     CTC_SHAwECDSA    = 520,
00055     CTC_SHA256wRSA   = 655,
00056     CTC_SHA256wECDSA = 524,
00057     CTC_SHA384wRSA   = 656,
00058     CTC_SHA384wECDSA = 525,
00059     CTC_SHA512wRSA   = 657,
00060     CTC_SHA512wECDSA = 526
00061 };
00062 
00063 
00064 #ifdef CYASSL_CERT_GEN
00065 
00066 enum Ctc_Misc {
00067     CTC_NAME_SIZE    =   64,
00068     CTC_DATE_SIZE    =   32,
00069     CTC_MAX_ALT_SIZE = 8192,    /* may be huge */
00070     CTC_SERIAL_SIZE  =    8
00071 };
00072 
00073 typedef struct CertName {
00074     char country[CTC_NAME_SIZE];
00075     char state[CTC_NAME_SIZE];
00076     char locality[CTC_NAME_SIZE];
00077     char sur[CTC_NAME_SIZE];
00078     char org[CTC_NAME_SIZE];
00079     char unit[CTC_NAME_SIZE];
00080     char commonName[CTC_NAME_SIZE];
00081     char email[CTC_NAME_SIZE];  /* !!!! email has to be last !!!! */
00082 } CertName;
00083 
00084 
00085 /* for user to fill for certificate generation */
00086 typedef struct Cert {
00087     int      version;                   /* x509 version  */
00088     byte     serial[CTC_SERIAL_SIZE];   /* serial number */
00089     int      sigType;                   /* signature algo type */
00090     CertName issuer;                    /* issuer info */
00091     int      daysValid;                 /* validity days */
00092     int      selfSigned;                /* self signed flag */
00093     CertName subject;                   /* subject info */
00094     int      isCA;                      /* is this going to be a CA */
00095     /* internal use only */
00096     int      bodySz;                    /* pre sign total size */
00097     int      keyType;                   /* public key type of subject */
00098 #ifdef CYASSL_ALT_NAMES
00099     byte     altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
00100     int      altNamesSz;                 /* altNames size in bytes */
00101     byte     beforeDate[CTC_DATE_SIZE];  /* before date copy */
00102     int      beforeDateSz;               /* size of copy */
00103     byte     afterDate[CTC_DATE_SIZE];   /* after date copy */
00104     int      afterDateSz;                /* size of copy */
00105 #endif
00106 } Cert;
00107 
00108 
00109 
00110 
00111 /* Initialize and Set Certficate defaults:
00112    version    = 3 (0x2)
00113    serial     = 0 (Will be randomly generated)
00114    sigType    = SHA_WITH_RSA
00115    issuer     = blank
00116    daysValid  = 500
00117    selfSigned = 1 (true) use subject as issuer
00118    subject    = blank
00119    isCA       = 0 (false)
00120    keyType    = RSA_KEY (default)
00121 */
00122 CYASSL_API void InitCert(Cert*);
00123 CYASSL_API int  MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
00124 CYASSL_API int  SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
00125 CYASSL_API int  MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
00126                              RNG*);
00127 CYASSL_API int  SetIssuer(Cert*, const char*);
00128 CYASSL_API int  SetSubject(Cert*, const char*);
00129 #ifdef CYASSL_ALT_NAMES
00130     CYASSL_API int  SetAltNames(Cert*, const char*);
00131 #endif
00132 CYASSL_API int  SetIssuerBuffer(Cert*, const byte*, int);
00133 CYASSL_API int  SetSubjectBuffer(Cert*, const byte*, int);
00134 CYASSL_API int  SetAltNamesBuffer(Cert*, const byte*, int);
00135 CYASSL_API int  SetDatesBuffer(Cert*, const byte*, int);
00136 
00137     #ifdef HAVE_NTRU
00138         CYASSL_API int  MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
00139                                      const byte* ntruKey, word16 keySz, RNG*);
00140     #endif
00141 
00142 #endif /* CYASSL_CERT_GEN */
00143 
00144 
00145 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
00146     CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
00147                             word32 outputSz, int type);
00148 #endif
00149 
00150 
00151 #ifdef __cplusplus
00152     } /* extern "C" */
00153 #endif
00154 
00155 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */
00156