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.
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 #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 00066 #ifdef CYASSL_CERT_GEN 00067 00068 #ifndef HAVE_ECC 00069 typedef struct ecc_key ecc_key; 00070 #endif 00071 00072 enum Ctc_Misc { 00073 CTC_NAME_SIZE = 64, 00074 CTC_DATE_SIZE = 32, 00075 CTC_MAX_ALT_SIZE = 8192, /* may be huge */ 00076 CTC_SERIAL_SIZE = 8 00077 }; 00078 00079 typedef struct CertName { 00080 char country[CTC_NAME_SIZE]; 00081 char state[CTC_NAME_SIZE]; 00082 char locality[CTC_NAME_SIZE]; 00083 char sur[CTC_NAME_SIZE]; 00084 char org[CTC_NAME_SIZE]; 00085 char unit[CTC_NAME_SIZE]; 00086 char commonName[CTC_NAME_SIZE]; 00087 char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */ 00088 } CertName; 00089 00090 00091 /* for user to fill for certificate generation */ 00092 typedef struct Cert { 00093 int version; /* x509 version */ 00094 byte serial[CTC_SERIAL_SIZE]; /* serial number */ 00095 int sigType; /* signature algo type */ 00096 CertName issuer; /* issuer info */ 00097 int daysValid; /* validity days */ 00098 int selfSigned; /* self signed flag */ 00099 CertName subject; /* subject info */ 00100 int isCA; /* is this going to be a CA */ 00101 /* internal use only */ 00102 int bodySz; /* pre sign total size */ 00103 int keyType; /* public key type of subject */ 00104 #ifdef CYASSL_ALT_NAMES 00105 byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */ 00106 int altNamesSz; /* altNames size in bytes */ 00107 byte beforeDate[CTC_DATE_SIZE]; /* before date copy */ 00108 int beforeDateSz; /* size of copy */ 00109 byte afterDate[CTC_DATE_SIZE]; /* after date copy */ 00110 int afterDateSz; /* size of copy */ 00111 #endif 00112 #ifdef CYASSL_CERT_REQ 00113 char challengePw[CTC_NAME_SIZE]; 00114 #endif 00115 } Cert; 00116 00117 00118 00119 00120 /* Initialize and Set Certficate defaults: 00121 version = 3 (0x2) 00122 serial = 0 (Will be randomly generated) 00123 sigType = SHA_WITH_RSA 00124 issuer = blank 00125 daysValid = 500 00126 selfSigned = 1 (true) use subject as issuer 00127 subject = blank 00128 isCA = 0 (false) 00129 keyType = RSA_KEY (default) 00130 */ 00131 CYASSL_API void InitCert(Cert*); 00132 CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00133 ecc_key*, RNG*); 00134 #ifdef CYASSL_CERT_REQ 00135 CYASSL_API int MakeCertReq(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00136 ecc_key*); 00137 #endif 00138 CYASSL_API int SignCert(int requestSz, int sigType, byte* derBuffer, 00139 word32 derSz, RsaKey*, ecc_key*, RNG*); 00140 CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, 00141 RNG*); 00142 CYASSL_API int SetIssuer(Cert*, const char*); 00143 CYASSL_API int SetSubject(Cert*, const char*); 00144 #ifdef CYASSL_ALT_NAMES 00145 CYASSL_API int SetAltNames(Cert*, const char*); 00146 #endif 00147 CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int); 00148 CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int); 00149 CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int); 00150 CYASSL_API int SetDatesBuffer(Cert*, const byte*, int); 00151 00152 #ifdef HAVE_NTRU 00153 CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz, 00154 const byte* ntruKey, word16 keySz, RNG*); 00155 #endif 00156 00157 #endif /* CYASSL_CERT_GEN */ 00158 00159 00160 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) 00161 CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output, 00162 word32 outputSz, int type); 00163 #endif 00164 00165 #ifdef HAVE_ECC 00166 /* private key helpers */ 00167 CYASSL_API int EccPrivateKeyDecode(const byte* input,word32* inOutIdx, 00168 ecc_key*,word32); 00169 #endif 00170 00171 00172 #ifdef __cplusplus 00173 } /* extern "C" */ 00174 #endif 00175 00176 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */ 00177
Generated on Tue Jul 12 2022 20:12:50 by
