Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL
asn_public.h
00001 /* asn_public.h 00002 * 00003 * Copyright (C) 2006-2014 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include <cyassl/ctaocrypt/ecc.h> 00028 #ifdef CYASSL_CERT_GEN 00029 #include <cyassl/ctaocrypt/rsa.h> 00030 #endif 00031 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif 00036 00037 00038 /* Certificate file Type */ 00039 enum CertType { 00040 CERT_TYPE = 0, 00041 PRIVATEKEY_TYPE, 00042 DH_PARAM_TYPE, 00043 CRL_TYPE, 00044 CA_TYPE, 00045 ECC_PRIVATEKEY_TYPE, 00046 CERTREQ_TYPE 00047 }; 00048 00049 00050 /* Signature type, by OID sum */ 00051 enum Ctc_SigType { 00052 CTC_SHAwDSA = 517, 00053 CTC_MD2wRSA = 646, 00054 CTC_MD5wRSA = 648, 00055 CTC_SHAwRSA = 649, 00056 CTC_SHAwECDSA = 520, 00057 CTC_SHA256wRSA = 655, 00058 CTC_SHA256wECDSA = 524, 00059 CTC_SHA384wRSA = 656, 00060 CTC_SHA384wECDSA = 525, 00061 CTC_SHA512wRSA = 657, 00062 CTC_SHA512wECDSA = 526 00063 }; 00064 00065 enum Ctc_Encoding { 00066 CTC_UTF8 = 0x0c, /* utf8 */ 00067 CTC_PRINTABLE = 0x13 /* printable */ 00068 }; 00069 00070 00071 #ifdef CYASSL_CERT_GEN 00072 00073 #ifndef HAVE_ECC 00074 typedef struct ecc_key ecc_key; 00075 #endif 00076 00077 enum Ctc_Misc { 00078 CTC_NAME_SIZE = 64, 00079 CTC_DATE_SIZE = 32, 00080 CTC_MAX_ALT_SIZE = 16384, /* may be huge */ 00081 CTC_SERIAL_SIZE = 8 00082 }; 00083 00084 typedef struct CertName { 00085 char country[CTC_NAME_SIZE]; 00086 char countryEnc; 00087 char state[CTC_NAME_SIZE]; 00088 char stateEnc; 00089 char locality[CTC_NAME_SIZE]; 00090 char localityEnc; 00091 char sur[CTC_NAME_SIZE]; 00092 char surEnc; 00093 char org[CTC_NAME_SIZE]; 00094 char orgEnc; 00095 char unit[CTC_NAME_SIZE]; 00096 char unitEnc; 00097 char commonName[CTC_NAME_SIZE]; 00098 char commonNameEnc; 00099 char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */ 00100 } CertName; 00101 00102 00103 /* for user to fill for certificate generation */ 00104 typedef struct Cert { 00105 int version; /* x509 version */ 00106 byte serial[CTC_SERIAL_SIZE]; /* serial number */ 00107 int sigType; /* signature algo type */ 00108 CertName issuer; /* issuer info */ 00109 int daysValid; /* validity days */ 00110 int selfSigned; /* self signed flag */ 00111 CertName subject; /* subject info */ 00112 int isCA; /* is this going to be a CA */ 00113 /* internal use only */ 00114 int bodySz; /* pre sign total size */ 00115 int keyType; /* public key type of subject */ 00116 #ifdef CYASSL_ALT_NAMES 00117 byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */ 00118 int altNamesSz; /* altNames size in bytes */ 00119 byte beforeDate[CTC_DATE_SIZE]; /* before date copy */ 00120 int beforeDateSz; /* size of copy */ 00121 byte afterDate[CTC_DATE_SIZE]; /* after date copy */ 00122 int afterDateSz; /* size of copy */ 00123 #endif 00124 #ifdef CYASSL_CERT_REQ 00125 char challengePw[CTC_NAME_SIZE]; 00126 #endif 00127 } Cert; 00128 00129 00130 00131 00132 /* Initialize and Set Certficate defaults: 00133 version = 3 (0x2) 00134 serial = 0 (Will be randomly generated) 00135 sigType = SHA_WITH_RSA 00136 issuer = blank 00137 daysValid = 500 00138 selfSigned = 1 (true) use subject as issuer 00139 subject = blank 00140 isCA = 0 (false) 00141 keyType = RSA_KEY (default) 00142 */ 00143 CYASSL_API void InitCert(Cert*); 00144 CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00145 ecc_key*, RNG*); 00146 #ifdef CYASSL_CERT_REQ 00147 CYASSL_API int MakeCertReq(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00148 ecc_key*); 00149 #endif 00150 CYASSL_API int SignCert(int requestSz, int sigType, byte* derBuffer, 00151 word32 derSz, RsaKey*, ecc_key*, RNG*); 00152 CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00153 RNG*); 00154 CYASSL_API int SetIssuer(Cert*, const char*); 00155 CYASSL_API int SetSubject(Cert*, const char*); 00156 #ifdef CYASSL_ALT_NAMES 00157 CYASSL_API int SetAltNames(Cert*, const char*); 00158 #endif 00159 CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int); 00160 CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int); 00161 CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int); 00162 CYASSL_API int SetDatesBuffer(Cert*, const byte*, int); 00163 00164 #ifdef HAVE_NTRU 00165 CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz, 00166 const byte* ntruKey, word16 keySz, RNG*); 00167 #endif 00168 00169 #endif /* CYASSL_CERT_GEN */ 00170 00171 00172 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) 00173 CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output, 00174 word32 outputSz, int type); 00175 #endif 00176 00177 #ifdef HAVE_ECC 00178 /* private key helpers */ 00179 CYASSL_API int EccPrivateKeyDecode(const byte* input,word32* inOutIdx, 00180 ecc_key*,word32); 00181 CYASSL_API int EccKeyToDer(ecc_key*, byte* output, word32 inLen); 00182 #endif 00183 00184 /* DER encode signature */ 00185 CYASSL_API word32 EncodeSignature(byte* out, const byte* digest, word32 digSz, 00186 int hashOID); 00187 CYASSL_API int GetCTC_HashOID(int type); 00188 00189 #ifdef __cplusplus 00190 } /* extern "C" */ 00191 #endif 00192 00193 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */ 00194
Generated on Wed Jul 13 2022 02:33:55 by
1.7.2