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.
wolfssl/wolfcrypt/asn_public.h@15:117db924cf7c, 2018-08-18 (annotated)
- Committer:
- wolfSSL
- Date:
- Sat Aug 18 22:20:43 2018 +0000
- Revision:
- 15:117db924cf7c
wolfSSL 3.15.3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wolfSSL | 15:117db924cf7c | 1 | /* asn_public.h |
| wolfSSL | 15:117db924cf7c | 2 | * |
| wolfSSL | 15:117db924cf7c | 3 | * Copyright (C) 2006-2017 wolfSSL Inc. |
| wolfSSL | 15:117db924cf7c | 4 | * |
| wolfSSL | 15:117db924cf7c | 5 | * This file is part of wolfSSL. |
| wolfSSL | 15:117db924cf7c | 6 | * |
| wolfSSL | 15:117db924cf7c | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
| wolfSSL | 15:117db924cf7c | 8 | * it under the terms of the GNU General Public License as published by |
| wolfSSL | 15:117db924cf7c | 9 | * the Free Software Foundation; either version 2 of the License, or |
| wolfSSL | 15:117db924cf7c | 10 | * (at your option) any later version. |
| wolfSSL | 15:117db924cf7c | 11 | * |
| wolfSSL | 15:117db924cf7c | 12 | * wolfSSL is distributed in the hope that it will be useful, |
| wolfSSL | 15:117db924cf7c | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| wolfSSL | 15:117db924cf7c | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| wolfSSL | 15:117db924cf7c | 15 | * GNU General Public License for more details. |
| wolfSSL | 15:117db924cf7c | 16 | * |
| wolfSSL | 15:117db924cf7c | 17 | * You should have received a copy of the GNU General Public License |
| wolfSSL | 15:117db924cf7c | 18 | * along with this program; if not, write to the Free Software |
| wolfSSL | 15:117db924cf7c | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| wolfSSL | 15:117db924cf7c | 20 | */ |
| wolfSSL | 15:117db924cf7c | 21 | |
| wolfSSL | 15:117db924cf7c | 22 | /*! |
| wolfSSL | 15:117db924cf7c | 23 | \file wolfssl/wolfcrypt/asn_public.h |
| wolfSSL | 15:117db924cf7c | 24 | */ |
| wolfSSL | 15:117db924cf7c | 25 | |
| wolfSSL | 15:117db924cf7c | 26 | #ifndef WOLF_CRYPT_ASN_PUBLIC_H |
| wolfSSL | 15:117db924cf7c | 27 | #define WOLF_CRYPT_ASN_PUBLIC_H |
| wolfSSL | 15:117db924cf7c | 28 | |
| wolfSSL | 15:117db924cf7c | 29 | #include <wolfssl/wolfcrypt/types.h> |
| wolfSSL | 15:117db924cf7c | 30 | |
| wolfSSL | 15:117db924cf7c | 31 | #ifdef __cplusplus |
| wolfSSL | 15:117db924cf7c | 32 | extern "C" { |
| wolfSSL | 15:117db924cf7c | 33 | #endif |
| wolfSSL | 15:117db924cf7c | 34 | |
| wolfSSL | 15:117db924cf7c | 35 | /* guard on redeclaration */ |
| wolfSSL | 15:117db924cf7c | 36 | #ifndef WC_ECCKEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 37 | typedef struct ecc_key ecc_key; |
| wolfSSL | 15:117db924cf7c | 38 | #define WC_ECCKEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 39 | #endif |
| wolfSSL | 15:117db924cf7c | 40 | #ifndef WC_ED25519KEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 41 | typedef struct ed25519_key ed25519_key; |
| wolfSSL | 15:117db924cf7c | 42 | #define WC_ED25519KEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 43 | #endif |
| wolfSSL | 15:117db924cf7c | 44 | #ifndef WC_RSAKEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 45 | typedef struct RsaKey RsaKey; |
| wolfSSL | 15:117db924cf7c | 46 | #define WC_RSAKEY_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 47 | #endif |
| wolfSSL | 15:117db924cf7c | 48 | #ifndef WC_RNG_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 49 | typedef struct WC_RNG WC_RNG; |
| wolfSSL | 15:117db924cf7c | 50 | #define WC_RNG_TYPE_DEFINED |
| wolfSSL | 15:117db924cf7c | 51 | #endif |
| wolfSSL | 15:117db924cf7c | 52 | |
| wolfSSL | 15:117db924cf7c | 53 | |
| wolfSSL | 15:117db924cf7c | 54 | /* Certificate file Type */ |
| wolfSSL | 15:117db924cf7c | 55 | enum CertType { |
| wolfSSL | 15:117db924cf7c | 56 | CERT_TYPE = 0, |
| wolfSSL | 15:117db924cf7c | 57 | PRIVATEKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 58 | DH_PARAM_TYPE, |
| wolfSSL | 15:117db924cf7c | 59 | DSA_PARAM_TYPE, |
| wolfSSL | 15:117db924cf7c | 60 | CRL_TYPE, |
| wolfSSL | 15:117db924cf7c | 61 | CA_TYPE, |
| wolfSSL | 15:117db924cf7c | 62 | ECC_PRIVATEKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 63 | DSA_PRIVATEKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 64 | CERTREQ_TYPE, |
| wolfSSL | 15:117db924cf7c | 65 | DSA_TYPE, |
| wolfSSL | 15:117db924cf7c | 66 | ECC_TYPE, |
| wolfSSL | 15:117db924cf7c | 67 | RSA_TYPE, |
| wolfSSL | 15:117db924cf7c | 68 | PUBLICKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 69 | RSA_PUBLICKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 70 | ECC_PUBLICKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 71 | TRUSTED_PEER_TYPE, |
| wolfSSL | 15:117db924cf7c | 72 | EDDSA_PRIVATEKEY_TYPE, |
| wolfSSL | 15:117db924cf7c | 73 | ED25519_TYPE, |
| wolfSSL | 15:117db924cf7c | 74 | PKCS12_TYPE |
| wolfSSL | 15:117db924cf7c | 75 | }; |
| wolfSSL | 15:117db924cf7c | 76 | |
| wolfSSL | 15:117db924cf7c | 77 | |
| wolfSSL | 15:117db924cf7c | 78 | /* Signature type, by OID sum */ |
| wolfSSL | 15:117db924cf7c | 79 | enum Ctc_SigType { |
| wolfSSL | 15:117db924cf7c | 80 | CTC_SHAwDSA = 517, |
| wolfSSL | 15:117db924cf7c | 81 | CTC_MD2wRSA = 646, |
| wolfSSL | 15:117db924cf7c | 82 | CTC_MD5wRSA = 648, |
| wolfSSL | 15:117db924cf7c | 83 | CTC_SHAwRSA = 649, |
| wolfSSL | 15:117db924cf7c | 84 | CTC_SHAwECDSA = 520, |
| wolfSSL | 15:117db924cf7c | 85 | CTC_SHA224wRSA = 658, |
| wolfSSL | 15:117db924cf7c | 86 | CTC_SHA224wECDSA = 523, |
| wolfSSL | 15:117db924cf7c | 87 | CTC_SHA256wRSA = 655, |
| wolfSSL | 15:117db924cf7c | 88 | CTC_SHA256wECDSA = 524, |
| wolfSSL | 15:117db924cf7c | 89 | CTC_SHA384wRSA = 656, |
| wolfSSL | 15:117db924cf7c | 90 | CTC_SHA384wECDSA = 525, |
| wolfSSL | 15:117db924cf7c | 91 | CTC_SHA512wRSA = 657, |
| wolfSSL | 15:117db924cf7c | 92 | CTC_SHA512wECDSA = 526, |
| wolfSSL | 15:117db924cf7c | 93 | CTC_ED25519 = 256 |
| wolfSSL | 15:117db924cf7c | 94 | }; |
| wolfSSL | 15:117db924cf7c | 95 | |
| wolfSSL | 15:117db924cf7c | 96 | enum Ctc_Encoding { |
| wolfSSL | 15:117db924cf7c | 97 | CTC_UTF8 = 0x0c, /* utf8 */ |
| wolfSSL | 15:117db924cf7c | 98 | CTC_PRINTABLE = 0x13 /* printable */ |
| wolfSSL | 15:117db924cf7c | 99 | }; |
| wolfSSL | 15:117db924cf7c | 100 | |
| wolfSSL | 15:117db924cf7c | 101 | #ifndef WC_CTC_MAX_ALT_SIZE |
| wolfSSL | 15:117db924cf7c | 102 | #define WC_CTC_MAX_ALT_SIZE 16384 |
| wolfSSL | 15:117db924cf7c | 103 | #endif |
| wolfSSL | 15:117db924cf7c | 104 | |
| wolfSSL | 15:117db924cf7c | 105 | enum Ctc_Misc { |
| wolfSSL | 15:117db924cf7c | 106 | CTC_COUNTRY_SIZE = 2, |
| wolfSSL | 15:117db924cf7c | 107 | CTC_NAME_SIZE = 64, |
| wolfSSL | 15:117db924cf7c | 108 | CTC_DATE_SIZE = 32, |
| wolfSSL | 15:117db924cf7c | 109 | CTC_MAX_ALT_SIZE = WC_CTC_MAX_ALT_SIZE, /* may be huge, default: 16384 */ |
| wolfSSL | 15:117db924cf7c | 110 | CTC_SERIAL_SIZE = 16, |
| wolfSSL | 15:117db924cf7c | 111 | #ifdef WOLFSSL_CERT_EXT |
| wolfSSL | 15:117db924cf7c | 112 | /* AKID could contains: hash + (Option) AuthCertIssuer,AuthCertSerialNum |
| wolfSSL | 15:117db924cf7c | 113 | * We support only hash */ |
| wolfSSL | 15:117db924cf7c | 114 | CTC_MAX_SKID_SIZE = 32, /* SHA256_DIGEST_SIZE */ |
| wolfSSL | 15:117db924cf7c | 115 | CTC_MAX_AKID_SIZE = 32, /* SHA256_DIGEST_SIZE */ |
| wolfSSL | 15:117db924cf7c | 116 | CTC_MAX_CERTPOL_SZ = 64, |
| wolfSSL | 15:117db924cf7c | 117 | CTC_MAX_CERTPOL_NB = 2 /* Max number of Certificate Policy */ |
| wolfSSL | 15:117db924cf7c | 118 | #endif /* WOLFSSL_CERT_EXT */ |
| wolfSSL | 15:117db924cf7c | 119 | }; |
| wolfSSL | 15:117db924cf7c | 120 | |
| wolfSSL | 15:117db924cf7c | 121 | /* DER buffer */ |
| wolfSSL | 15:117db924cf7c | 122 | typedef struct DerBuffer { |
| wolfSSL | 15:117db924cf7c | 123 | byte* buffer; |
| wolfSSL | 15:117db924cf7c | 124 | void* heap; |
| wolfSSL | 15:117db924cf7c | 125 | word32 length; |
| wolfSSL | 15:117db924cf7c | 126 | int type; /* enum CertType */ |
| wolfSSL | 15:117db924cf7c | 127 | int dynType; /* DYNAMIC_TYPE_* */ |
| wolfSSL | 15:117db924cf7c | 128 | } DerBuffer; |
| wolfSSL | 15:117db924cf7c | 129 | |
| wolfSSL | 15:117db924cf7c | 130 | enum { |
| wolfSSL | 15:117db924cf7c | 131 | IV_SZ = 32, /* max iv sz */ |
| wolfSSL | 15:117db924cf7c | 132 | NAME_SZ = 80, /* max one line */ |
| wolfSSL | 15:117db924cf7c | 133 | |
| wolfSSL | 15:117db924cf7c | 134 | PEM_PASS_READ = 0, |
| wolfSSL | 15:117db924cf7c | 135 | PEM_PASS_WRITE = 1, |
| wolfSSL | 15:117db924cf7c | 136 | }; |
| wolfSSL | 15:117db924cf7c | 137 | |
| wolfSSL | 15:117db924cf7c | 138 | |
| wolfSSL | 15:117db924cf7c | 139 | typedef int (pem_password_cb)(char* passwd, int sz, int rw, void* userdata); |
| wolfSSL | 15:117db924cf7c | 140 | |
| wolfSSL | 15:117db924cf7c | 141 | typedef struct EncryptedInfo { |
| wolfSSL | 15:117db924cf7c | 142 | pem_password_cb* passwd_cb; |
| wolfSSL | 15:117db924cf7c | 143 | void* passwd_userdata; |
| wolfSSL | 15:117db924cf7c | 144 | |
| wolfSSL | 15:117db924cf7c | 145 | long consumed; /* tracks PEM bytes consumed */ |
| wolfSSL | 15:117db924cf7c | 146 | |
| wolfSSL | 15:117db924cf7c | 147 | int cipherType; |
| wolfSSL | 15:117db924cf7c | 148 | word32 keySz; |
| wolfSSL | 15:117db924cf7c | 149 | word32 ivSz; /* salt or encrypted IV size */ |
| wolfSSL | 15:117db924cf7c | 150 | |
| wolfSSL | 15:117db924cf7c | 151 | char name[NAME_SZ]; /* cipher name, such as "DES-CBC" */ |
| wolfSSL | 15:117db924cf7c | 152 | byte iv[IV_SZ]; /* salt or encrypted IV */ |
| wolfSSL | 15:117db924cf7c | 153 | |
| wolfSSL | 15:117db924cf7c | 154 | int set:1; /* if encryption set */ |
| wolfSSL | 15:117db924cf7c | 155 | } EncryptedInfo; |
| wolfSSL | 15:117db924cf7c | 156 | |
| wolfSSL | 15:117db924cf7c | 157 | |
| wolfSSL | 15:117db924cf7c | 158 | #ifdef WOLFSSL_CERT_GEN |
| wolfSSL | 15:117db924cf7c | 159 | |
| wolfSSL | 15:117db924cf7c | 160 | #ifdef WOLFSSL_EKU_OID |
| wolfSSL | 15:117db924cf7c | 161 | #ifndef CTC_MAX_EKU_NB |
| wolfSSL | 15:117db924cf7c | 162 | #define CTC_MAX_EKU_NB 1 |
| wolfSSL | 15:117db924cf7c | 163 | #endif |
| wolfSSL | 15:117db924cf7c | 164 | #ifndef CTC_MAX_EKU_OID_SZ |
| wolfSSL | 15:117db924cf7c | 165 | #define CTC_MAX_EKU_OID_SZ 30 |
| wolfSSL | 15:117db924cf7c | 166 | #endif |
| wolfSSL | 15:117db924cf7c | 167 | #else |
| wolfSSL | 15:117db924cf7c | 168 | #undef CTC_MAX_EKU_OID_SZ |
| wolfSSL | 15:117db924cf7c | 169 | #define CTC_MAX_EKU_OID_SZ 0 |
| wolfSSL | 15:117db924cf7c | 170 | #endif |
| wolfSSL | 15:117db924cf7c | 171 | |
| wolfSSL | 15:117db924cf7c | 172 | |
| wolfSSL | 15:117db924cf7c | 173 | #ifdef WOLFSSL_MULTI_ATTRIB |
| wolfSSL | 15:117db924cf7c | 174 | #ifndef CTC_MAX_ATTRIB |
| wolfSSL | 15:117db924cf7c | 175 | #define CTC_MAX_ATTRIB 4 |
| wolfSSL | 15:117db924cf7c | 176 | #endif |
| wolfSSL | 15:117db924cf7c | 177 | |
| wolfSSL | 15:117db924cf7c | 178 | /* ASN Encoded Name field */ |
| wolfSSL | 15:117db924cf7c | 179 | typedef struct NameAttrib { |
| wolfSSL | 15:117db924cf7c | 180 | int sz; /* actual string value length */ |
| wolfSSL | 15:117db924cf7c | 181 | int id; /* id of name */ |
| wolfSSL | 15:117db924cf7c | 182 | int type; /* enc of name */ |
| wolfSSL | 15:117db924cf7c | 183 | char value[CTC_NAME_SIZE]; /* name */ |
| wolfSSL | 15:117db924cf7c | 184 | } NameAttrib; |
| wolfSSL | 15:117db924cf7c | 185 | #endif /* WOLFSSL_MULTI_ATTRIB */ |
| wolfSSL | 15:117db924cf7c | 186 | |
| wolfSSL | 15:117db924cf7c | 187 | |
| wolfSSL | 15:117db924cf7c | 188 | typedef struct CertName { |
| wolfSSL | 15:117db924cf7c | 189 | char country[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 190 | char countryEnc; |
| wolfSSL | 15:117db924cf7c | 191 | char state[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 192 | char stateEnc; |
| wolfSSL | 15:117db924cf7c | 193 | char locality[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 194 | char localityEnc; |
| wolfSSL | 15:117db924cf7c | 195 | char sur[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 196 | char surEnc; |
| wolfSSL | 15:117db924cf7c | 197 | char org[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 198 | char orgEnc; |
| wolfSSL | 15:117db924cf7c | 199 | char unit[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 200 | char unitEnc; |
| wolfSSL | 15:117db924cf7c | 201 | char commonName[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 202 | char commonNameEnc; |
| wolfSSL | 15:117db924cf7c | 203 | char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */ |
| wolfSSL | 15:117db924cf7c | 204 | #ifdef WOLFSSL_MULTI_ATTRIB |
| wolfSSL | 15:117db924cf7c | 205 | NameAttrib name[CTC_MAX_ATTRIB]; |
| wolfSSL | 15:117db924cf7c | 206 | #endif |
| wolfSSL | 15:117db924cf7c | 207 | } CertName; |
| wolfSSL | 15:117db924cf7c | 208 | |
| wolfSSL | 15:117db924cf7c | 209 | |
| wolfSSL | 15:117db924cf7c | 210 | /* for user to fill for certificate generation */ |
| wolfSSL | 15:117db924cf7c | 211 | typedef struct Cert { |
| wolfSSL | 15:117db924cf7c | 212 | int version; /* x509 version */ |
| wolfSSL | 15:117db924cf7c | 213 | byte serial[CTC_SERIAL_SIZE]; /* serial number */ |
| wolfSSL | 15:117db924cf7c | 214 | int serialSz; /* serial size */ |
| wolfSSL | 15:117db924cf7c | 215 | int sigType; /* signature algo type */ |
| wolfSSL | 15:117db924cf7c | 216 | CertName issuer; /* issuer info */ |
| wolfSSL | 15:117db924cf7c | 217 | int daysValid; /* validity days */ |
| wolfSSL | 15:117db924cf7c | 218 | int selfSigned; /* self signed flag */ |
| wolfSSL | 15:117db924cf7c | 219 | CertName subject; /* subject info */ |
| wolfSSL | 15:117db924cf7c | 220 | int isCA; /* is this going to be a CA */ |
| wolfSSL | 15:117db924cf7c | 221 | /* internal use only */ |
| wolfSSL | 15:117db924cf7c | 222 | int bodySz; /* pre sign total size */ |
| wolfSSL | 15:117db924cf7c | 223 | int keyType; /* public key type of subject */ |
| wolfSSL | 15:117db924cf7c | 224 | #ifdef WOLFSSL_ALT_NAMES |
| wolfSSL | 15:117db924cf7c | 225 | byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */ |
| wolfSSL | 15:117db924cf7c | 226 | int altNamesSz; /* altNames size in bytes */ |
| wolfSSL | 15:117db924cf7c | 227 | byte beforeDate[CTC_DATE_SIZE]; /* before date copy */ |
| wolfSSL | 15:117db924cf7c | 228 | int beforeDateSz; /* size of copy */ |
| wolfSSL | 15:117db924cf7c | 229 | byte afterDate[CTC_DATE_SIZE]; /* after date copy */ |
| wolfSSL | 15:117db924cf7c | 230 | int afterDateSz; /* size of copy */ |
| wolfSSL | 15:117db924cf7c | 231 | #endif |
| wolfSSL | 15:117db924cf7c | 232 | #ifdef WOLFSSL_CERT_EXT |
| wolfSSL | 15:117db924cf7c | 233 | byte skid[CTC_MAX_SKID_SIZE]; /* Subject Key Identifier */ |
| wolfSSL | 15:117db924cf7c | 234 | int skidSz; /* SKID size in bytes */ |
| wolfSSL | 15:117db924cf7c | 235 | byte akid[CTC_MAX_AKID_SIZE]; /* Authority Key Identifier */ |
| wolfSSL | 15:117db924cf7c | 236 | int akidSz; /* AKID size in bytes */ |
| wolfSSL | 15:117db924cf7c | 237 | word16 keyUsage; /* Key Usage */ |
| wolfSSL | 15:117db924cf7c | 238 | byte extKeyUsage; /* Extended Key Usage */ |
| wolfSSL | 15:117db924cf7c | 239 | #ifdef WOLFSSL_EKU_OID |
| wolfSSL | 15:117db924cf7c | 240 | /* Extended Key Usage OIDs */ |
| wolfSSL | 15:117db924cf7c | 241 | byte extKeyUsageOID[CTC_MAX_EKU_NB][CTC_MAX_EKU_OID_SZ]; |
| wolfSSL | 15:117db924cf7c | 242 | byte extKeyUsageOIDSz[CTC_MAX_EKU_NB]; |
| wolfSSL | 15:117db924cf7c | 243 | #endif |
| wolfSSL | 15:117db924cf7c | 244 | char certPolicies[CTC_MAX_CERTPOL_NB][CTC_MAX_CERTPOL_SZ]; |
| wolfSSL | 15:117db924cf7c | 245 | word16 certPoliciesNb; /* Number of Cert Policy */ |
| wolfSSL | 15:117db924cf7c | 246 | #endif |
| wolfSSL | 15:117db924cf7c | 247 | #ifdef WOLFSSL_CERT_REQ |
| wolfSSL | 15:117db924cf7c | 248 | char challengePw[CTC_NAME_SIZE]; |
| wolfSSL | 15:117db924cf7c | 249 | #endif |
| wolfSSL | 15:117db924cf7c | 250 | void* heap; /* heap hint */ |
| wolfSSL | 15:117db924cf7c | 251 | } Cert; |
| wolfSSL | 15:117db924cf7c | 252 | |
| wolfSSL | 15:117db924cf7c | 253 | |
| wolfSSL | 15:117db924cf7c | 254 | |
| wolfSSL | 15:117db924cf7c | 255 | /* Initialize and Set Certificate defaults: |
| wolfSSL | 15:117db924cf7c | 256 | version = 3 (0x2) |
| wolfSSL | 15:117db924cf7c | 257 | serial = 0 (Will be randomly generated) |
| wolfSSL | 15:117db924cf7c | 258 | sigType = SHA_WITH_RSA |
| wolfSSL | 15:117db924cf7c | 259 | issuer = blank |
| wolfSSL | 15:117db924cf7c | 260 | daysValid = 500 |
| wolfSSL | 15:117db924cf7c | 261 | selfSigned = 1 (true) use subject as issuer |
| wolfSSL | 15:117db924cf7c | 262 | subject = blank |
| wolfSSL | 15:117db924cf7c | 263 | isCA = 0 (false) |
| wolfSSL | 15:117db924cf7c | 264 | keyType = RSA_KEY (default) |
| wolfSSL | 15:117db924cf7c | 265 | */ |
| wolfSSL | 15:117db924cf7c | 266 | WOLFSSL_API int wc_InitCert(Cert*); |
| wolfSSL | 15:117db924cf7c | 267 | WOLFSSL_API int wc_MakeCert_ex(Cert* cert, byte* derBuffer, word32 derSz, |
| wolfSSL | 15:117db924cf7c | 268 | int keyType, void* key, WC_RNG* rng); |
| wolfSSL | 15:117db924cf7c | 269 | WOLFSSL_API int wc_MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, |
| wolfSSL | 15:117db924cf7c | 270 | ecc_key*, WC_RNG*); |
| wolfSSL | 15:117db924cf7c | 271 | #ifdef WOLFSSL_CERT_REQ |
| wolfSSL | 15:117db924cf7c | 272 | WOLFSSL_API int wc_MakeCertReq_ex(Cert*, byte* derBuffer, word32 derSz, |
| wolfSSL | 15:117db924cf7c | 273 | int, void*); |
| wolfSSL | 15:117db924cf7c | 274 | WOLFSSL_API int wc_MakeCertReq(Cert*, byte* derBuffer, word32 derSz, |
| wolfSSL | 15:117db924cf7c | 275 | RsaKey*, ecc_key*); |
| wolfSSL | 15:117db924cf7c | 276 | #endif |
| wolfSSL | 15:117db924cf7c | 277 | WOLFSSL_API int wc_SignCert_ex(int requestSz, int sType, byte* buffer, |
| wolfSSL | 15:117db924cf7c | 278 | word32 buffSz, int keyType, void* key, |
| wolfSSL | 15:117db924cf7c | 279 | WC_RNG* rng); |
| wolfSSL | 15:117db924cf7c | 280 | WOLFSSL_API int wc_SignCert(int requestSz, int sigType, byte* derBuffer, |
| wolfSSL | 15:117db924cf7c | 281 | word32 derSz, RsaKey*, ecc_key*, WC_RNG*); |
| wolfSSL | 15:117db924cf7c | 282 | WOLFSSL_API int wc_MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, |
| wolfSSL | 15:117db924cf7c | 283 | WC_RNG*); |
| wolfSSL | 15:117db924cf7c | 284 | WOLFSSL_API int wc_SetIssuer(Cert*, const char*); |
| wolfSSL | 15:117db924cf7c | 285 | WOLFSSL_API int wc_SetSubject(Cert*, const char*); |
| wolfSSL | 15:117db924cf7c | 286 | #ifdef WOLFSSL_ALT_NAMES |
| wolfSSL | 15:117db924cf7c | 287 | WOLFSSL_API int wc_SetAltNames(Cert*, const char*); |
| wolfSSL | 15:117db924cf7c | 288 | #endif |
| wolfSSL | 15:117db924cf7c | 289 | WOLFSSL_API int wc_SetIssuerBuffer(Cert*, const byte*, int); |
| wolfSSL | 15:117db924cf7c | 290 | WOLFSSL_API int wc_SetSubjectBuffer(Cert*, const byte*, int); |
| wolfSSL | 15:117db924cf7c | 291 | WOLFSSL_API int wc_SetAltNamesBuffer(Cert*, const byte*, int); |
| wolfSSL | 15:117db924cf7c | 292 | WOLFSSL_API int wc_SetDatesBuffer(Cert*, const byte*, int); |
| wolfSSL | 15:117db924cf7c | 293 | |
| wolfSSL | 15:117db924cf7c | 294 | #ifndef NO_ASN_TIME |
| wolfSSL | 15:117db924cf7c | 295 | WOLFSSL_API int wc_GetCertDates(Cert* cert, struct tm* before, |
| wolfSSL | 15:117db924cf7c | 296 | struct tm* after); |
| wolfSSL | 15:117db924cf7c | 297 | #endif |
| wolfSSL | 15:117db924cf7c | 298 | |
| wolfSSL | 15:117db924cf7c | 299 | #ifdef WOLFSSL_CERT_EXT |
| wolfSSL | 15:117db924cf7c | 300 | WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey_ex(Cert *cert, int keyType, |
| wolfSSL | 15:117db924cf7c | 301 | void* key); |
| wolfSSL | 15:117db924cf7c | 302 | WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, |
| wolfSSL | 15:117db924cf7c | 303 | ecc_key *eckey); |
| wolfSSL | 15:117db924cf7c | 304 | WOLFSSL_API int wc_SetAuthKeyIdFromCert(Cert *cert, const byte *der, int derSz); |
| wolfSSL | 15:117db924cf7c | 305 | WOLFSSL_API int wc_SetAuthKeyId(Cert *cert, const char* file); |
| wolfSSL | 15:117db924cf7c | 306 | WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey_ex(Cert *cert, int keyType, |
| wolfSSL | 15:117db924cf7c | 307 | void* key); |
| wolfSSL | 15:117db924cf7c | 308 | WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, |
| wolfSSL | 15:117db924cf7c | 309 | ecc_key *eckey); |
| wolfSSL | 15:117db924cf7c | 310 | WOLFSSL_API int wc_SetSubjectKeyId(Cert *cert, const char* file); |
| wolfSSL | 15:117db924cf7c | 311 | |
| wolfSSL | 15:117db924cf7c | 312 | #ifdef HAVE_NTRU |
| wolfSSL | 15:117db924cf7c | 313 | WOLFSSL_API int wc_SetSubjectKeyIdFromNtruPublicKey(Cert *cert, byte *ntruKey, |
| wolfSSL | 15:117db924cf7c | 314 | word16 ntruKeySz); |
| wolfSSL | 15:117db924cf7c | 315 | #endif |
| wolfSSL | 15:117db924cf7c | 316 | |
| wolfSSL | 15:117db924cf7c | 317 | /* Set the KeyUsage. |
| wolfSSL | 15:117db924cf7c | 318 | * Value is a string separated tokens with ','. Accepted tokens are : |
| wolfSSL | 15:117db924cf7c | 319 | * digitalSignature,nonRepudiation,contentCommitment,keyCertSign,cRLSign, |
| wolfSSL | 15:117db924cf7c | 320 | * dataEncipherment,keyAgreement,keyEncipherment,encipherOnly and decipherOnly. |
| wolfSSL | 15:117db924cf7c | 321 | * |
| wolfSSL | 15:117db924cf7c | 322 | * nonRepudiation and contentCommitment are for the same usage. |
| wolfSSL | 15:117db924cf7c | 323 | */ |
| wolfSSL | 15:117db924cf7c | 324 | WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value); |
| wolfSSL | 15:117db924cf7c | 325 | |
| wolfSSL | 15:117db924cf7c | 326 | /* Set ExtendedKeyUsage |
| wolfSSL | 15:117db924cf7c | 327 | * Value is a string separated tokens with ','. Accepted tokens are : |
| wolfSSL | 15:117db924cf7c | 328 | * any,serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,OCSPSigning |
| wolfSSL | 15:117db924cf7c | 329 | */ |
| wolfSSL | 15:117db924cf7c | 330 | WOLFSSL_API int wc_SetExtKeyUsage(Cert *cert, const char *value); |
| wolfSSL | 15:117db924cf7c | 331 | |
| wolfSSL | 15:117db924cf7c | 332 | |
| wolfSSL | 15:117db924cf7c | 333 | #ifdef WOLFSSL_EKU_OID |
| wolfSSL | 15:117db924cf7c | 334 | /* Set ExtendedKeyUsage with unique OID |
| wolfSSL | 15:117db924cf7c | 335 | * oid is expected to be in byte representation |
| wolfSSL | 15:117db924cf7c | 336 | */ |
| wolfSSL | 15:117db924cf7c | 337 | WOLFSSL_API int wc_SetExtKeyUsageOID(Cert *cert, const char *oid, word32 sz, |
| wolfSSL | 15:117db924cf7c | 338 | byte idx, void* heap); |
| wolfSSL | 15:117db924cf7c | 339 | #endif /* WOLFSSL_EKU_OID */ |
| wolfSSL | 15:117db924cf7c | 340 | #endif /* WOLFSSL_CERT_EXT */ |
| wolfSSL | 15:117db924cf7c | 341 | |
| wolfSSL | 15:117db924cf7c | 342 | #ifdef HAVE_NTRU |
| wolfSSL | 15:117db924cf7c | 343 | WOLFSSL_API int wc_MakeNtruCert(Cert*, byte* derBuffer, word32 derSz, |
| wolfSSL | 15:117db924cf7c | 344 | const byte* ntruKey, word16 keySz, |
| wolfSSL | 15:117db924cf7c | 345 | WC_RNG*); |
| wolfSSL | 15:117db924cf7c | 346 | #endif |
| wolfSSL | 15:117db924cf7c | 347 | |
| wolfSSL | 15:117db924cf7c | 348 | #endif /* WOLFSSL_CERT_GEN */ |
| wolfSSL | 15:117db924cf7c | 349 | |
| wolfSSL | 15:117db924cf7c | 350 | WOLFSSL_API int wc_GetDateInfo(const byte* certDate, int certDateSz, |
| wolfSSL | 15:117db924cf7c | 351 | const byte** date, byte* format, int* length); |
| wolfSSL | 15:117db924cf7c | 352 | #ifndef NO_ASN_TIME |
| wolfSSL | 15:117db924cf7c | 353 | WOLFSSL_API int wc_GetDateAsCalendarTime(const byte* date, int length, |
| wolfSSL | 15:117db924cf7c | 354 | byte format, struct tm* time); |
| wolfSSL | 15:117db924cf7c | 355 | #endif |
| wolfSSL | 15:117db924cf7c | 356 | |
| wolfSSL | 15:117db924cf7c | 357 | #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM) |
| wolfSSL | 15:117db924cf7c | 358 | |
| wolfSSL | 15:117db924cf7c | 359 | WOLFSSL_API int wc_PemGetHeaderFooter(int type, const char** header, |
| wolfSSL | 15:117db924cf7c | 360 | const char** footer); |
| wolfSSL | 15:117db924cf7c | 361 | |
| wolfSSL | 15:117db924cf7c | 362 | #endif |
| wolfSSL | 15:117db924cf7c | 363 | |
| wolfSSL | 15:117db924cf7c | 364 | #ifdef WOLFSSL_PEM_TO_DER |
| wolfSSL | 15:117db924cf7c | 365 | WOLFSSL_API int wc_PemToDer(const unsigned char* buff, long longSz, int type, |
| wolfSSL | 15:117db924cf7c | 366 | DerBuffer** pDer, void* heap, EncryptedInfo* info, int* eccKey); |
| wolfSSL | 15:117db924cf7c | 367 | |
| wolfSSL | 15:117db924cf7c | 368 | WOLFSSL_API int wc_KeyPemToDer(const unsigned char*, int, |
| wolfSSL | 15:117db924cf7c | 369 | unsigned char*, int, const char*); |
| wolfSSL | 15:117db924cf7c | 370 | WOLFSSL_API int wc_CertPemToDer(const unsigned char*, int, |
| wolfSSL | 15:117db924cf7c | 371 | unsigned char*, int, int); |
| wolfSSL | 15:117db924cf7c | 372 | #endif /* WOLFSSL_PEM_TO_DER */ |
| wolfSSL | 15:117db924cf7c | 373 | |
| wolfSSL | 15:117db924cf7c | 374 | #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER) |
| wolfSSL | 15:117db924cf7c | 375 | #ifndef NO_FILESYSTEM |
| wolfSSL | 15:117db924cf7c | 376 | WOLFSSL_API int wc_PemPubKeyToDer(const char* fileName, |
| wolfSSL | 15:117db924cf7c | 377 | unsigned char* derBuf, int derSz); |
| wolfSSL | 15:117db924cf7c | 378 | #endif |
| wolfSSL | 15:117db924cf7c | 379 | |
| wolfSSL | 15:117db924cf7c | 380 | WOLFSSL_API int wc_PubKeyPemToDer(const unsigned char*, int, |
| wolfSSL | 15:117db924cf7c | 381 | unsigned char*, int); |
| wolfSSL | 15:117db924cf7c | 382 | #endif /* WOLFSSL_CERT_EXT || WOLFSSL_PUB_PEM_TO_DER */ |
| wolfSSL | 15:117db924cf7c | 383 | |
| wolfSSL | 15:117db924cf7c | 384 | #ifdef WOLFSSL_CERT_GEN |
| wolfSSL | 15:117db924cf7c | 385 | #ifndef NO_FILESYSTEM |
| wolfSSL | 15:117db924cf7c | 386 | WOLFSSL_API int wc_PemCertToDer(const char* fileName, |
| wolfSSL | 15:117db924cf7c | 387 | unsigned char* derBuf, int derSz); |
| wolfSSL | 15:117db924cf7c | 388 | #endif |
| wolfSSL | 15:117db924cf7c | 389 | #endif /* WOLFSSL_CERT_GEN */ |
| wolfSSL | 15:117db924cf7c | 390 | |
| wolfSSL | 15:117db924cf7c | 391 | #ifdef WOLFSSL_DER_TO_PEM |
| wolfSSL | 15:117db924cf7c | 392 | WOLFSSL_API int wc_DerToPem(const byte* der, word32 derSz, byte* output, |
| wolfSSL | 15:117db924cf7c | 393 | word32 outputSz, int type); |
| wolfSSL | 15:117db924cf7c | 394 | WOLFSSL_API int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, |
| wolfSSL | 15:117db924cf7c | 395 | word32 outputSz, byte *cipherIno, int type); |
| wolfSSL | 15:117db924cf7c | 396 | #endif |
| wolfSSL | 15:117db924cf7c | 397 | |
| wolfSSL | 15:117db924cf7c | 398 | #ifdef HAVE_ECC |
| wolfSSL | 15:117db924cf7c | 399 | /* private key helpers */ |
| wolfSSL | 15:117db924cf7c | 400 | WOLFSSL_API int wc_EccPrivateKeyDecode(const byte*, word32*, |
| wolfSSL | 15:117db924cf7c | 401 | ecc_key*, word32); |
| wolfSSL | 15:117db924cf7c | 402 | WOLFSSL_API int wc_EccKeyToDer(ecc_key*, byte* output, word32 inLen); |
| wolfSSL | 15:117db924cf7c | 403 | WOLFSSL_API int wc_EccPrivateKeyToDer(ecc_key* key, byte* output, |
| wolfSSL | 15:117db924cf7c | 404 | word32 inLen); |
| wolfSSL | 15:117db924cf7c | 405 | WOLFSSL_API int wc_EccPrivateKeyToPKCS8(ecc_key* key, byte* output, |
| wolfSSL | 15:117db924cf7c | 406 | word32* outLen); |
| wolfSSL | 15:117db924cf7c | 407 | |
| wolfSSL | 15:117db924cf7c | 408 | /* public key helper */ |
| wolfSSL | 15:117db924cf7c | 409 | WOLFSSL_API int wc_EccPublicKeyDecode(const byte*, word32*, |
| wolfSSL | 15:117db924cf7c | 410 | ecc_key*, word32); |
| wolfSSL | 15:117db924cf7c | 411 | WOLFSSL_API int wc_EccPublicKeyToDer(ecc_key*, byte* output, |
| wolfSSL | 15:117db924cf7c | 412 | word32 inLen, int with_AlgCurve); |
| wolfSSL | 15:117db924cf7c | 413 | #endif |
| wolfSSL | 15:117db924cf7c | 414 | |
| wolfSSL | 15:117db924cf7c | 415 | #ifdef HAVE_ED25519 |
| wolfSSL | 15:117db924cf7c | 416 | /* private key helpers */ |
| wolfSSL | 15:117db924cf7c | 417 | WOLFSSL_API int wc_Ed25519PrivateKeyDecode(const byte*, word32*, |
| wolfSSL | 15:117db924cf7c | 418 | ed25519_key*, word32); |
| wolfSSL | 15:117db924cf7c | 419 | WOLFSSL_API int wc_Ed25519KeyToDer(ed25519_key* key, byte* output, |
| wolfSSL | 15:117db924cf7c | 420 | word32 inLen); |
| wolfSSL | 15:117db924cf7c | 421 | WOLFSSL_API int wc_Ed25519PrivateKeyToDer(ed25519_key* key, byte* output, |
| wolfSSL | 15:117db924cf7c | 422 | word32 inLen); |
| wolfSSL | 15:117db924cf7c | 423 | |
| wolfSSL | 15:117db924cf7c | 424 | /* public key helper */ |
| wolfSSL | 15:117db924cf7c | 425 | WOLFSSL_API int wc_Ed25519PublicKeyDecode(const byte*, word32*, |
| wolfSSL | 15:117db924cf7c | 426 | ed25519_key*, word32); |
| wolfSSL | 15:117db924cf7c | 427 | #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN)) |
| wolfSSL | 15:117db924cf7c | 428 | WOLFSSL_API int wc_Ed25519PublicKeyToDer(ed25519_key*, byte* output, |
| wolfSSL | 15:117db924cf7c | 429 | word32 inLen, int with_AlgCurve); |
| wolfSSL | 15:117db924cf7c | 430 | #endif |
| wolfSSL | 15:117db924cf7c | 431 | #endif |
| wolfSSL | 15:117db924cf7c | 432 | |
| wolfSSL | 15:117db924cf7c | 433 | /* DER encode signature */ |
| wolfSSL | 15:117db924cf7c | 434 | WOLFSSL_API word32 wc_EncodeSignature(byte* out, const byte* digest, |
| wolfSSL | 15:117db924cf7c | 435 | word32 digSz, int hashOID); |
| wolfSSL | 15:117db924cf7c | 436 | WOLFSSL_API int wc_GetCTC_HashOID(int type); |
| wolfSSL | 15:117db924cf7c | 437 | |
| wolfSSL | 15:117db924cf7c | 438 | WOLFSSL_API int wc_GetPkcs8TraditionalOffset(byte* input, |
| wolfSSL | 15:117db924cf7c | 439 | word32* inOutIdx, word32 sz); |
| wolfSSL | 15:117db924cf7c | 440 | WOLFSSL_API int wc_CreatePKCS8Key(byte* out, word32* outSz, |
| wolfSSL | 15:117db924cf7c | 441 | byte* key, word32 keySz, int algoID, const byte* curveOID, word32 oidSz); |
| wolfSSL | 15:117db924cf7c | 442 | |
| wolfSSL | 15:117db924cf7c | 443 | #ifndef NO_ASN_TIME |
| wolfSSL | 15:117db924cf7c | 444 | /* Time */ |
| wolfSSL | 15:117db924cf7c | 445 | /* Returns seconds (Epoch/UTC) |
| wolfSSL | 15:117db924cf7c | 446 | * timePtr: is "time_t", which is typically "long" |
| wolfSSL | 15:117db924cf7c | 447 | * Example: |
| wolfSSL | 15:117db924cf7c | 448 | long lTime; |
| wolfSSL | 15:117db924cf7c | 449 | rc = wc_GetTime(&lTime, (word32)sizeof(lTime)); |
| wolfSSL | 15:117db924cf7c | 450 | */ |
| wolfSSL | 15:117db924cf7c | 451 | WOLFSSL_API int wc_GetTime(void* timePtr, word32 timeSize); |
| wolfSSL | 15:117db924cf7c | 452 | #endif |
| wolfSSL | 15:117db924cf7c | 453 | |
| wolfSSL | 15:117db924cf7c | 454 | #ifdef WOLFSSL_ENCRYPTED_KEYS |
| wolfSSL | 15:117db924cf7c | 455 | WOLFSSL_API int wc_EncryptedInfoGet(EncryptedInfo* info, |
| wolfSSL | 15:117db924cf7c | 456 | const char* cipherInfo); |
| wolfSSL | 15:117db924cf7c | 457 | #endif |
| wolfSSL | 15:117db924cf7c | 458 | |
| wolfSSL | 15:117db924cf7c | 459 | |
| wolfSSL | 15:117db924cf7c | 460 | #ifdef __cplusplus |
| wolfSSL | 15:117db924cf7c | 461 | } /* extern "C" */ |
| wolfSSL | 15:117db924cf7c | 462 | #endif |
| wolfSSL | 15:117db924cf7c | 463 | |
| wolfSSL | 15:117db924cf7c | 464 | #endif /* WOLF_CRYPT_ASN_PUBLIC_H */ |
| wolfSSL | 15:117db924cf7c | 465 | |
| wolfSSL | 15:117db924cf7c | 466 |