diff --git a/cyassl/ctaocrypt/misc.h b/cyassl/ctaocrypt/misc.h index c55f50bd0..63a9df7e6 100644 --- a/cyassl/ctaocrypt/misc.h +++ b/cyassl/ctaocrypt/misc.h @@ -23,9 +23,12 @@ #ifndef CTAO_CRYPT_MISC_H #define CTAO_CRYPT_MISC_H - #include +#ifndef HAVE_FIPS + #include +#else + #ifdef __cplusplus extern "C" { @@ -68,5 +71,6 @@ void ByteReverseWords64(word64*, const word64*, word32); #endif +#endif /* HAVE_FIPS */ #endif /* CTAO_CRYPT_MISC_H */ diff --git a/cyassl/ctaocrypt/poly1305.h b/cyassl/ctaocrypt/poly1305.h index 361432fda..b631c73bc 100644 --- a/cyassl/ctaocrypt/poly1305.h +++ b/cyassl/ctaocrypt/poly1305.h @@ -27,6 +27,11 @@ #include +/* for poly1305 reverse compatibility */ +#define Poly1305SetKey wc_Poly1305SetKey +#define Poly1305Update wc_Poly1305Update +#define Poly1305Final wc_Poly1305Final + #endif /* CTAO_CRYPT_POLY1305_H */ #endif /* HAVE_POLY1305 */ diff --git a/cyassl/ctaocrypt/types.h b/cyassl/ctaocrypt/types.h index a5d393e74..27d8a5de8 100644 --- a/cyassl/ctaocrypt/types.h +++ b/cyassl/ctaocrypt/types.h @@ -23,6 +23,16 @@ #ifndef CTAO_CRYPT_TYPES_H #define CTAO_CRYPT_TYPES_H +#ifndef HAVE_FIPS + #include + /* compatibility macros */ +#define CYASSL_WORD_SIZE WOLFSSL_WORD_SIZE +#define CYASSL_BIT_SIZE WOLFSSL_BIT_SIZE +#define CYASSL_MAX_16BIT WOLFSSL_MAX_16BIT +#define cyassl_word wolfssl_word + +#else + #include #include @@ -324,5 +334,6 @@ CYASSL_API word32 CheckRunTimeSettings(void); #endif +#endif /* HAVE_FIPS */ #endif /* CTAO_CRYPT_TYPES_H */ diff --git a/cyassl/ctaocrypt/visibility.h b/cyassl/ctaocrypt/visibility.h index 05b50e146..11c489696 100644 --- a/cyassl/ctaocrypt/visibility.h +++ b/cyassl/ctaocrypt/visibility.h @@ -26,9 +26,13 @@ /* fips compatibility @wc_fips */ #ifndef HAVE_FIPS + #ifndef CYASSL_API + #define CYASSL_API WOLFSSL_API + #endif + #ifndef CYASSL_LOCAL + #define CYASSL_LOCAL WOLFSSL_LOCAL + #endif #include - #define CYASSL_API WOLFSSL_API - #define CYASSL_LOCAL WOLFSSL_LOCAL #else #define BUILDING_CYASSL /* CYASSL_API is used for the public API symbols. diff --git a/cyassl/ssl.h b/cyassl/ssl.h index 4c7674d81..ef389279b 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -84,8 +84,9 @@ #define CYASSL_THREAD WOLFSSL_THREAD #endif -/* wolfcrypt/src/error.c */ -#define WOLFSSL_MAX_ERROR_SZ CYASSL_MAX_ERROR_SZ +#ifndef CYASSL_MAX_ERROR_SZ + #define CYASSL_MAX_ERROR_SZ WOLFSSL_MAX_ERROR_SZ +#endif /* src/ssl.c */ #define CYASSL_CRL WOLFSSL_CRL @@ -121,6 +122,8 @@ #define CyaSSL_get_current_cipher_suite wolfSSL_get_current_cipher_suite #define CyaSSL_CTX_load_verify_locations wolfSSL_CTX_load_verify_locations +#define CyaSSL_use_old_poly wolfSSL_use_old_poly + /* io.c */ #define CYASSL_CBIO_ERR_ISR WOLFSSL_CBIO_ERR_ISR #define CYASSL_CBIO_ERR_TIMEOUT WOLFSSL_CBIO_ERR_TIMEOUT @@ -153,7 +156,7 @@ #define cyassl_chacha wolfssl_chacha #define CyaSSL_ERR_reason_error_string wolfSSL_ERR_reason_error_string -#define wolfcrypt_test ctaocrypt_test +//#define wolfcrypt_test ctaocrypt_test /* src/eys.c */ #define cyassl_triple_des wolfssl_triple_des @@ -367,12 +370,8 @@ #undef WOLFSSL_API #define WOLFSSL_API CYASSL_API #endif - -#define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE /* @TODO*/ - /* wrapper around macros until they are changed in cyassl code * needs investigation in regards to macros in fips */ -#define WOLFSSL_MAX_16BIT CYASSL_MAX_16BIT #define NO_WOLFSSL_ALLOC_ALIGN NO_CYASSL_ALLOC_ALIGN /* @TODO*/ /* for pwdbased reverse compatibility */ diff --git a/src/internal.c b/src/internal.c index cdf8b9fc4..6f31bc39d 100644 --- a/src/internal.c +++ b/src/internal.c @@ -5318,16 +5318,16 @@ static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out, XMEMSET(padding, 0, sizeof(padding)); - if ((ret = Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) + if ((ret = wc_Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) return ret; /* additional input to poly1305 */ - if ((ret = Poly1305Update(ssl->auth.poly1305, additional, + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, additional, CHACHA20_BLOCK_SIZE)) != 0) return ret; /* cipher input */ - if ((ret = Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) return ret; /* handle padding for cipher input to make it 16 bytes long */ @@ -5336,7 +5336,7 @@ static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out, if (paddingSz < 0) return INPUT_CASE_ERROR; - if ((ret = Poly1305Update(ssl->auth.poly1305, padding, paddingSz)) + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, paddingSz)) != 0) return ret; } @@ -5350,12 +5350,12 @@ static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out, padding[9] = (msglen >> 8) & 0xff; padding[10] = (msglen >>16) & 0xff; padding[11] = (msglen >>24) & 0xff; - if ((ret = Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* generate tag */ - if ((ret = Poly1305Final(ssl->auth.poly1305, tag)) != 0) + if ((ret = wc_Poly1305Final(ssl->auth.poly1305, tag)) != 0) return ret; return ret; @@ -5378,27 +5378,27 @@ static int Poly1305TagOld(WOLFSSL* ssl, byte* additional, const byte* out, if (msglen < 0) return INPUT_CASE_ERROR; - if ((ret = Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) + if ((ret = wc_Poly1305SetKey(ssl->auth.poly1305, cipher, keySz)) != 0) return ret; /* add TLS compressed length and additional input to poly1305 */ additional[AEAD_AUTH_DATA_SZ - 2] = (msglen >> 8) & 0xff; additional[AEAD_AUTH_DATA_SZ - 1] = msglen & 0xff; - if ((ret = Poly1305Update(ssl->auth.poly1305, additional, + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, additional, AEAD_AUTH_DATA_SZ)) != 0) return ret; /* length of additional input plus padding */ XMEMSET(padding, 0, sizeof(padding)); padding[0] = AEAD_AUTH_DATA_SZ; - if ((ret = Poly1305Update(ssl->auth.poly1305, padding, + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* add cipher info and then its length */ XMEMSET(padding, 0, sizeof(padding)); - if ((ret = Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, out, msglen)) != 0) return ret; /* 32 bit size of cipher to 64 bit endian */ @@ -5406,12 +5406,12 @@ static int Poly1305TagOld(WOLFSSL* ssl, byte* additional, const byte* out, padding[1] = (msglen >> 8) & 0xff; padding[2] = (msglen >> 16) & 0xff; padding[3] = (msglen >> 24) & 0xff; - if ((ret = Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) + if ((ret = wc_Poly1305Update(ssl->auth.poly1305, padding, sizeof(padding))) != 0) return ret; /* generate tag */ - if ((ret = Poly1305Final(ssl->auth.poly1305, tag)) != 0) + if ((ret = wc_Poly1305Final(ssl->auth.poly1305, tag)) != 0) return ret; return ret; @@ -5472,15 +5472,15 @@ static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input, #endif /* set the nonce for chacha and get poly1305 key */ - if ((ret = Chacha_SetIV(ssl->encrypt.chacha, nonce, 0)) != 0) + if ((ret = wc_Chacha_SetIV(ssl->encrypt.chacha, nonce, 0)) != 0) return ret; - if ((ret = Chacha_Process(ssl->encrypt.chacha, cipher, + if ((ret = wc_Chacha_Process(ssl->encrypt.chacha, cipher, cipher, sizeof(cipher))) != 0) return ret; /* encrypt the plain text */ - if ((ret = Chacha_Process(ssl->encrypt.chacha, out, input, + if ((ret = wc_Chacha_Process(ssl->encrypt.chacha, out, input, sz - ssl->specs.aead_mac_size)) != 0) return ret; @@ -5576,10 +5576,10 @@ static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input, #endif /* set nonce and get poly1305 key */ - if ((ret = Chacha_SetIV(ssl->decrypt.chacha, nonce, 0)) != 0) + if ((ret = wc_Chacha_SetIV(ssl->decrypt.chacha, nonce, 0)) != 0) return ret; - if ((ret = Chacha_Process(ssl->decrypt.chacha, cipher, + if ((ret = wc_Chacha_Process(ssl->decrypt.chacha, cipher, cipher, sizeof(cipher))) != 0) return ret; @@ -5612,7 +5612,7 @@ static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input, } /* if mac was good decrypt message */ - if ((ret = Chacha_Process(ssl->decrypt.chacha, plain, input, + if ((ret = wc_Chacha_Process(ssl->decrypt.chacha, plain, input, sz - ssl->specs.aead_mac_size)) != 0) return ret; diff --git a/src/keys.c b/src/keys.c index f62ac1de3..3636bdb0c 100644 --- a/src/keys.c +++ b/src/keys.c @@ -1885,14 +1885,14 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, return MEMORY_E; if (side == WOLFSSL_CLIENT_END) { if (enc) { - chachaRet = Chacha_SetKey(enc->chacha, keys->client_write_key, + chachaRet = wc_Chacha_SetKey(enc->chacha, keys->client_write_key, specs->key_size); XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV, AEAD_IMP_IV_SZ); if (chachaRet != 0) return chachaRet; } if (dec) { - chachaRet = Chacha_SetKey(dec->chacha, keys->server_write_key, + chachaRet = wc_Chacha_SetKey(dec->chacha, keys->server_write_key, specs->key_size); XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV, AEAD_IMP_IV_SZ); @@ -1901,14 +1901,14 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, } else { if (enc) { - chachaRet = Chacha_SetKey(enc->chacha, keys->server_write_key, + chachaRet = wc_Chacha_SetKey(enc->chacha, keys->server_write_key, specs->key_size); XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV, AEAD_IMP_IV_SZ); if (chachaRet != 0) return chachaRet; } if (dec) { - chachaRet = Chacha_SetKey(dec->chacha, keys->client_write_key, + chachaRet = wc_Chacha_SetKey(dec->chacha, keys->client_write_key, specs->key_size); XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV, AEAD_IMP_IV_SZ); diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index ab9e7691c..85a0d71e2 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -1647,13 +1647,13 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, word32 orderBits = mp_count_bits(&p); /* truncate down to byte size, may be all that's needed */ - if ( (WOLFSSLF_BIT_SIZE * inlen) > orderBits) - inlen = (orderBits + WOLFSSLF_BIT_SIZE - 1)/WOLFSSL_BIT_SIZE; + if ( (WOLFSSL_BIT_SIZE * inlen) > orderBits) + inlen = (orderBits + WOLFSSL_BIT_SIZE - 1)/WOLFSSL_BIT_SIZE; err = mp_read_unsigned_bin(&e, (byte*)in, inlen); /* may still need bit truncation too */ - if (err == MP_OKAY && (WOLFSSLF_BIT_SIZE * inlen) > orderBits) - mp_rshb(&e, WOLFSSLF_BIT_SIZE - (orderBits & 0x7)); + if (err == MP_OKAY && (WOLFSSL_BIT_SIZE * inlen) > orderBits) + mp_rshb(&e, WOLFSSL_BIT_SIZE - (orderBits & 0x7)); } /* make up a key and export the public copy */ @@ -2059,13 +2059,13 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, unsigned int orderBits = mp_count_bits(&p); /* truncate down to byte size, may be all that's needed */ - if ( (WOLFSSLF_BIT_SIZE * hashlen) > orderBits) - hashlen = (orderBits + WOLFSSLF_BIT_SIZE - 1)/WOLFSSL_BIT_SIZE; + if ( (WOLFSSL_BIT_SIZE * hashlen) > orderBits) + hashlen = (orderBits + WOLFSSL_BIT_SIZE - 1)/WOLFSSL_BIT_SIZE; err = mp_read_unsigned_bin(&e, hash, hashlen); /* may still need bit truncation too */ - if (err == MP_OKAY && (WOLFSSLF_BIT_SIZE * hashlen) > orderBits) - mp_rshb(&e, WOLFSSLF_BIT_SIZE - (orderBits & 0x7)); + if (err == MP_OKAY && (WOLFSSL_BIT_SIZE * hashlen) > orderBits) + mp_rshb(&e, WOLFSSL_BIT_SIZE - (orderBits & 0x7)); } /* w = s^-1 mod n */ diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index ba5743d2e..06208b64f 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -100,7 +100,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return 0; } - #elif defined(CYASSL_SAFERTOS) + #elif defined(WOLFSSL_SAFERTOS) int InitMutex(wolfSSL_Mutex* m) { @@ -160,7 +160,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return 0; } - #elif defined(CYASSL_PTHREADS) + #elif defined(WOLFSSL_PTHREADS) int InitMutex(wolfSSL_Mutex* m) { @@ -292,7 +292,7 @@ int UnLockMutex(wolfSSL_Mutex *m) int InitMutex(wolfSSL_Mutex* m) { - if (rtp_sig_mutex_alloc(m, "CyaSSL Mutex") == -1) + if (rtp_sig_mutex_alloc(m, "wolfSSL Mutex") == -1) return BAD_MUTEX_E; else return 0; @@ -352,7 +352,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return BAD_MUTEX_E; } - #elif defined (CYASSL_TIRTOS) + #elif defined (WOLFSSL_TIRTOS) int InitMutex(wolfSSL_Mutex* m) { @@ -387,20 +387,20 @@ int UnLockMutex(wolfSSL_Mutex *m) return 0; } - #elif defined(CYASSL_MDK_ARM)|| defined(CYASSL_CMSIS_RTOS) + #elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_CMSIS_RTOS) - #if defined(CYASSL_CMSIS_RTOS) + #if defined(WOLFSSL_CMSIS_RTOS) #include "cmsis_os.h" #define CMSIS_NMUTEX 10 - osMutexDef(CyaSSL_mt0) ; osMutexDef(CyaSSL_mt1) ; osMutexDef(CyaSSL_mt2) ; - osMutexDef(CyaSSL_mt3) ; osMutexDef(CyaSSL_mt4) ; osMutexDef(CyaSSL_mt5) ; - osMutexDef(CyaSSL_mt6) ; osMutexDef(CyaSSL_mt7) ; osMutexDef(CyaSSL_mt8) ; - osMutexDef(CyaSSL_mt9) ; + osMutexDef(wolfSSL_mt0) ; osMutexDef(wolfSSL_mt1) ; osMutexDef(wolfSSL_mt2) ; + osMutexDef(wolfSSL_mt3) ; osMutexDef(wolfSSL_mt4) ; osMutexDef(wolfSSL_mt5) ; + osMutexDef(wolfSSL_mt6) ; osMutexDef(wolfSSL_mt7) ; osMutexDef(wolfSSL_mt8) ; + osMutexDef(wolfSSL_mt9) ; - static const osMutexDef_t *CMSIS_mutex[] = { osMutex(CyaSSL_mt0), - osMutex(CyaSSL_mt1), osMutex(CyaSSL_mt2), osMutex(CyaSSL_mt3), - osMutex(CyaSSL_mt4), osMutex(CyaSSL_mt5), osMutex(CyaSSL_mt6), - osMutex(CyaSSL_mt7), osMutex(CyaSSL_mt8), osMutex(CyaSSL_mt9) } ; + static const osMutexDef_t *CMSIS_mutex[] = { osMutex(wolfSSL_mt0), + osMutex(wolfSSL_mt1), osMutex(wolfSSL_mt2), osMutex(wolfSSL_mt3), + osMutex(wolfSSL_mt4), osMutex(wolfSSL_mt5), osMutex(wolfSSL_mt6), + osMutex(wolfSSL_mt7), osMutex(wolfSSL_mt8), osMutex(wolfSSL_mt9) } ; static osMutexId CMSIS_mutexID[CMSIS_NMUTEX] = {0} ; diff --git a/wolfcrypt/test/test.h b/wolfcrypt/test/test.h index ad02ccaff..81e95be4d 100644 --- a/wolfcrypt/test/test.h +++ b/wolfcrypt/test/test.h @@ -25,7 +25,7 @@ extern "C" { #endif -int ctaocrypt_test(void* args); +int wolfcrypt_test(void* args); #ifdef __cplusplus } /* extern "C" */ diff --git a/wolfssl/wolfcrypt/poly1305.h b/wolfssl/wolfcrypt/poly1305.h index 08797b556..6383b589f 100644 --- a/wolfssl/wolfcrypt/poly1305.h +++ b/wolfssl/wolfcrypt/poly1305.h @@ -27,11 +27,6 @@ #include -/* for poly1305 reverse compatibility */ -#define Poly1305SetKey wc_Poly1305SetKey -#define Poly1305Update wc_Poly1305Update -#define Poly1305Final wc_Poly1305Final - #ifdef __cplusplus extern "C" { #endif diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 0226e72b9..60252d666 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -20,311 +20,322 @@ */ /* Name change compatibility layer */ -#include +//#include -#include #ifndef WOLF_CRYPT_TYPES_H #define WOLF_CRYPT_TYPES_H - #include - #include - -// #ifdef __cplusplus -// extern "C" { -// #endif - - -// #if defined(WORDS_BIGENDIAN) -// #define BIG_ENDIAN_ORDER -// #endif - -// #ifndef BIG_ENDIAN_ORDER -// #define LITTLE_ENDIAN_ORDER -// #endif - -// #ifndef WOLFSSL_TYPES -// #ifndef byte -// typedef unsigned char byte; -// #endif -// typedef unsigned short word16; -// typedef unsigned int word32; -// #endif - - -// /* try to set SIZEOF_LONG or LONG_LONG if user didn't */ -// #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) -// #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) -// #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \ -// || defined(__mips64) || defined(__x86_64__)) -// /* long should be 64bit */ -// #define SIZEOF_LONG 8 -// #elif defined(__i386__) || defined(__CORTEX_M3__) -// /* long long should be 64bit */ -// #define SIZEOF_LONG_LONG 8 -// #endif -// #endif -// #endif - - -// #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) -// #define WORD64_AVAILABLE -// #define W64LIT(x) x##ui64 -// typedef unsigned __int64 word64; -// #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8 -// #define WORD64_AVAILABLE -// #define W64LIT(x) x##LL -// typedef unsigned long word64; -// #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8 -// #define WORD64_AVAILABLE -// #define W64LIT(x) x##LL -// typedef unsigned long long word64; -// #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8 -// #define WORD64_AVAILABLE -// #define W64LIT(x) x##LL -// typedef unsigned long long word64; -// #else -// #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as -// mp_digit, no 64 bit type so make mp_digit 16 bit */ -// #endif - - -// /* These platforms have 64-bit CPU registers. */ -// #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ -// defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) -// typedef word64 wolfssl_word; -// #else -// typedef word32 wolfssl_word; -// #ifdef WORD64_AVAILABLE -// #define WOLFCRYPT_SLOW_WORD64 -// #endif -// #endif - - -// enum { -// WOLFSSL_WORD_SIZE = sizeof(wolfssl_word), -// WOLFSSL_BIT_SIZE = 8, -// WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE -// }; - -// #define WOLFSSL_MAX_16BIT 0xffffU - -// /* use inlining if compiler allows */ -// #ifndef INLINE -// #ifndef NO_INLINE -// #ifdef _MSC_VER -// #define INLINE __inline -// #elif defined(__GNUC__) -// #define INLINE inline -// #elif defined(__IAR_SYSTEMS_ICC__) -// #define INLINE inline -// #elif defined(THREADX) -// #define INLINE _Inline -// #else -// #define INLINE -// #endif -// #else -// #define INLINE -// #endif -// #endif - - -// /* set up rotate style */ -// #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) -// #define INTEL_INTRINSICS -// #define FAST_ROTATE -// #elif defined(__MWERKS__) && TARGET_CPU_PPC -// #define PPC_INTRINSICS -// #define FAST_ROTATE -// #elif defined(__GNUC__) && defined(__i386__) -// /* GCC does peephole optimizations which should result in using rotate -// instructions */ -// #define FAST_ROTATE -// #endif - - -// /* set up thread local storage if available */ -// #ifdef HAVE_THREAD_LS -// #if defined(_MSC_VER) -// #define THREAD_LS_T __declspec(thread) -// #else -// #define THREAD_LS_T __thread -// #endif -// #else -// #define THREAD_LS_T -// #endif - - -// /* Micrium will use Visual Studio for compilation but not the Win32 API */ -// #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) \ -// && !defined(EBSNET) -// #define USE_WINDOWS_API -// #endif - - -// /* idea to add global alloc override by Moisés Guimarães */ -// /* default to libc stuff */ -// /* XREALLOC is used once in normal math lib, not in fast math lib */ -// /* XFREE on some embeded systems doesn't like free(0) so test */ -// #if defined(XMALLOC_USER) -// /* prototypes for user heap override functions */ -// #include /* for size_t */ -// extern void *XMALLOC(size_t n, void* heap, int type); -// extern void *XREALLOC(void *p, size_t n, void* heap, int type); -// extern void XFREE(void *p, void* heap, int type); -// #elif defined(NO_WOLFSSL_MEMORY) -// /* just use plain C stdlib stuff if desired */ -// #include -// #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) -// #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} -// #define XREALLOC(p, n, h, t) realloc((p), (n)) -// #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \ -// && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \ -// && !defined(WOLFSSL_LEANPSK) -// /* default C runtime, can install different routines at runtime via cbs */ -// #include -// #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) -// #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} -// #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n)) -// #endif - -// #ifndef STRING_USER -// #include -// char* mystrnstr(const char* s1, const char* s2, unsigned int n); - -// #define XMEMCPY(d,s,l) memcpy((d),(s),(l)) -// #define XMEMSET(b,c,l) memset((b),(c),(l)) -// #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n)) -// #define XMEMMOVE(d,s,l) memmove((d),(s),(l)) - -// #define XSTRLEN(s1) strlen((s1)) -// #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n)) -// /* strstr, strncmp, and strncat only used by wolfSSL proper, not required for -// CTaoCrypt only */ -// #define XSTRSTR(s1,s2) strstr((s1),(s2)) -// #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n)) -// #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n)) -// #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n)) -// #ifndef USE_WINDOWS_API -// #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n)) -// #define XSNPRINTF snprintf -// #else -// #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n)) -// #define XSNPRINTF _snprintf -// #endif -// #endif - -// #ifndef CTYPE_USER -// #include -// #if defined(HAVE_ECC) || defined(HAVE_OCSP) -// #define XTOUPPER(c) toupper((c)) -// #define XISALPHA(c) isalpha((c)) -// #endif -// /* needed by wolfSSL_check_domain_name() */ -// #ifdef __CYGWIN__ -// /* Cygwin uses a macro version of tolower() by default, use the -// * function version. */ -// #undef tolower -// #endif -// #define XTOLOWER(c) tolower((c)) -// #endif - - -// /* memory allocation types for user hints */ -// enum { -// DYNAMIC_TYPE_CA = 1, -// DYNAMIC_TYPE_CERT = 2, -// DYNAMIC_TYPE_KEY = 3, -// DYNAMIC_TYPE_FILE = 4, -// DYNAMIC_TYPE_SUBJECT_CN = 5, -// DYNAMIC_TYPE_PUBLIC_KEY = 6, -// DYNAMIC_TYPE_SIGNER = 7, -// DYNAMIC_TYPE_NONE = 8, -// DYNAMIC_TYPE_BIGINT = 9, -// DYNAMIC_TYPE_RSA = 10, -// DYNAMIC_TYPE_METHOD = 11, -// DYNAMIC_TYPE_OUT_BUFFER = 12, -// DYNAMIC_TYPE_IN_BUFFER = 13, -// DYNAMIC_TYPE_INFO = 14, -// DYNAMIC_TYPE_DH = 15, -// DYNAMIC_TYPE_DOMAIN = 16, -// DYNAMIC_TYPE_SSL = 17, -// DYNAMIC_TYPE_CTX = 18, -// DYNAMIC_TYPE_WRITEV = 19, -// DYNAMIC_TYPE_OPENSSL = 20, -// DYNAMIC_TYPE_DSA = 21, -// DYNAMIC_TYPE_CRL = 22, -// DYNAMIC_TYPE_REVOKED = 23, -// DYNAMIC_TYPE_CRL_ENTRY = 24, -// DYNAMIC_TYPE_CERT_MANAGER = 25, -// DYNAMIC_TYPE_CRL_MONITOR = 26, -// DYNAMIC_TYPE_OCSP_STATUS = 27, -// DYNAMIC_TYPE_OCSP_ENTRY = 28, -// DYNAMIC_TYPE_ALTNAME = 29, -// DYNAMIC_TYPE_SUITES = 30, -// DYNAMIC_TYPE_CIPHER = 31, -// DYNAMIC_TYPE_RNG = 32, -// DYNAMIC_TYPE_ARRAYS = 33, -// DYNAMIC_TYPE_DTLS_POOL = 34, -// DYNAMIC_TYPE_SOCKADDR = 35, -// DYNAMIC_TYPE_LIBZ = 36, -// DYNAMIC_TYPE_ECC = 37, -// DYNAMIC_TYPE_TMP_BUFFER = 38, -// DYNAMIC_TYPE_DTLS_MSG = 39, -// DYNAMIC_TYPE_CAVIUM_TMP = 40, -// DYNAMIC_TYPE_CAVIUM_RSA = 41, -// DYNAMIC_TYPE_X509 = 42, -// DYNAMIC_TYPE_TLSX = 43, -// DYNAMIC_TYPE_OCSP = 44, -// DYNAMIC_TYPE_SIGNATURE = 45 -// }; - -// /* max error buffer string size */ -// enum { -// WOLFSSL_MAX_ERROR_SZ = 80 -// }; - -// /* stack protection */ -// enum { -// MIN_STACK_BUFFER = 8 -// }; - - - -// /* settings detection for compile vs runtime math incombatibilities */ -// enum { -// #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG) -// CTC_SETTINGS = 0x0 -// #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8) -// CTC_SETTINGS = 0x1 -// #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8) -// CTC_SETTINGS = 0x2 -// #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4) -// CTC_SETTINGS = 0x4 -// #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG) -// CTC_SETTINGS = 0x8 -// #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8) -// CTC_SETTINGS = 0x10 -// #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8) -// CTC_SETTINGS = 0x20 -// #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4) -// CTC_SETTINGS = 0x40 -// #else -// #error "bad math long / long long settings" -// #endif -// }; - - -// WOLFSSL_API word32 CheckRunTimeSettings(void); - -// /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long -// types need to match at compile time and run time, CheckCtcSettings will -// return 1 if a match otherwise 0 */ -// #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings()) - - -// #ifdef __cplusplus -// } /* extern "C" */ -// #endif - - +/* for fips compatiblity @wc_fips */ +#ifdef HAVE_FIPS + #include +#else + /* set old macros since this is often called for visibility also */ + #ifndef CYASSL_API + #define CYASSL_API WOLFSSL_API + #endif + #ifndef CYASSL_LOCAL + #define CYASSL_LOCAL WOLFSSL_LOCAL + #endif + + #include + #include + + #ifdef __cplusplus + extern "C" { + #endif + + + #if defined(WORDS_BIGENDIAN) + #define BIG_ENDIAN_ORDER + #endif + + #ifndef BIG_ENDIAN_ORDER + #define LITTLE_ENDIAN_ORDER + #endif + + #ifndef WOLFSSL_TYPES + #ifndef byte + typedef unsigned char byte; + #endif + typedef unsigned short word16; + typedef unsigned int word32; + #endif + + + /* try to set SIZEOF_LONG or LONG_LONG if user didn't */ + #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) + #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) + #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \ + || defined(__mips64) || defined(__x86_64__)) + /* long should be 64bit */ + #define SIZEOF_LONG 8 + #elif defined(__i386__) || defined(__CORTEX_M3__) + /* long long should be 64bit */ + #define SIZEOF_LONG_LONG 8 + #endif + #endif + #endif + + + #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) + #define WORD64_AVAILABLE + #define W64LIT(x) x##ui64 + typedef unsigned __int64 word64; + #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8 + #define WORD64_AVAILABLE + #define W64LIT(x) x##LL + typedef unsigned long word64; + #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8 + #define WORD64_AVAILABLE + #define W64LIT(x) x##LL + typedef unsigned long long word64; + #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8 + #define WORD64_AVAILABLE + #define W64LIT(x) x##LL + typedef unsigned long long word64; + #else + #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as + mp_digit, no 64 bit type so make mp_digit 16 bit */ + #endif + + + /* These platforms have 64-bit CPU registers. */ + #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ + defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) + typedef word64 wolfssl_word; + #else + typedef word32 wolfssl_word; + #ifdef WORD64_AVAILABLE + #define WOLFCRYPT_SLOW_WORD64 + #endif + #endif + + + enum { + WOLFSSL_WORD_SIZE = sizeof(wolfssl_word), + WOLFSSL_BIT_SIZE = 8, + WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE + }; + + #define WOLFSSL_MAX_16BIT 0xffffU + + /* use inlining if compiler allows */ + #ifndef INLINE + #ifndef NO_INLINE + #ifdef _MSC_VER + #define INLINE __inline + #elif defined(__GNUC__) + #define INLINE inline + #elif defined(__IAR_SYSTEMS_ICC__) + #define INLINE inline + #elif defined(THREADX) + #define INLINE _Inline + #else + #define INLINE + #endif + #else + #define INLINE + #endif + #endif + + + /* set up rotate style */ + #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) + #define INTEL_INTRINSICS + #define FAST_ROTATE + #elif defined(__MWERKS__) && TARGET_CPU_PPC + #define PPC_INTRINSICS + #define FAST_ROTATE + #elif defined(__GNUC__) && defined(__i386__) + /* GCC does peephole optimizations which should result in using rotate + instructions */ + #define FAST_ROTATE + #endif + + + /* set up thread local storage if available */ + #ifdef HAVE_THREAD_LS + #if defined(_MSC_VER) + #define THREAD_LS_T __declspec(thread) + #else + #define THREAD_LS_T __thread + #endif + #else + #define THREAD_LS_T + #endif + + + /* Micrium will use Visual Studio for compilation but not the Win32 API */ + #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) \ + && !defined(EBSNET) + #define USE_WINDOWS_API + #endif + + + /* idea to add global alloc override by Moisés Guimarães */ + /* default to libc stuff */ + /* XREALLOC is used once in normal math lib, not in fast math lib */ + /* XFREE on some embeded systems doesn't like free(0) so test */ + #if defined(XMALLOC_USER) + /* prototypes for user heap override functions */ + #include /* for size_t */ + extern void *XMALLOC(size_t n, void* heap, int type); + extern void *XREALLOC(void *p, size_t n, void* heap, int type); + extern void XFREE(void *p, void* heap, int type); + #elif defined(NO_WOLFSSL_MEMORY) + /* just use plain C stdlib stuff if desired */ + #include + #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) + #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} + #define XREALLOC(p, n, h, t) realloc((p), (n)) + #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \ + && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \ + && !defined(WOLFSSL_LEANPSK) + /* default C runtime, can install different routines at runtime via cbs */ + #include + #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) + #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} + #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n)) + #endif + + #ifndef STRING_USER + #include + char* mystrnstr(const char* s1, const char* s2, unsigned int n); + + #define XMEMCPY(d,s,l) memcpy((d),(s),(l)) + #define XMEMSET(b,c,l) memset((b),(c),(l)) + #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n)) + #define XMEMMOVE(d,s,l) memmove((d),(s),(l)) + + #define XSTRLEN(s1) strlen((s1)) + #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n)) + /* strstr, strncmp, and strncat only used by wolfSSL proper, not required for + CTaoCrypt only */ + #define XSTRSTR(s1,s2) strstr((s1),(s2)) + #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n)) + #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n)) + #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n)) + #ifndef USE_WINDOWS_API + #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n)) + #define XSNPRINTF snprintf + #else + #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n)) + #define XSNPRINTF _snprintf + #endif + #endif + + #ifndef CTYPE_USER + #include + #if defined(HAVE_ECC) || defined(HAVE_OCSP) + #define XTOUPPER(c) toupper((c)) + #define XISALPHA(c) isalpha((c)) + #endif + /* needed by wolfSSL_check_domain_name() */ + #ifdef __CYGWIN__ + /* Cygwin uses a macro version of tolower() by default, use the + * function version. */ + #undef tolower + #endif + #define XTOLOWER(c) tolower((c)) + #endif + + + /* memory allocation types for user hints */ + enum { + DYNAMIC_TYPE_CA = 1, + DYNAMIC_TYPE_CERT = 2, + DYNAMIC_TYPE_KEY = 3, + DYNAMIC_TYPE_FILE = 4, + DYNAMIC_TYPE_SUBJECT_CN = 5, + DYNAMIC_TYPE_PUBLIC_KEY = 6, + DYNAMIC_TYPE_SIGNER = 7, + DYNAMIC_TYPE_NONE = 8, + DYNAMIC_TYPE_BIGINT = 9, + DYNAMIC_TYPE_RSA = 10, + DYNAMIC_TYPE_METHOD = 11, + DYNAMIC_TYPE_OUT_BUFFER = 12, + DYNAMIC_TYPE_IN_BUFFER = 13, + DYNAMIC_TYPE_INFO = 14, + DYNAMIC_TYPE_DH = 15, + DYNAMIC_TYPE_DOMAIN = 16, + DYNAMIC_TYPE_SSL = 17, + DYNAMIC_TYPE_CTX = 18, + DYNAMIC_TYPE_WRITEV = 19, + DYNAMIC_TYPE_OPENSSL = 20, + DYNAMIC_TYPE_DSA = 21, + DYNAMIC_TYPE_CRL = 22, + DYNAMIC_TYPE_REVOKED = 23, + DYNAMIC_TYPE_CRL_ENTRY = 24, + DYNAMIC_TYPE_CERT_MANAGER = 25, + DYNAMIC_TYPE_CRL_MONITOR = 26, + DYNAMIC_TYPE_OCSP_STATUS = 27, + DYNAMIC_TYPE_OCSP_ENTRY = 28, + DYNAMIC_TYPE_ALTNAME = 29, + DYNAMIC_TYPE_SUITES = 30, + DYNAMIC_TYPE_CIPHER = 31, + DYNAMIC_TYPE_RNG = 32, + DYNAMIC_TYPE_ARRAYS = 33, + DYNAMIC_TYPE_DTLS_POOL = 34, + DYNAMIC_TYPE_SOCKADDR = 35, + DYNAMIC_TYPE_LIBZ = 36, + DYNAMIC_TYPE_ECC = 37, + DYNAMIC_TYPE_TMP_BUFFER = 38, + DYNAMIC_TYPE_DTLS_MSG = 39, + DYNAMIC_TYPE_CAVIUM_TMP = 40, + DYNAMIC_TYPE_CAVIUM_RSA = 41, + DYNAMIC_TYPE_X509 = 42, + DYNAMIC_TYPE_TLSX = 43, + DYNAMIC_TYPE_OCSP = 44, + DYNAMIC_TYPE_SIGNATURE = 45 + }; + + /* max error buffer string size */ + enum { + WOLFSSL_MAX_ERROR_SZ = 80 + }; + + /* stack protection */ + enum { + MIN_STACK_BUFFER = 8 + }; + + + + /* settings detection for compile vs runtime math incombatibilities */ + enum { + #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG) + CTC_SETTINGS = 0x0 + #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8) + CTC_SETTINGS = 0x1 + #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8) + CTC_SETTINGS = 0x2 + #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4) + CTC_SETTINGS = 0x4 + #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG) + CTC_SETTINGS = 0x8 + #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8) + CTC_SETTINGS = 0x10 + #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8) + CTC_SETTINGS = 0x20 + #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4) + CTC_SETTINGS = 0x40 + #else + #error "bad math long / long long settings" + #endif + }; + + + WOLFSSL_API word32 CheckRunTimeSettings(void); + + /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long + types need to match at compile time and run time, CheckCtcSettings will + return 1 if a match otherwise 0 */ + #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings()) + + + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /* HAVE_FIPS */ #endif /* WOLF_CRYPT_TYPES_H */ diff --git a/wolfssl/wolfcrypt/visibility.h b/wolfssl/wolfcrypt/visibility.h index 3908c8bf1..40d993688 100644 --- a/wolfssl/wolfcrypt/visibility.h +++ b/wolfssl/wolfcrypt/visibility.h @@ -31,7 +31,7 @@ WOLFSSL_LOCAL is used for non-API symbols (private). */ -//#if defined(BUILDING_WOLFSSL) +#if defined(BUILDING_WOLFSSL) #if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY #define WOLFSSL_API __attribute__ ((visibility("default"))) #define WOLFSSL_LOCAL __attribute__ ((visibility("hidden"))) @@ -49,19 +49,19 @@ #define WOLFSSL_API #define WOLFSSL_LOCAL #endif /* HAVE_VISIBILITY */ -//#else /* BUILDING_WOLFSSL */ -// #if defined(_MSC_VER) -// #ifdef WOLFSSL_DLL -// #define WOLFSSL_API extern __declspec(dllimport) -// #else -// #define WOLFSSL_API -// #endif -// #define WOLFSSL_LOCAL -// #else -// #define WOLFSSL_API -// #define WOLFSSL_LOCAL -// #endif -//#endif /* BUILDING_WOLFSSL */ +#else /* BUILDING_WOLFSSL */ + #if defined(_MSC_VER) + #ifdef WOLFSSL_DLL + #define WOLFSSL_API extern __declspec(dllimport) + #else + #define WOLFSSL_API + #endif + #define WOLFSSL_LOCAL + #else + #define WOLFSSL_API + #define WOLFSSL_LOCAL + #endif +#endif /* BUILDING_WOLFSSL */ #endif /* WOLF_CRYPT_VISIBILITY_H */