26 #ifndef WOLF_CRYPT_ASN_PUBLIC_H 27 #define WOLF_CRYPT_ASN_PUBLIC_H 36 #ifndef WC_ECCKEY_TYPE_DEFINED 38 #define WC_ECCKEY_TYPE_DEFINED 40 #ifndef WC_ED25519KEY_TYPE_DEFINED 42 #define WC_ED25519KEY_TYPE_DEFINED 44 #ifndef WC_ED448KEY_TYPE_DEFINED 46 #define WC_ED448KEY_TYPE_DEFINED 48 #ifndef WC_RSAKEY_TYPE_DEFINED 50 #define WC_RSAKEY_TYPE_DEFINED 52 #ifndef WC_RNG_TYPE_DEFINED 54 #define WC_RNG_TYPE_DEFINED 58 ECC_SECP112R1_OID = 182,
59 ECC_SECP112R2_OID = 183,
60 ECC_SECP128R1_OID = 204,
61 ECC_SECP128R2_OID = 205,
62 ECC_SECP160R1_OID = 184,
63 ECC_SECP160R2_OID = 206,
64 ECC_SECP160K1_OID = 185,
65 ECC_BRAINPOOLP160R1_OID = 98,
66 ECC_SECP192R1_OID = 520,
67 ECC_PRIME192V2_OID = 521,
68 ECC_PRIME192V3_OID = 522,
69 ECC_SECP192K1_OID = 207,
70 ECC_BRAINPOOLP192R1_OID = 100,
71 ECC_SECP224R1_OID = 209,
72 ECC_SECP224K1_OID = 208,
73 ECC_BRAINPOOLP224R1_OID = 102,
74 ECC_PRIME239V1_OID = 523,
75 ECC_PRIME239V2_OID = 524,
76 ECC_PRIME239V3_OID = 525,
77 ECC_SECP256R1_OID = 526,
78 ECC_SECP256K1_OID = 186,
79 ECC_BRAINPOOLP256R1_OID = 104,
81 ECC_ED25519_OID = 256,
82 ECC_BRAINPOOLP320R1_OID = 106,
85 ECC_SECP384R1_OID = 210,
86 ECC_BRAINPOOLP384R1_OID = 108,
87 ECC_BRAINPOOLP512R1_OID = 110,
88 ECC_SECP521R1_OID = 211,
110 EDDSA_PRIVATEKEY_TYPE,
114 PKCS8_PRIVATEKEY_TYPE,
115 PKCS8_ENC_PRIVATEKEY_TYPE,
128 CTC_SHA224wRSA = 658,
129 CTC_SHA224wECDSA = 523,
130 CTC_SHA256wRSA = 655,
131 CTC_SHA256wECDSA = 524,
132 CTC_SHA384wRSA = 656,
133 CTC_SHA384wECDSA = 525,
134 CTC_SHA512wRSA = 657,
135 CTC_SHA512wECDSA = 526,
145 #ifndef WC_CTC_NAME_SIZE 146 #define WC_CTC_NAME_SIZE 64 148 #ifndef WC_CTC_MAX_ALT_SIZE 149 #define WC_CTC_MAX_ALT_SIZE 16384 153 CTC_COUNTRY_SIZE = 2,
154 CTC_NAME_SIZE = WC_CTC_NAME_SIZE,
156 CTC_MAX_ALT_SIZE = WC_CTC_MAX_ALT_SIZE,
157 CTC_SERIAL_SIZE = 20,
158 CTC_GEN_SERIAL_SZ = 16,
159 #ifdef WOLFSSL_CERT_EXT 162 CTC_MAX_SKID_SIZE = 32,
163 CTC_MAX_AKID_SIZE = 32,
164 CTC_MAX_CERTPOL_SZ = 64,
165 CTC_MAX_CERTPOL_NB = 2
179 unsigned char data[CTC_DATE_SIZE];
193 typedef int (pem_password_cb)(
char* passwd,
int sz,
int rw,
void* userdata);
196 pem_password_cb* passwd_cb;
197 void* passwd_userdata;
212 #define WOLFSSL_ASN1_INTEGER_MAX 20 216 unsigned char intData[WOLFSSL_ASN1_INTEGER_MAX];
218 unsigned char negative;
221 unsigned int dataMax;
222 unsigned int isDynamic:1;
229 #if defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT) 230 #ifdef WOLFSSL_EKU_OID 231 #ifndef CTC_MAX_EKU_NB 232 #define CTC_MAX_EKU_NB 1 234 #ifndef CTC_MAX_EKU_OID_SZ 235 #define CTC_MAX_EKU_OID_SZ 30 238 #undef CTC_MAX_EKU_OID_SZ 239 #define CTC_MAX_EKU_OID_SZ 0 243 #ifdef WOLFSSL_CERT_GEN 245 #ifdef WOLFSSL_MULTI_ATTRIB 246 #ifndef CTC_MAX_ATTRIB 247 #define CTC_MAX_ATTRIB 4 255 char value[CTC_NAME_SIZE];
261 char country[CTC_NAME_SIZE];
263 char state[CTC_NAME_SIZE];
265 char locality[CTC_NAME_SIZE];
267 char sur[CTC_NAME_SIZE];
269 char org[CTC_NAME_SIZE];
271 char unit[CTC_NAME_SIZE];
273 char commonName[CTC_NAME_SIZE];
275 char serialDev[CTC_NAME_SIZE];
277 #ifdef WOLFSSL_CERT_EXT 278 char busCat[CTC_NAME_SIZE];
280 char joiC[CTC_NAME_SIZE];
282 char joiSt[CTC_NAME_SIZE];
285 char email[CTC_NAME_SIZE];
286 #ifdef WOLFSSL_MULTI_ATTRIB 295 byte serial[CTC_SERIAL_SIZE];
306 #ifdef WOLFSSL_ALT_NAMES 307 byte altNames[CTC_MAX_ALT_SIZE];
309 byte beforeDate[CTC_DATE_SIZE];
311 byte afterDate[CTC_DATE_SIZE];
314 #ifdef WOLFSSL_CERT_EXT 315 byte skid[CTC_MAX_SKID_SIZE];
317 byte akid[CTC_MAX_AKID_SIZE];
321 #ifdef WOLFSSL_EKU_OID 323 byte extKeyUsageOID[CTC_MAX_EKU_NB][CTC_MAX_EKU_OID_SZ];
324 byte extKeyUsageOIDSz[CTC_MAX_EKU_NB];
326 char certPolicies[CTC_MAX_CERTPOL_NB][CTC_MAX_CERTPOL_SZ];
327 word16 certPoliciesNb;
331 #ifdef WOLFSSL_CERT_REQ 332 char challengePw[CTC_NAME_SIZE];
333 int challengePwPrintableString;
353 WOLFSSL_API
int wc_MakeCert_ex(
Cert* cert, byte* derBuffer, word32 derSz,
354 int keyType,
void* key,
WC_RNG* rng);
357 #ifdef WOLFSSL_CERT_REQ 358 WOLFSSL_API
int wc_MakeCertReq_ex(
Cert*, byte* derBuffer, word32 derSz,
363 WOLFSSL_API
int wc_SignCert_ex(
int requestSz,
int sType, byte* buffer,
364 word32 buffSz,
int keyType,
void* key,
366 WOLFSSL_API
int wc_SignCert(
int requestSz,
int sigType, byte* derBuffer,
372 #ifdef WOLFSSL_ALT_NAMES 376 #ifdef WOLFSSL_CERT_GEN_CACHE 386 WOLFSSL_API
int wc_GetCertDates(
Cert* cert,
struct tm* before,
390 #ifdef WOLFSSL_CERT_EXT 391 WOLFSSL_API
int wc_SetAuthKeyIdFromPublicKey_ex(
Cert *cert,
int keyType,
397 WOLFSSL_API
int wc_SetSubjectKeyIdFromPublicKey_ex(
Cert *cert,
int keyType,
424 WOLFSSL_API
int wc_SetExtKeyUsage(
Cert *cert,
const char *value);
427 #ifdef WOLFSSL_EKU_OID 431 WOLFSSL_API
int wc_SetExtKeyUsageOID(
Cert *cert,
const char *oid, word32 sz,
432 byte idx,
void* heap);
438 const byte* ntruKey, word16 keySz,
444 WOLFSSL_API
int wc_GetDateInfo(
const byte* certDate,
int certDateSz,
445 const byte** date, byte* format,
int* length);
447 WOLFSSL_API
int wc_GetDateAsCalendarTime(
const byte* date,
int length,
448 byte format,
struct tm* time);
451 #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM) 453 WOLFSSL_API
int wc_PemGetHeaderFooter(
int type,
const char** header,
454 const char** footer);
458 WOLFSSL_API
int wc_AllocDer(
DerBuffer** pDer, word32 length,
int type,
void* heap);
459 WOLFSSL_API
void wc_FreeDer(
DerBuffer** pDer);
461 #ifdef WOLFSSL_PEM_TO_DER 462 WOLFSSL_API
int wc_PemToDer(
const unsigned char* buff,
long longSz,
int type,
466 unsigned char*,
int,
const char*);
468 unsigned char*,
int,
int);
471 #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER) 472 #ifndef NO_FILESYSTEM 474 unsigned char* derBuf,
int derSz);
478 unsigned char*,
int);
481 #ifdef WOLFSSL_CERT_GEN 482 #ifndef NO_FILESYSTEM 484 unsigned char* derBuf,
int derSz);
488 #ifdef WOLFSSL_DER_TO_PEM 489 WOLFSSL_API
int wc_DerToPem(
const byte* der, word32 derSz, byte* output,
490 word32 outputSz,
int type);
491 WOLFSSL_API
int wc_DerToPemEx(
const byte* der, word32 derSz, byte* output,
492 word32 outputSz, byte *cipherIno,
int type);
496 #if !defined(HAVE_USER_RSA) 497 WOLFSSL_API
int wc_RsaPublicKeyDecode_ex(
const byte* input, word32* inOutIdx,
498 word32 inSz,
const byte** n, word32* nSz,
const byte** e, word32* eSz);
500 WOLFSSL_API
int wc_RsaPublicKeyDerSize(
RsaKey* key,
int with_header);
508 WOLFSSL_API
int wc_EccPrivateKeyToDer(
ecc_key* key, byte* output,
510 WOLFSSL_API
int wc_EccPrivateKeyToPKCS8(
ecc_key* key, byte* output,
517 word32 inLen,
int with_AlgCurve);
518 WOLFSSL_API
int wc_EccPublicKeyDerSize(
ecc_key*,
int with_AlgCurve);
523 WOLFSSL_API
int wc_Ed25519PrivateKeyDecode(
const byte*, word32*,
525 WOLFSSL_API
int wc_Ed25519KeyToDer(
ed25519_key* key, byte* output,
527 WOLFSSL_API
int wc_Ed25519PrivateKeyToDer(
ed25519_key* key, byte* output,
531 WOLFSSL_API
int wc_Ed25519PublicKeyDecode(
const byte*, word32*,
533 #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN)) 534 WOLFSSL_API
int wc_Ed25519PublicKeyToDer(
ed25519_key*, byte* output,
535 word32 inLen,
int with_AlgCurve);
541 WOLFSSL_API
int wc_Ed448PrivateKeyDecode(
const byte*, word32*,
543 WOLFSSL_API
int wc_Ed448KeyToDer(
ed448_key* key, byte* output,
545 WOLFSSL_API
int wc_Ed448PrivateKeyToDer(
ed448_key* key, byte* output,
549 WOLFSSL_API
int wc_Ed448PublicKeyDecode(
const byte*, word32*,
551 #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN)) 552 WOLFSSL_API
int wc_Ed448PublicKeyToDer(
ed448_key*, byte* output,
553 word32 inLen,
int with_AlgCurve);
559 word32 digSz,
int hashOID);
562 WOLFSSL_API
int wc_GetPkcs8TraditionalOffset(byte* input,
563 word32* inOutIdx, word32 sz);
564 WOLFSSL_API
int wc_CreatePKCS8Key(byte* out, word32* outSz,
565 byte* key, word32 keySz,
int algoID,
const byte* curveOID, word32 oidSz);
575 WOLFSSL_API
int wc_GetTime(
void* timePtr, word32 timeSize);
578 #ifdef WOLFSSL_ENCRYPTED_KEYS 580 const char* cipherInfo);
584 #ifdef WOLFSSL_CERT_PIV 589 const byte* certErrDet;
593 const byte* signedNonce;
594 word32 signedNonceSz;
597 word16 compression:2;
602 WOLFSSL_API
int wc_ParseCertPIV(
wc_CertPIV* cert,
const byte* buf, word32 totalSz);
WOLFSSL_API int wc_EccPublicKeyToDer(ecc_key *, byte *output, word32 inLen, int with_AlgCurve)
This function converts the ECC public key to DER format. It returns the size of buffer used...
Definition: asn.c:11565
WOLFSSL_API int wc_MakeNtruCert(Cert *, byte *derBuffer, word32 derSz, const byte *ntruKey, word16 keySz, WC_RNG *)
Used to make CA signed certs. Called after the subject information has been entered. This function makes an NTRU Certificate from a cert input. It then writes this cert to derBuffer. It takes in an ntruKey and a rng to generate the certificate. The certificate must be initialized with wc_InitCert before this method is called.
Definition: asn.c:13440
WOLFSSL_API int wc_PemCertToDer(const char *fileName, unsigned char *derBuf, int derSz)
This function converts a pem certificate to a der certificate, and places the resulting certificate i...
Definition: asn.c:10776
WOLFSSL_API word32 wc_EncodeSignature(byte *out, const byte *digest, word32 digSz, int hashOID)
This function encodes a digital signature into the output buffer, and returns the size of the encoded...
Definition: asn.c:6852
WOLFSSL_API int wc_CertPemToDer(const unsigned char *, int, unsigned char *, int, int)
This function converts a PEM formatted certificate to DER format. Calls OpenSSL function PemToDer...
Definition: asn.c:10692
WOLFSSL_API int wc_MakeCert(Cert *, byte *derBuffer, word32 derSz, RsaKey *, ecc_key *, WC_RNG *)
Used to make CA signed certs. Called after the subject information has been entered. This function makes an x509 Certificate v3 RSA or ECC from a cert input. It then writes this cert to derBuffer. It takes in either an rsaKey or an eccKey to generate the certificate. The certificate must be initialized with wc_InitCert before this method is called.
Definition: asn.c:13430
WOLFSSL_API int wc_KeyPemToDer(const unsigned char *, int, unsigned char *, int, const char *)
Converts a key in PEM format to DER format.
Definition: asn.c:10636
WOLFSSL_API int wc_GetSubjectRaw(byte **subjectRaw, Cert *cert)
This function gets the raw subject from the certificate structure.
Definition: asn.c:13943
WOLFSSL_API int wc_MakeCertReq(Cert *, byte *derBuffer, word32 derSz, RsaKey *, ecc_key *)
This function makes a certificate signing request using the input certificate and writes the output t...
Definition: asn.c:13810
WOLFSSL_API int wc_SetSubjectKeyId(Cert *cert, const char *file)
Set SKID from public key file in PEM format. Both arguments are required.
Definition: asn.c:14097
Definition: asn_public.h:586
WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey)
Set SKID from RSA or ECC public key.
Definition: asn.c:14050
WOLFSSL_API int wc_SetSubjectKeyIdFromNtruPublicKey(Cert *cert, byte *ntruKey, word16 ntruKeySz)
Set SKID from NTRU public key.
Definition: asn.c:14058
Definition: asn_public.h:195
WOLFSSL_API int wc_SetIssuer(Cert *, const char *)
This function sets the issuer for a certificate to the issuer in the provided pem issuerFile...
Definition: asn.c:14701
Definition: asn_public.h:260
WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey)
Set AKID from either an RSA or ECC public key. note: Only set one of rsakey or eckey, not both.
Definition: asn.c:14087
WOLFSSL_API int wc_SetDatesBuffer(Cert *, const byte *, int)
This function sets the dates for a certificate from the date range in the provided der buffer...
Definition: asn.c:14925
WOLFSSL_API int wc_SetAltNamesBuffer(Cert *, const byte *, int)
This function sets the alternate names for a certificate from the alternate names in the provided der...
Definition: asn.c:14899
WOLFSSL_API int wc_DerToPemEx(const byte *der, word32 derSz, byte *output, word32 outputSz, byte *cipherIno, int type)
This function converts a der formatted input certificate, contained in the der buffer, into a pem formatted output certificate, contained in the output buffer. It should be noted that this is not an in place conversion, and a separate buffer must be utilized to store the pem formatted output. Allows setting cipher info.
Definition: asn.c:10173
WOLFSSL_API int wc_GetCTC_HashOID(int type)
This function returns the hash OID that corresponds to a hashing type. For example, when given the type: SHA512, this function returns the identifier corresponding to a SHA512 hash, SHA512h.
Definition: asn.c:6874
WOLFSSL_API int wc_SetSubjectRaw(Cert *cert, const byte *der, int derSz)
This function sets the raw subject for a certificate from the subject in the provided der buffer...
Definition: asn.c:14833
WOLFSSL_API int wc_SetAuthKeyId(Cert *cert, const char *file)
Set AKID from certificate file in PEM format.
Definition: asn.c:14250
WOLFSSL_API int wc_SetSubject(Cert *, const char *)
This function sets the subject for a certificate to the subject in the provided pem subjectFile...
Definition: asn.c:14726
WOLFSSL_API int wc_SetIssuerBuffer(Cert *, const byte *, int)
This function sets the issuer for a certificate from the issuer in the provided der buffer...
Definition: asn.c:14779
Definition: asn_public.h:178
WOLFSSL_API int wc_SetAuthKeyIdFromCert(Cert *cert, const byte *der, int derSz)
Set AKID from from DER encoded certificate.
Definition: asn.c:14221
WOLFSSL_API int wc_EccPublicKeyDecode(const byte *, word32 *, ecc_key *, word32)
Decodes an ECC public key from an input buffer. It will parse an ASN sequence to retrieve the ECC key...
Definition: asn.c:15369
WOLFSSL_API int wc_SignCert(int requestSz, int sigType, byte *derBuffer, word32 derSz, RsaKey *, ecc_key *, WC_RNG *)
This function signs buffer and adds the signature to the end of buffer. It takes in a signature type...
Definition: asn.c:13918
WOLFSSL_API int wc_EccPrivateKeyDecode(const byte *, word32 *, ecc_key *, word32)
This function reads in an ECC private key from the input buffer, input, parses the private key...
Definition: asn.c:15166
WOLFSSL_API int wc_SetSubjectBuffer(Cert *, const byte *, int)
This function sets the subject for a certificate from the subject in the provided der buffer...
Definition: asn.c:14807
WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value)
This function allows you to set the key usage using a comma delimited string of tokens. Accepted tokens are: digitalSignature, nonRepudiation, contentCommitment, keyCertSign, cRLSign, dataEncipherment, keyAgreement, keyEncipherment, encipherOnly, decipherOnly. Example: "digitalSignature,nonRepudiation" nonRepudiation and contentCommitment are for the same usage.
Definition: asn.c:14281
WOLFSSL_API int wc_InitCert(Cert *)
This function initializes a default cert, with the default options: version = 3 (0x2), serial = 0, sigType = SHA_WITH_RSA, issuer = blank, daysValid = 500, selfSigned = 1 (true) use subject as issuer, subject = blank.
Definition: asn.c:11273
WOLFSSL_API int wc_SetIssuerRaw(Cert *cert, const byte *der, int derSz)
This function sets the raw issuer for a certificate from the issuer in the provided der buffer...
Definition: asn.c:14865
Definition: asn_public.h:251
WOLFSSL_API int wc_SetAltNames(Cert *, const char *)
This function sets the alternate names for a certificate to the alternate names in the provided pem f...
Definition: asn.c:14752
WOLFSSL_API int wc_PemPubKeyToDer(const char *fileName, unsigned char *derBuf, int derSz)
Loads a PEM key from a file and converts to a DER encoded buffer.
Definition: asn.c:10856
Definition: asn_public.h:293
Definition: user_rsa.h:60
WOLFSSL_API int wc_MakeSelfCert(Cert *, byte *derBuffer, word32 derSz, RsaKey *, WC_RNG *)
This function is a combination of the previous two functions, wc_MakeCert and wc_SignCert for self si...
Definition: asn.c:13925
WOLFSSL_API int wc_EccKeyToDer(ecc_key *, byte *output, word32 inLen)
This function writes a private ECC key to der format.
Definition: asn.c:15685
WOLFSSL_API int wc_DerToPem(const byte *der, word32 derSz, byte *output, word32 outputSz, int type)
This function converts a der formatted input certificate, contained in the der buffer, into a pem formatted output certificate, contained in the output buffer. It should be noted that this is not an in place conversion, and a separate buffer must be utilized to store the pem formatted output.
Definition: asn.c:10165
Definition: asn_public.h:170
WOLFSSL_API void wc_SetCert_Free(Cert *cert)
This function cleans up memory and resources used by the certificate structure's decoded cert cache...
WOLFSSL_API int wc_PubKeyPemToDer(const unsigned char *, int, unsigned char *, int)
Convert a PEM encoded public key to DER. Returns the number of bytes written to the buffer or a negat...
Definition: asn.c:10738
Definition: asn_public.h:213