cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

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-2012 Sawtooth Consulting Ltd.
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 };
00045 
00046 
00047 /* Signature type, by OID sum */
00048 enum Ctc_SigType {
00049     CTC_SHAwDSA      = 517,
00050     CTC_MD2wRSA      = 646,
00051     CTC_MD5wRSA      = 648,
00052     CTC_SHAwRSA      = 649,
00053     CTC_SHAwECDSA    = 520,
00054     CTC_SHA256wRSA   = 655,
00055     CTC_SHA256wECDSA = 524,
00056     CTC_SHA384wRSA   = 656,
00057     CTC_SHA384wECDSA = 525,
00058     CTC_SHA512wRSA   = 657,
00059     CTC_SHA512wECDSA = 526
00060 };
00061 
00062 
00063 #ifdef CYASSL_CERT_GEN
00064 
00065 enum Ctc_Misc {
00066     CTC_NAME_SIZE    =   64,
00067     CTC_DATE_SIZE    =   32,
00068     CTC_MAX_ALT_SIZE = 8192,    /* may be huge */
00069     CTC_SERIAL_SIZE  =    8
00070 };
00071 
00072 typedef struct CertName {
00073     char country[CTC_NAME_SIZE];
00074     char state[CTC_NAME_SIZE];
00075     char locality[CTC_NAME_SIZE];
00076     char sur[CTC_NAME_SIZE];
00077     char org[CTC_NAME_SIZE];
00078     char unit[CTC_NAME_SIZE];
00079     char commonName[CTC_NAME_SIZE];
00080     char email[CTC_NAME_SIZE];  /* !!!! email has to be last !!!! */
00081 } CertName;
00082 
00083 
00084 /* for user to fill for certificate generation */
00085 typedef struct Cert {
00086     int      version;                   /* x509 version  */
00087     byte     serial[CTC_SERIAL_SIZE];   /* serial number */
00088     int      sigType;                   /* signature algo type */
00089     CertName issuer;                    /* issuer info */
00090     int      daysValid;                 /* validity days */
00091     int      selfSigned;                /* self signed flag */
00092     CertName subject;                   /* subject info */
00093     int      isCA;                      /* is this going to be a CA */
00094     /* internal use only */
00095     int      bodySz;                    /* pre sign total size */
00096     int      keyType;                   /* public key type of subject */
00097 #ifdef CYASSL_ALT_NAMES
00098     byte     altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
00099     int      altNamesSz;                 /* altNames size in bytes */
00100     byte     beforeDate[CTC_DATE_SIZE];  /* before date copy */
00101     int      beforeDateSz;               /* size of copy */
00102     byte     afterDate[CTC_DATE_SIZE];   /* after date copy */
00103     int      afterDateSz;                /* size of copy */
00104 #endif
00105 } Cert;
00106 
00107 
00108 
00109 
00110 /* Initialize and Set Certficate defaults:
00111    version    = 3 (0x2)
00112    serial     = 0 (Will be randomly generated)
00113    sigType    = SHA_WITH_RSA
00114    issuer     = blank
00115    daysValid  = 500
00116    selfSigned = 1 (true) use subject as issuer
00117    subject    = blank
00118    isCA       = 0 (false)
00119    keyType    = RSA_KEY (default)
00120 */
00121 CYASSL_API void InitCert(Cert*);
00122 CYASSL_API int  MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
00123 CYASSL_API int  SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
00124 CYASSL_API int  MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
00125                              RNG*);
00126 CYASSL_API int  SetIssuer(Cert*, const char*);
00127 CYASSL_API int  SetSubject(Cert*, const char*);
00128 #ifdef CYASSL_ALT_NAMES
00129     CYASSL_API int  SetAltNames(Cert*, const char*);
00130 #endif
00131 CYASSL_API int  SetIssuerBuffer(Cert*, const byte*, int);
00132 CYASSL_API int  SetSubjectBuffer(Cert*, const byte*, int);
00133 CYASSL_API int  SetAltNamesBuffer(Cert*, const byte*, int);
00134 CYASSL_API int  SetDatesBuffer(Cert*, const byte*, int);
00135 
00136     #ifdef HAVE_NTRU
00137         CYASSL_API int  MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
00138                                      const byte* ntruKey, word16 keySz, RNG*);
00139     #endif
00140 
00141 #endif /* CYASSL_CERT_GEN */
00142 
00143 
00144 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
00145     CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
00146                             word32 outputSz, int type);
00147 #endif
00148 
00149 
00150 #ifdef __cplusplus
00151     } /* extern "C" */
00152 #endif
00153 
00154 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */
00155