mirror of https://github.com/wolfSSL/wolfssl.git
progress on asn
parent
59eb83c6e9
commit
d1e48e2364
|
@ -29,166 +29,88 @@
|
||||||
#include <cyassl/ctaocrypt/rsa.h>
|
#include <cyassl/ctaocrypt/rsa.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/asn_public.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifndef HAVE_FIPS
|
||||||
extern "C" {
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
#define InitCert wc_InitCert
|
||||||
|
#define MakeCert wc_MakeCert
|
||||||
|
#ifdef WOLFSSL_CERT_REQ
|
||||||
|
#define MakeCertReq wc_MakeCertReq
|
||||||
#endif
|
#endif
|
||||||
|
#define SignCert wc_SignCert
|
||||||
|
#define MakeSelfCert wc_MakeSelfCert
|
||||||
/* Certificate file Type */
|
#define SetIssuer wc_SetIssuer
|
||||||
enum CertType {
|
#define SetSubject wc_SetSubject
|
||||||
CERT_TYPE = 0,
|
#ifdef WOLFSSL_ALT_NAMES
|
||||||
PRIVATEKEY_TYPE,
|
#define SetAltNames wc_SetAltNames
|
||||||
DH_PARAM_TYPE,
|
|
||||||
CRL_TYPE,
|
|
||||||
CA_TYPE,
|
|
||||||
ECC_PRIVATEKEY_TYPE,
|
|
||||||
CERTREQ_TYPE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Signature type, by OID sum */
|
|
||||||
enum Ctc_SigType {
|
|
||||||
CTC_SHAwDSA = 517,
|
|
||||||
CTC_MD2wRSA = 646,
|
|
||||||
CTC_MD5wRSA = 648,
|
|
||||||
CTC_SHAwRSA = 649,
|
|
||||||
CTC_SHAwECDSA = 520,
|
|
||||||
CTC_SHA256wRSA = 655,
|
|
||||||
CTC_SHA256wECDSA = 524,
|
|
||||||
CTC_SHA384wRSA = 656,
|
|
||||||
CTC_SHA384wECDSA = 525,
|
|
||||||
CTC_SHA512wRSA = 657,
|
|
||||||
CTC_SHA512wECDSA = 526
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Ctc_Encoding {
|
|
||||||
CTC_UTF8 = 0x0c, /* utf8 */
|
|
||||||
CTC_PRINTABLE = 0x13 /* printable */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CYASSL_CERT_GEN
|
|
||||||
|
|
||||||
#ifndef HAVE_ECC
|
|
||||||
typedef struct ecc_key ecc_key;
|
|
||||||
#endif
|
#endif
|
||||||
|
#define SetIssuerBuffer wc_SetIssuerBuffer
|
||||||
enum Ctc_Misc {
|
#define SetSubjectBuffer wc_SetSubjectBuffer
|
||||||
CTC_NAME_SIZE = 64,
|
#define SetAltNamesBuffer wc_SetAltNamesBuffer
|
||||||
CTC_DATE_SIZE = 32,
|
#define SetDatesBuffer wc_SetDatesBuffer
|
||||||
CTC_MAX_ALT_SIZE = 16384, /* may be huge */
|
|
||||||
CTC_SERIAL_SIZE = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct CertName {
|
|
||||||
char country[CTC_NAME_SIZE];
|
|
||||||
char countryEnc;
|
|
||||||
char state[CTC_NAME_SIZE];
|
|
||||||
char stateEnc;
|
|
||||||
char locality[CTC_NAME_SIZE];
|
|
||||||
char localityEnc;
|
|
||||||
char sur[CTC_NAME_SIZE];
|
|
||||||
char surEnc;
|
|
||||||
char org[CTC_NAME_SIZE];
|
|
||||||
char orgEnc;
|
|
||||||
char unit[CTC_NAME_SIZE];
|
|
||||||
char unitEnc;
|
|
||||||
char commonName[CTC_NAME_SIZE];
|
|
||||||
char commonNameEnc;
|
|
||||||
char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
|
|
||||||
} CertName;
|
|
||||||
|
|
||||||
|
|
||||||
/* for user to fill for certificate generation */
|
|
||||||
typedef struct Cert {
|
|
||||||
int version; /* x509 version */
|
|
||||||
byte serial[CTC_SERIAL_SIZE]; /* serial number */
|
|
||||||
int sigType; /* signature algo type */
|
|
||||||
CertName issuer; /* issuer info */
|
|
||||||
int daysValid; /* validity days */
|
|
||||||
int selfSigned; /* self signed flag */
|
|
||||||
CertName subject; /* subject info */
|
|
||||||
int isCA; /* is this going to be a CA */
|
|
||||||
/* internal use only */
|
|
||||||
int bodySz; /* pre sign total size */
|
|
||||||
int keyType; /* public key type of subject */
|
|
||||||
#ifdef CYASSL_ALT_NAMES
|
|
||||||
byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
|
|
||||||
int altNamesSz; /* altNames size in bytes */
|
|
||||||
byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
|
|
||||||
int beforeDateSz; /* size of copy */
|
|
||||||
byte afterDate[CTC_DATE_SIZE]; /* after date copy */
|
|
||||||
int afterDateSz; /* size of copy */
|
|
||||||
#endif
|
|
||||||
#ifdef CYASSL_CERT_REQ
|
|
||||||
char challengePw[CTC_NAME_SIZE];
|
|
||||||
#endif
|
|
||||||
} Cert;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize and Set Certficate defaults:
|
|
||||||
version = 3 (0x2)
|
|
||||||
serial = 0 (Will be randomly generated)
|
|
||||||
sigType = SHA_WITH_RSA
|
|
||||||
issuer = blank
|
|
||||||
daysValid = 500
|
|
||||||
selfSigned = 1 (true) use subject as issuer
|
|
||||||
subject = blank
|
|
||||||
isCA = 0 (false)
|
|
||||||
keyType = RSA_KEY (default)
|
|
||||||
*/
|
|
||||||
CYASSL_API void InitCert(Cert*);
|
|
||||||
CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
||||||
ecc_key*, RNG*);
|
|
||||||
#ifdef CYASSL_CERT_REQ
|
|
||||||
CYASSL_API int MakeCertReq(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
||||||
ecc_key*);
|
|
||||||
#endif
|
|
||||||
CYASSL_API int SignCert(int requestSz, int sigType, byte* derBuffer,
|
|
||||||
word32 derSz, RsaKey*, ecc_key*, RNG*);
|
|
||||||
CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
||||||
RNG*);
|
|
||||||
CYASSL_API int SetIssuer(Cert*, const char*);
|
|
||||||
CYASSL_API int SetSubject(Cert*, const char*);
|
|
||||||
#ifdef CYASSL_ALT_NAMES
|
|
||||||
CYASSL_API int SetAltNames(Cert*, const char*);
|
|
||||||
#endif
|
|
||||||
CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int);
|
|
||||||
CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int);
|
|
||||||
CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int);
|
|
||||||
CYASSL_API int SetDatesBuffer(Cert*, const byte*, int);
|
|
||||||
|
|
||||||
#ifdef HAVE_NTRU
|
#ifdef HAVE_NTRU
|
||||||
CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
|
#define MakeNtruCert wc_MakeNtruCert
|
||||||
const byte* ntruKey, word16 keySz, RNG*);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
#if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
|
||||||
|
#define DerToPem wc_DerToPem
|
||||||
#if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
|
|
||||||
CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
|
|
||||||
word32 outputSz, int type);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
/* private key helpers */
|
/* private key helpers */
|
||||||
CYASSL_API int EccPrivateKeyDecode(const byte* input,word32* inOutIdx,
|
#define EccPrivateKeyDecode wc_EccPrivateKeyDecode
|
||||||
ecc_key*,word32);
|
#define EccKeyToDer wc_EccKeyToDer
|
||||||
CYASSL_API int EccKeyToDer(ecc_key*, byte* output, word32 inLen);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* DER encode signature */
|
/* DER encode signature */
|
||||||
CYASSL_API word32 EncodeSignature(byte* out, const byte* digest, word32 digSz,
|
#define EncodeSignature wc_EncodeSignature
|
||||||
int hashOID);
|
#define GetCTC_HashOID wc_GetCTC_HashOID
|
||||||
CYASSL_API int GetCTC_HashOID(int type);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#else
|
||||||
} /* extern "C" */
|
|
||||||
|
#define WOLFSSL_CERT_GEN CYASSL_CERTGEN
|
||||||
|
#define WOLFSSL_CERT_REQ CYASSL_CERT_REQ
|
||||||
|
#define WOLFSSL_ALT_NAMES CYASSL_ALT_NAMES
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
#define wc_InitCert InitCert
|
||||||
|
#define wc_MakeCert MakeCert
|
||||||
|
#ifdef WOLFSSL_CERT_REQ
|
||||||
|
#define wc_MakeCertReq MakeCertReq
|
||||||
|
#endif
|
||||||
|
#define wc_SignCert SignCert
|
||||||
|
#define wc_MakeSelfCert MakeSelfCert
|
||||||
|
#define wc_SetIssuer SetIssuer
|
||||||
|
#define wc_SetSubject SetSubject
|
||||||
|
#ifdef WOLFSSL_ALT_NAMES
|
||||||
|
#define wc_SetAltNames SetAltNames
|
||||||
|
#endif
|
||||||
|
#define wc_SetIssuerBuffer SetIssuerBuffer
|
||||||
|
#define wc_SetSubjectBuffer SetSubjectBuffer
|
||||||
|
#define wc_SetAltNamesBuffer SetAltNamesBuffer
|
||||||
|
#define wc_SetDatesBuffer SetDatesBuffer
|
||||||
|
|
||||||
|
#ifdef HAVE_NTRU
|
||||||
|
#define wc_MakeNtruCert MakeNtruCert
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
#if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
|
||||||
|
#define wc_DerToPem DerToPem
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CTAO_CRYPT_ASN_PUBLIC_H */
|
#ifdef HAVE_ECC
|
||||||
|
/* private key helpers */
|
||||||
|
#define wc_EccPrivateKeyDecode EccPrivateKeyDecode
|
||||||
|
#define wc_EccKeyToDer EccKeyToDer
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* DER encode signature */
|
||||||
|
#define wc_EncodeSignature EncodeSignature
|
||||||
|
#define wc_GetCTC_HashOID GetCTC_HashOID
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
#endif /* CTA_CRYPT_ASN_PUBLIC_H */
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
#ifndef HAVE_FIPS
|
#ifndef HAVE_FIPS
|
||||||
#include <wolfssl/wolfcrypt/types.h>
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
/* compatibility macros */
|
/* compatibility macros */
|
||||||
#define CYASSL_WORD_SIZE WOLFSSL_WORD_SIZE
|
#define CYASSL_WORD_SIZE WOLFSSL_WORD_SIZE
|
||||||
#define CYASSL_BIT_SIZE WOLFSSL_BIT_SIZE
|
#define CYASSL_BIT_SIZE WOLFSSL_BIT_SIZE
|
||||||
#define CYASSL_MAX_16BIT WOLFSSL_MAX_16BIT
|
#define CYASSL_MAX_16BIT WOLFSSL_MAX_16BIT
|
||||||
#define CYASSL_MAX_ERROR_SZ WOLFSSL_MAX_ERROR_SZ
|
#define CYASSL_MAX_ERROR_SZ WOLFSSL_MAX_ERROR_SZ
|
||||||
#define cyassl_word wolfssl_word
|
#define cyassl_word wolfssl_word
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <cyassl/ctaocrypt/settings.h>
|
#include <cyassl/ctaocrypt/settings.h>
|
||||||
|
|
|
@ -83,12 +83,8 @@ src_libwolfssl_la_SOURCES += wolfcrypt/src/dh.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if BUILD_ASN
|
if BUILD_ASN
|
||||||
if BUILD_FIPS
|
|
||||||
src_libwolfssl_la_SOURCES += ctaocrypt/src/asn.c
|
|
||||||
else
|
|
||||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/asn.c
|
src_libwolfssl_la_SOURCES += wolfcrypt/src/asn.c
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
if BUILD_CODING
|
if BUILD_CODING
|
||||||
if BUILD_FIPS
|
if BUILD_FIPS
|
||||||
|
|
|
@ -40,6 +40,11 @@
|
||||||
#endif
|
#endif
|
||||||
#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||||
|
|
||||||
|
#define WOLFSSL_WORD_SIZE CYASSL_WORD_SIZE
|
||||||
|
#define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE
|
||||||
|
#define WOLFSSL_MAX_16BIT CYASSL_MAX_16BIT
|
||||||
|
#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ
|
||||||
|
#define wolfssl_word cyassl_word
|
||||||
/* memory macros */
|
/* memory macros */
|
||||||
/* when using fips map wolfSSL to CyaSSL*/
|
/* when using fips map wolfSSL to CyaSSL*/
|
||||||
#define wolfSSL_Malloc_cb CyaSSL_Malloc_cb
|
#define wolfSSL_Malloc_cb CyaSSL_Malloc_cb
|
||||||
|
|
Loading…
Reference in New Issue