From 3c2155f4a90bad7b3e6a31844f532d29ca25cc2d Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Thu, 13 Aug 2020 14:42:01 -0500 Subject: [PATCH] linuxkm WIP -- update for kernels 4.9.x (LTS representative) and 5.8.x (latest). --- .gitignore | 1 + src/internal.c | 4 +- src/ssl.c | 3 +- src/tls13.c | 15 +++++ src/wolfio.c | 2 +- wolfcrypt/src/asn.c | 33 ++++++++++- wolfcrypt/src/fe_448.c | 2 + wolfcrypt/src/fe_operations.c | 2 + wolfcrypt/src/random.c | 21 ------- wolfcrypt/src/sha3.c | 4 +- wolfcrypt/src/wc_port.c | 41 ++++++++++--- wolfssl/wolfcrypt/blake2-int.h | 10 ++-- wolfssl/wolfcrypt/fe_448.h | 2 + wolfssl/wolfcrypt/fe_operations.h | 2 + wolfssl/wolfcrypt/random.h | 28 +++++---- wolfssl/wolfcrypt/sp.h | 2 + wolfssl/wolfcrypt/sp_int.h | 2 + wolfssl/wolfcrypt/types.h | 14 +++-- wolfssl/wolfcrypt/wc_port.h | 97 +++++++++++++++++++++++++++++-- wolfssl/wolfio.h | 2 +- 20 files changed, 219 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 2d534cda7..f35d17bca 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ctaocrypt/src/src/ *.o *.patch *.deps +*.d *.libs *.cache .dirstamp diff --git a/src/internal.c b/src/internal.c index b16ff32c5..265e4f683 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7652,9 +7652,7 @@ ProtocolVersion MakeDTLSv1_2(void) #include word32 LowResTimer(void) { - struct timespec ts; - getnstimeofday(&ts); - return ts.tv_sec * 1000000000LL + ts.tv_nsec; + return (word32)ktime_get_real_ns(); } #else diff --git a/src/ssl.c b/src/ssl.c index b5978f151..0003cace3 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -34,11 +34,12 @@ #if !defined(WOLFCRYPT_ONLY) || defined(OPENSSL_EXTRA) || \ defined(OPENSSL_EXTRA_X509_SMALL) +#include + #ifdef HAVE_ERRNO_H #include #endif -#include #include #include #ifdef NO_INLINE diff --git a/src/tls13.c b/src/tls13.c index ca92588f3..ca7c7ea38 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -1346,6 +1346,21 @@ end: { return (word32)(uTaskerSystemTick / (TICK_RESOLUTION / 1000)); } +#elif defined(WOLFSSL_LINUXKM) + /* The time in milliseconds. + * Used for tickets to represent difference between when first seen and when + * sending. + * + * returns the time in milliseconds as a 32-bit value. + */ + word32 TimeNowInMilliseconds(void) + { + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) + return (word32)(ktime_get_real_ns() / (s64)1000000); + #else + return (word32)(ktime_get_real_ns() / (ktime_t)1000000); + #endif + } #else /* The time in milliseconds. * Used for tickets to represent difference between when first seen and when diff --git a/src/wolfio.c b/src/wolfio.c index e00c87ea5..d5f5bf3da 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -465,7 +465,7 @@ int EmbedReceiveFromMcast(WOLFSSL *ssl, char *buf, int sz, void *ctx) recvd = TranslateReturnCode(recvd, sd); if (recvd < 0) { - err = wolfSSL_LastError(); + err = wolfSSL_LastError(recvd); WOLFSSL_MSG("Embed Receive From error"); if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) { diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index f6213ff9e..067a60511 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -6108,6 +6108,25 @@ static WC_INLINE int GetTime(int* value, const byte* date, int* idx) return 0; } +#ifdef WOLFSSL_LINUXKM +static WC_INLINE int GetTime_Long(long* value, const byte* date, int* idx) +{ + int i = *idx; + + if (date[i] < 0x30 || date[i] > 0x39 || date[i+1] < 0x30 || + date[i+1] > 0x39) { + return ASN_PARSE_E; + } + + *value += (long)btoi(date[i++]) * 10; + *value += (long)btoi(date[i++]); + + *idx = i; + + return 0; +} +#endif + int ExtractDate(const unsigned char* date, unsigned char format, struct tm* certTime, int* idx) { @@ -6120,7 +6139,11 @@ int ExtractDate(const unsigned char* date, unsigned char format, certTime->tm_year = 2000; } else { /* format == GENERALIZED_TIME */ +#ifdef WOLFSSL_LINUXKM + if (GetTime_Long(&certTime->tm_year, date, idx) != 0) return 0; +#else if (GetTime(&certTime->tm_year, date, idx) != 0) return 0; +#endif certTime->tm_year *= 100; } @@ -6135,7 +6158,11 @@ int ExtractDate(const unsigned char* date, unsigned char format, int tm_min = certTime->tm_min; int tm_sec = certTime->tm_sec; +#ifdef WOLFSSL_LINUXKM + if (GetTime_Long(&tm_year, date, idx) != 0) return 0; +#else if (GetTime(&tm_year, date, idx) != 0) return 0; +#endif if (GetTime(&tm_mon , date, idx) != 0) return 0; if (GetTime(&tm_mday, date, idx) != 0) return 0; if (GetTime(&tm_hour, date, idx) != 0) return 0; @@ -6151,7 +6178,11 @@ int ExtractDate(const unsigned char* date, unsigned char format, certTime->tm_sec = tm_sec; #else /* adjust tm_year, tm_mon */ +#ifdef WOLFSSL_LINUXKM + if (GetTime_Long(&certTime->tm_year, date, idx) != 0) return 0; +#else if (GetTime(&certTime->tm_year, date, idx) != 0) return 0; +#endif certTime->tm_year -= 1900; if (GetTime(&certTime->tm_mon , date, idx) != 0) return 0; certTime->tm_mon -= 1; @@ -6203,7 +6234,7 @@ int GetTimeString(byte* date, int format, char* buf, int len) idx = 4; /* use idx now for char buffer */ XSNPRINTF(buf + idx, len - idx, "%2d %02d:%02d:%02d %d GMT", - t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, t.tm_year + 1900); + t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, (int)t.tm_year + 1900); return 1; } diff --git a/wolfcrypt/src/fe_448.c b/wolfcrypt/src/fe_448.c index cf0ee7c93..cd93bcb83 100644 --- a/wolfcrypt/src/fe_448.c +++ b/wolfcrypt/src/fe_448.c @@ -33,7 +33,9 @@ #if defined(HAVE_CURVE448) || defined(HAVE_ED448) #include +#ifndef WOLFSSL_LINUXKM #include +#endif #ifdef NO_INLINE #include diff --git a/wolfcrypt/src/fe_operations.c b/wolfcrypt/src/fe_operations.c index 691b344e8..2da2a9e5e 100644 --- a/wolfcrypt/src/fe_operations.c +++ b/wolfcrypt/src/fe_operations.c @@ -32,7 +32,9 @@ #if !defined(CURVE25519_SMALL) || !defined(ED25519_SMALL) /* run when not defined to use small memory math */ #include +#ifndef WOLFSSL_LINUXKM #include +#endif #ifdef NO_INLINE #include diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index a473b887f..9639efcde 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -309,23 +309,6 @@ enum { drbgInitV }; -/* NOTE: if DRBG struct is changed please update random.h drbg_data size */ -typedef struct DRBG { - word32 reseedCtr; - word32 lastBlock; - byte V[DRBG_SEED_LEN]; - byte C[DRBG_SEED_LEN]; -#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB) - void* heap; - int devId; -#endif - byte matchCount; -#ifdef WOLFSSL_SMALL_STACK_CACHE - wc_Sha256 sha256; -#endif -} DRBG; - - static int wc_RNG_HealthTestLocal(int reseed); /* Hash Derivation Function */ @@ -808,10 +791,6 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz, rng->status = DRBG_FAILED; } #else - /* compile-time validation of drbg_data size */ - typedef char drbg_data_test[sizeof(rng->drbg_data) >= - sizeof(struct DRBG) ? 1 : -1]; - (void)sizeof(drbg_data_test); rng->drbg = (struct DRBG*)rng->drbg_data; #endif if (ret == 0) { diff --git a/wolfcrypt/src/sha3.c b/wolfcrypt/src/sha3.c index 78158b8f4..8cd9c9d58 100644 --- a/wolfcrypt/src/sha3.c +++ b/wolfcrypt/src/sha3.c @@ -639,7 +639,7 @@ static int Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p) static int Sha3Final(wc_Sha3* sha3, byte padChar, byte* hash, byte p, byte l) { byte i; - byte *s8 = (byte *)sha3->s; + byte *state = (byte *)sha3->s; sha3->t[p * 8 - 1] = 0x00; #ifdef WOLFSSL_HASH_FLAGS @@ -658,7 +658,7 @@ static int Sha3Final(wc_Sha3* sha3, byte padChar, byte* hash, byte p, byte l) ByteReverseWords64(sha3->s, sha3->s, ((l+7)/8)*8); #endif for (i = 0; i < l; i++) - hash[i] = s8[i]; + hash[i] = state[i]; return 0; } diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index ff679f153..0b3e5573b 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -1050,6 +1050,33 @@ int wolfSSL_CryptHwMutexUnLock(void) return BAD_MUTEX_E; } +#elif defined(WOLFSSL_KTHREADS) + + int wc_InitMutex(wolfSSL_Mutex* m) + { + mutex_init(m); + return 0; + } + + int wc_FreeMutex(wolfSSL_Mutex* m) + { + mutex_destroy(m); + return 0; + } + + int wc_LockMutex(wolfSSL_Mutex* m) + { + mutex_lock(m); + return 0; + } + + + int wc_UnLockMutex(wolfSSL_Mutex* m) + { + mutex_unlock(m); + return 0; + } + #elif defined(WOLFSSL_VXWORKS) int wc_InitMutex(wolfSSL_Mutex* m) @@ -2263,16 +2290,12 @@ time_t wiced_pseudo_unix_epoch_time(time_t * timer) #if defined(WOLFSSL_LINUXKM) -unsigned long long GetUNIXCompatibleTime(void) +time_t time(time_t * timer) { - struct timespec ts; - getnstimeofday(&ts); - return ts.tv_sec * 1000000000LL + ts.tv_nsec; -} - -time_t XTIME(time_t * timer) -{ - return (time_t) (GetUNIXCompatibleTime() / 1000000000LL); + time_t ret = ktime_get_real_seconds(); + if (timer) + *timer = ret; + return ret; } #endif /* WOLFSSL_LINUXKM */ diff --git a/wolfssl/wolfcrypt/blake2-int.h b/wolfssl/wolfcrypt/blake2-int.h index 6f5610dc7..ec921ceb4 100644 --- a/wolfssl/wolfcrypt/blake2-int.h +++ b/wolfssl/wolfcrypt/blake2-int.h @@ -41,11 +41,11 @@ #if defined(_MSC_VER) - #define ALIGN(x) __declspec(align(x)) + #define ALIGN_TO(x) __declspec(align(x)) #elif defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) - #define ALIGN(x) __attribute__((aligned(x))) + #define ALIGN_TO(x) __attribute__((aligned(x))) #else - #define ALIGN(x) + #define ALIGN_TO(x) #endif @@ -87,7 +87,7 @@ byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */ } blake2s_param; - ALIGN( 32 ) typedef struct __blake2s_state + ALIGN_TO( 32 ) typedef struct __blake2s_state { word32 h[8]; word32 t[2]; @@ -112,7 +112,7 @@ byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */ } blake2b_param; - ALIGN( 64 ) typedef struct __blake2b_state + ALIGN_TO( 64 ) typedef struct __blake2b_state { word64 h[8]; word64 t[2]; diff --git a/wolfssl/wolfcrypt/fe_448.h b/wolfssl/wolfcrypt/fe_448.h index 14191346a..352311609 100644 --- a/wolfssl/wolfcrypt/fe_448.h +++ b/wolfssl/wolfcrypt/fe_448.h @@ -27,7 +27,9 @@ #if defined(HAVE_CURVE448) || defined(HAVE_ED448) +#ifndef WOLFSSL_LINUXKM #include +#endif #include diff --git a/wolfssl/wolfcrypt/fe_operations.h b/wolfssl/wolfcrypt/fe_operations.h index 5e01eb83b..73d130579 100644 --- a/wolfssl/wolfcrypt/fe_operations.h +++ b/wolfssl/wolfcrypt/fe_operations.h @@ -28,8 +28,10 @@ #if defined(HAVE_CURVE25519) || defined(HAVE_ED25519) #if !defined(CURVE25519_SMALL) || !defined(ED25519_SMALL) +#ifndef WOLFSSL_LINUXKM #include #endif +#endif #include diff --git a/wolfssl/wolfcrypt/random.h b/wolfssl/wolfcrypt/random.h index aefd44e37..d2665dda8 100644 --- a/wolfssl/wolfcrypt/random.h +++ b/wolfssl/wolfcrypt/random.h @@ -149,6 +149,21 @@ typedef struct OS_Seed { #define WC_RNG_TYPE_DEFINED #endif +typedef struct DRBG { + word32 reseedCtr; + word32 lastBlock; + byte V[DRBG_SEED_LEN]; + byte C[DRBG_SEED_LEN]; +#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB) + void* heap; + int devId; +#endif + byte matchCount; +#ifdef WOLFSSL_SMALL_STACK_CACHE + wc_Sha256 sha256; +#endif +} DRBG; + /* RNG context */ struct WC_RNG { OS_Seed seed; @@ -157,18 +172,7 @@ struct WC_RNG { /* Hash-based Deterministic Random Bit Generator */ struct DRBG* drbg; #if defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_STATIC_MEMORY) - #define DRBG_STRUCT_SZ ((sizeof(word32)*3) + (DRBG_SEED_LEN*2)) - #ifdef WOLFSSL_SMALL_STACK_CACHE - #define DRBG_STRUCT_SZ_SHA256 (sizeof(wc_Sha256)) - #else - #define DRBG_STRUCT_SZ_SHA256 0 - #endif - #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB) - #define DRBG_STRUCT_SZ_ASYNC (sizeof(void*) + sizeof(int)) - #else - #define DRBG_STRUCT_SZ_ASYNC 0 - #endif - byte drbg_data[DRBG_STRUCT_SZ + DRBG_STRUCT_SZ_SHA256 + DRBG_STRUCT_SZ_ASYNC]; + byte drbg_data[sizeof(DRBG)]; #endif byte status; #endif diff --git a/wolfssl/wolfcrypt/sp.h b/wolfssl/wolfcrypt/sp.h index 9b769bb34..2c7ef2b5e 100644 --- a/wolfssl/wolfcrypt/sp.h +++ b/wolfssl/wolfcrypt/sp.h @@ -28,7 +28,9 @@ #if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH) || \ defined(WOLFSSL_HAVE_SP_ECC) +#ifndef WOLFSSL_LINUXKM #include +#endif #include #include diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index 7d546e12c..01c9ed5d0 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -27,8 +27,10 @@ This library provides single precision (SP) integer math functions. #ifndef WOLF_CRYPT_SP_INT_H #define WOLF_CRYPT_SP_INT_H +#ifndef WOLFSSL_LINUXKM #include #include +#endif /* Make sure WOLFSSL_SP_ASM build option defined when requested */ #if !defined(WOLFSSL_SP_ASM) && ( \ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 577f3a54d..e613b5151 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -249,7 +249,11 @@ decouple library dependencies with standard string, memory and so on. #if defined(__GNUC__) #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1))) #undef FALL_THROUGH - #define FALL_THROUGH __attribute__ ((fallthrough)); + #if defined(WOLFSSL_LINUXKM) && defined(fallthrough) + #define FALL_THROUGH fallthrough + #else + #define FALL_THROUGH __attribute__ ((fallthrough)); + #endif #endif #endif #endif /* FALL_THROUGH */ @@ -583,11 +587,9 @@ decouple library dependencies with standard string, memory and so on. #endif /* OPENSSL_EXTRA */ #ifndef CTYPE_USER - #if defined(WOLFSSL_LINUXKM) - #include - #else - #include - #endif + #ifndef WOLFSSL_LINUXKM + #include + #endif #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \ defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA) #define XTOUPPER(c) toupper((c)) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index fadae9503..af7a12c18 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -54,6 +54,84 @@ #endif #endif +#ifdef WOLFSSL_LINUXKM + +/* +note, leaving out --enable-pkcs11 in this (depends on -ldl): + +KROOT=/usr/src/linux KARCH=x86 CFLAGS="-I${KROOT}/include -I${KROOT}/arch/${KARCH}/include -I${KROOT}/arch/${KARCH}/include/generated -I${KROOT}/arch/${KARCH}/include/generated/uapi -I${KROOT}/arch/${KARCH}/include/uapi -I${KROOT}/include/uapi -I${KROOT}/tools/include/uapi -I${KROOT}/tools/arch/${KARCH}/include -I${KROOT}/tools/include -I/usr/lib/gcc/${KARCH}_64-pc-linux-gnu/9.3.0/include" ./configure --disable-jobserver --enable-keygen --enable-tls13 --enable-dtls --enable-dtls-mtu --enable-openssh --enable-wpas --enable-wpas-dpp --enable-opensslall --enable-opensslextra --enable-aesccm --enable-aesctr --enable-aesofb --enable-intelasm --enable-sp --enable-sp-asm --enable-curve25519 --enable-ed25519 --enable-curve448 --enable-blake2 --enable-blake2s --enable-camellia --enable-ed448 --enable-hc128 --enable-idea --enable-md2 --enable-rabbit --enable-srp --enable-fpecc --enable-certreq --enable-certgen --enable-certext --enable-certgencache --enable-eccencrypt --enable-mcast --enable-ssh --enable-pkcs7 --enable-pkcallbacks --enable-cryptocb --enable-libwebsockets --enable-linuxkm + +(run with and without --enable-fpecc, and with and without --enable-intelasm --enable-sp --enable-sp-asm) + +probably better if lib objs are compiled -ffreestanding -nostdinc. + +building so far: + +make -j 24 src/crl.o src/internal.o src/keys.o src/ocsp.o src/sniffer.o src/ssl.o src/tls13.o wolfcrypt/src/aes.o wolfcrypt/src/arc4.o wolfcrypt/src/asm.o wolfcrypt/src/asn.o wolfcrypt/src/async.o wolfcrypt/src/blake2b.o wolfcrypt/src/blake2s.o wolfcrypt/src/camellia.o wolfcrypt/src/chacha20_poly1305.o wolfcrypt/src/chacha.o wolfcrypt/src/cmac.o wolfcrypt/src/coding.o wolfcrypt/src/compress.o wolfcrypt/src/cpuid.o wolfcrypt/src/cryptocb.o wolfcrypt/src/curve25519.o wolfcrypt/src/curve448.o wolfcrypt/src/des3.o wolfcrypt/src/dh.o wolfcrypt/src/dsa.o wolfcrypt/src/ecc_fp.o wolfcrypt/src/ecc.o wolfcrypt/src/ed25519.o wolfcrypt/src/ed448.o wolfcrypt/src/error.o wolfcrypt/src/fe_448.o wolfcrypt/src/fe_low_mem.o wolfcrypt/src/fe_operations.o wolfcrypt/src/fips.o wolfcrypt/src/fips_test.o wolfcrypt/src/ge_448.o wolfcrypt/src/ge_low_mem.o wolfcrypt/src/ge_operations.o wolfcrypt/src/hash.o wolfcrypt/src/hc128.o wolfcrypt/src/hmac.o wolfcrypt/src/idea.o wolfcrypt/src/integer.o wolfcrypt/src/logging.o wolfcrypt/src/md2.o wolfcrypt/src/md4.o wolfcrypt/src/md5.o wolfcrypt/src/memory.o wolfcrypt/src/pkcs12.o wolfcrypt/src/pkcs7.o wolfcrypt/src/poly1305.o wolfcrypt/src/pwdbased.o wolfcrypt/src/rabbit.o wolfcrypt/src/random.o wolfcrypt/src/ripemd.o wolfcrypt/src/rsa.o wolfcrypt/src/selftest.o wolfcrypt/src/sha256.o wolfcrypt/src/sha3.o wolfcrypt/src/sha512.o wolfcrypt/src/sha.o wolfcrypt/src/signature.o wolfcrypt/src/sp_arm32.o wolfcrypt/src/sp_arm64.o wolfcrypt/src/sp_armthumb.o wolfcrypt/src/sp_c32.o wolfcrypt/src/sp_c64.o wolfcrypt/src/sp_cortexm.o wolfcrypt/src/sp_dsp32.o wolfcrypt/src/sp_int.o wolfcrypt/src/sp_x86_64.o wolfcrypt/src/srp.o wolfcrypt/src/tfm.o wolfcrypt/src/wc_dsp.o wolfcrypt/src/wc_encrypt.o wolfcrypt/src/wc_port.o wolfcrypt/src/wolfcrypt_first.o wolfcrypt/src/wolfcrypt_last.o wolfcrypt/src/wolfevent.o wolfcrypt/src/wolfmath.o +*/ + +#ifdef HAVE_CONFIG_H +#ifndef PACKAGE_NAME +#error wc_port.h included before config.h + #endif + /* config.h is autogenerated without gating to exclude multiple inclusions, so gate it out here to keep autodetection masking intact: */ +#undef HAVE_CONFIG_H +#endif + + #define __KERNEL__ + + _Pragma("GCC diagnostic push"); + /* Linux kernel header files generate profuse warnings unless these are masked out: */ + _Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); + _Pragma("GCC diagnostic ignored \"-Wpointer-arith\""); + _Pragma("GCC diagnostic ignored \"-Wshadow\""); + _Pragma("GCC diagnostic ignored \"-Wnested-externs\""); + _Pragma("GCC diagnostic ignored \"-Wredundant-decls\""); + _Pragma("GCC diagnostic ignored \"-Wsign-compare\""); + _Pragma("GCC diagnostic ignored \"-Wpointer-sign\""); + _Pragma("GCC diagnostic ignored \"-Wbad-function-cast\""); + #include + #include + #include + #include + #ifndef SINGLE_THREADED + #include + #endif + #include /* include this here, while the incompatible warnings are disabled, and before undefining conflicting kernel macros below. */ + #include + _Pragma("GCC diagnostic pop"); + + /* a multifariously conflicting macro is picked up from + * Linux arch//include/asm/current.h, which must be + * removed here. + */ + #undef current + + /* prevent mm_malloc.h from being included, since it unconditionally includes stdlib.h, which is kernel-incompatible: */ + #define _MM_MALLOC_H_INCLUDED + + /* min() and max() in linux/kernel.h over-aggressively type-check, producing myriad spurious -Werrors throughout the codebase. */ + #undef min + #undef WOLFSSL_HAVE_MIN + #undef max + #undef WOLFSSL_HAVE_MAX + + #define key_update wc_key_update /* work around namespace conflict between wolfssl/internal.h (enum HandShakeType) and linux/key.h (extern int()) */ + + #define printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args) + #define XSNPRINTF snprintf /* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */ + #define XATOI(s) ({ long _xatoi_res = 0; int _xatoi_ret = kstrtol(s, 10, &_xatoi_res); if (_xatoi_ret != 0) { _xatoi_res = 0; } (int)_xatoi_res; }) + + /* tweak the autotools-detected feature set to accomodate switch from user to kernel space: */ + #undef HAVE_STRINGS_H + #undef HAVE_ERRNO_H + #define WOLFSSL_DH_CONST 1 /* Linux kernel doesn't have floating point math facilities. */ + #define WOLFSSL_NO_MALLOC 1 + #define WOLFSSL_NO_SOCK 1 + #define WOLFSSL_USER_IO 1 +// #define CTYPE_USER 1 + #undef HAVE_INTEL_RDSEED /* prevents -Wunused-function on wc_GenerateSeed_IntelRD() */ +#endif /* THREADING/MUTEX SECTION */ #ifdef USE_WINDOWS_API @@ -159,7 +237,6 @@ #ifndef WOLFSSL_USER_MUTEX #if defined(WOLFSSL_LINUXKM) #define WOLFSSL_KTHREADS - #include #else #define WOLFSSL_PTHREADS #include @@ -199,6 +276,8 @@ typedef CRITICAL_SECTION wolfSSL_Mutex; #elif defined(WOLFSSL_PTHREADS) typedef pthread_mutex_t wolfSSL_Mutex; + #elif defined(WOLFSSL_KTHREADS) + typedef struct mutex wolfSSL_Mutex; #elif defined(THREADX) typedef TX_MUTEX wolfSSL_Mutex; #elif defined(WOLFSSL_DEOS) @@ -673,12 +752,18 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #elif defined(WOLFSSL_LINUXKM) - #include - #include - - /* forward declaration */ + /* includes are all above, with incompatible warnings masked out. */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) + typedef __kernel_time_t time_t; + #else + typedef __kernel_time64_t time_t; + #endif struct tm* gmtime(const time_t* timer); - #define XGMTIME(c, t) gmtime((c)) + extern time_t time(time_t * timer); + #define XTIME time + #define XGMTIME(c, t) gmtime(c) + #define NO_TIMEVAL 1 + #else /* default */ /* uses complete facility */ diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 32940dd64..989cc5e1a 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -95,7 +95,7 @@ #include #include #elif defined(WOLFSSL_LINUXKM) - #include + /* the requisite linux/net.h is included in wc_port.h, with incompatible warnings masked out. */ #elif defined(WOLFSSL_ATMEL) #include "socket/include/socket.h" #elif defined(INTIME_RTOS)