diff --git a/IDE/WIN-SGX/ReadMe.txt b/IDE/WIN-SGX/ReadMe.txt new file mode 100755 index 000000000..4844066cc --- /dev/null +++ b/IDE/WIN-SGX/ReadMe.txt @@ -0,0 +1,33 @@ +================================================================================================== + Static Library : wolfssl Project Overview +================================================================================================== + +Requirements: +This code was created to use Intel's SGX hardware. It is expected that the user has gone through the +steps of both turning on the hardware in bios if needed and has installed the necesary software +from Intel to make use of the hardware. (https://software.intel.com/en-us/sgx) If these steps have +not been done then it is expected that the user is familure with simiulation software being used in +place of hardware. + +Overview and Build: +This project creates a static library to then link with Enclaves. A simple example of an Enclave +linking to the created wolfSSL library can be found in wolfssl-examples on github. By default +the Platform Toolset is set to "Intel C++ Compiler 16.0", this may need adjusted depending on +available compilers on the system being built on. + Testing and development was done with Visual Studio 2013. This project may build with other versions +of Visual Studio but has not been tested with them. + +To link with the created library with Visual Studio first open the wolfSSL_SGX project in Visual Studio. +Select platform desired from build configuration ie Win32 or x64. (note the architecture of the library +should match that of the Enclave/application being linked to it) Select Debug or PreSales, if looking +to build in Release mode look at Intels documentation for farther steps on creating a Release build. +Next select Build->Build Solution. This will create a library named wolfssl.lib in the directory +wolfssl-root/IDE/WIN-SGX//. Move this library to the search path of Enclave +linking to. Next create an Enclave using the library. + +Limitations: + Single Threaded (multiple threaded applications have not been tested) + Crypto Only (network communication from trusted Enclave has not been added yet) + No ASN/Certificates (handling getting the system time has not yet been added) + AES-NI use with SGX has not been added in yet + diff --git a/IDE/WIN-SGX/include.am b/IDE/WIN-SGX/include.am new file mode 100644 index 000000000..cce4b10f0 --- /dev/null +++ b/IDE/WIN-SGX/include.am @@ -0,0 +1,10 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST+= IDE/WIN-SGX/ReadMe.txt +EXTRA_DIST+= IDE/WIN-SGX/wolfSSL_SGX.edl +EXTRA_DIST+= IDE/WIN-SGX/wolfSSL_SGX.sln +EXTRA_DIST+= IDE/WIN-SGX/wolfSSL_SGX.suo +EXTRA_DIST+= IDE/WIN-SGX/wolfSSL_SGX.vcxproj +EXTRA_DIST+= IDE/WIN-SGX/wolfSSL_SGX.vcxproj.filters diff --git a/IDE/WIN-SGX/wolfSSL_SGX.edl b/IDE/WIN-SGX/wolfSSL_SGX.edl new file mode 100755 index 000000000..7366e91a1 --- /dev/null +++ b/IDE/WIN-SGX/wolfSSL_SGX.edl @@ -0,0 +1,11 @@ +enclave { + + trusted { + + }; + + untrusted { + /* define OCALLs here. */ + + }; +}; diff --git a/IDE/WIN-SGX/wolfSSL_SGX.sln b/IDE/WIN-SGX/wolfSSL_SGX.sln new file mode 100755 index 000000000..2efdf7785 --- /dev/null +++ b/IDE/WIN-SGX/wolfSSL_SGX.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfSSL_SGX", "wolfSSL_SGX.vcxproj", "{D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Prerelease|Win32 = Prerelease|Win32 + Prerelease|x64 = Prerelease|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + Simulation|Win32 = Simulation|Win32 + Simulation|x64 = Simulation|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Debug|Win32.ActiveCfg = Debug|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Debug|Win32.Build.0 = Debug|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Debug|x64.ActiveCfg = Debug|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Debug|x64.Build.0 = Debug|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Prerelease|Win32.ActiveCfg = Prerelease|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Prerelease|Win32.Build.0 = Prerelease|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Prerelease|x64.ActiveCfg = Prerelease|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Prerelease|x64.Build.0 = Prerelease|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Release|Win32.ActiveCfg = Release|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Release|Win32.Build.0 = Release|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Release|x64.ActiveCfg = Release|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Release|x64.Build.0 = Release|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Simulation|Win32.ActiveCfg = Simulation|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Simulation|Win32.Build.0 = Simulation|Win32 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Simulation|x64.ActiveCfg = Simulation|x64 + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3}.Simulation|x64.Build.0 = Simulation|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/IDE/WIN-SGX/wolfSSL_SGX.vcxproj b/IDE/WIN-SGX/wolfSSL_SGX.vcxproj new file mode 100755 index 000000000..203d1ac62 --- /dev/null +++ b/IDE/WIN-SGX/wolfSSL_SGX.vcxproj @@ -0,0 +1,321 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Prerelease + Win32 + + + Prerelease + x64 + + + Release + Win32 + + + Release + x64 + + + Simulation + Win32 + + + Simulation + x64 + + + + {D4D81C31-1404-4E8C-8E8C-19C3A74F66F3} + v4.5.2 + wolfSSL_SGX + + + + StaticLibrary + Intel C++ Compiler 16.0 + + + StaticLibrary + Intel C++ Compiler 16.0 + Unicode + + + StaticLibrary + v120 + + + StaticLibrary + v120 + + + StaticLibrary + Intel C++ Compiler 16.0 + + + StaticLibrary + Intel C++ Compiler 16.0 + Unicode + + + StaticLibrary + v120 + + + StaticLibrary + v120 + + + StaticLibrary + Intel C++ Compiler 16.0 + + + StaticLibrary + Intel C++ Compiler 16.0 + Unicode + + + StaticLibrary + Intel C++ Compiler 16.0 + + + StaticLibrary + Intel C++ Compiler 16.0 + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(NoInherit) + $(NoInherit) + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + wolfssl + + + $(NoInherit) + $(NoInherit) + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform\obj\ + wolfssl + + + $(NoInherit) + $(NoInherit) + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + $(NoInherit) + $(NoInherit) + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform\obj\ + + + $(NoInherit) + $(NoInherit) + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + $(NoInherit) + $(NoInherit) + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform\obj\ + + + $(NoInherit) + $(NoInherit) + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + wolfssl + + + $(NoInherit) + $(NoInherit) + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform\obj\ + wolfssl + + + + Default + MultiThreadedDebug + Disabled + Level4 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreadedDebug + Disabled + Level4 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreadedDebug + Disabled + Level4 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;%(AdditionalIncludeDirectories) + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreadedDebug + Disabled + Level3 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;%(AdditionalIncludeDirectories) + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreaded + MaxSpeed + Level4 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + true + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreaded + MaxSpeed + Level3 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + true + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreaded + MaxSpeed + Level4 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;%(AdditionalIncludeDirectories) + true + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + Default + MultiThreaded + MaxSpeed + Level3 + ../../;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + true + WOLFSSL_LIB;WOLFSSL_SGX + + + true + + + + + + + + + + + + + + ..\..;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + ..\..;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;%(AdditionalIncludeDirectories) + ..\..;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + ..\..;$(SGXSDKInstallPath)include;$(SGXSDKInstallPath)include\tlibc;$(SGXSDKInstallPath)include\stlport;$(SolutionDir)wolfssl-3.9.6;%(AdditionalIncludeDirectories) + + + + + + + + + + + + \ No newline at end of file diff --git a/IDE/WIN-SGX/wolfSSL_SGX.vcxproj.filters b/IDE/WIN-SGX/wolfSSL_SGX.vcxproj.filters new file mode 100755 index 000000000..427aaef0a --- /dev/null +++ b/IDE/WIN-SGX/wolfSSL_SGX.vcxproj.filters @@ -0,0 +1,58 @@ + + + + + {750b7ded-415e-41ff-a260-cdeed365e21c} + + + {14d1a4f3-1b3b-4e74-be2c-af4e52bd5c11} + cpp;c;edl;def; .. and other options + + + {22d38e35-4cca-4899-9551-3809351f7aa5} + h;hpp; .. and other options + + + {e5d0cd71-716c-402b-a23c-4a161912a7b1} + rc;xml;pem; .. and other options + + + + + Generated Files + + + + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + Source Files + + + \ No newline at end of file diff --git a/IDE/include.am b/IDE/include.am index e77c86c35..96fa894d7 100644 --- a/IDE/include.am +++ b/IDE/include.am @@ -4,6 +4,7 @@ include IDE/iOS/include.am include IDE/WIN/include.am +include IDE/WIN-SGX/include.am include IDE/WORKBENCH/include.am include IDE/ROWLEY-CROSSWORKS-ARM/include.am include IDE/ARDUINO/include.am diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index d8c100c2c..550d96503 100755 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -135,7 +135,9 @@ int wc_FreeRng(WC_RNG* rng) #endif #endif /* HAVE_HASHDRBG || NO_RC4 */ -#if defined(USE_WINDOWS_API) +#if defined(WOLFSSL_SGX) +#include +#elif defined(USE_WINDOWS_API) #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif @@ -1167,6 +1169,20 @@ static int wc_GenerateRand_IntelRD(OS_Seed* os, byte* output, word32 sz) return CUSTOM_RAND_GENERATE_SEED_OS(os, output, sz); } +#elif defined(WOLFSSL_SGX) + +int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) +{ + int ret = !SGX_SUCCESS; + int i, read_max = 10; + + for (i = 0; i < read_max && ret != SGX_SUCCESS; i++) { + ret = sgx_read_rand(output, sz); + } + + (void)os; + return (ret == SGX_SUCCESS) ? 0 : 1; +} #elif defined(USE_WINDOWS_API) diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 6a1117d86..734e756e6 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -1230,6 +1230,20 @@ static char *fgets(char *buff, int sz, FILE *fp) #endif #endif +#ifdef WOLFSSL_SGX + #define WOLFCRYPT_ONLY /* limitation until IO resolved */ + #define SINGLE_THREADED + #define NO_ASN_TIME /* can not use headers such as windows.h */ + + /* options used in created example */ + #define HAVE_AESGCM + #define USE_CERT_BUFFERS_2048 + #define USE_FAST_MATH + #define NO_RC4 + #define NO_DES3 + #define NO_SHA + #define NO_MD5 +#endif /* WOLFSSL_SGX */ /* FreeScale MMCAU hardware crypto has 4 byte alignment. However, fsl_mmcau.h gives API with no alignment requirements (4 byte alignment is managed internally by fsl_mmcau.c) */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index c1e26429a..ac20cae99 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -132,18 +132,18 @@ #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 rotate style */ + #if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && !defined(WOLFSSL_SGX) + #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 */ diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 23dd4e078..db8d1ee43 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -38,12 +38,14 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif + #ifndef WOLFCRYPT_ONLY #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) /* On WinCE winsock2.h must be included before windows.h */ #include #endif #include #endif + #endif /* WOLFCRYPT_ONLY */ #elif defined(THREADX) #ifndef SINGLE_THREADED #include "tx_api.h"