aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLordOfDorks <mail@LordOfDorks.com>2018-02-05 15:17:42 -0800
committerLordOfDorks <mail@LordOfDorks.com>2018-02-05 15:17:42 -0800
commite37233fd873a64053aa024c77eac13372f4e4c82 (patch)
treea54cca70c942d4c128649d9bb3036052d9040728
parentd81005bd9067b1b620678f2f8d69ae1d4fd9d882 (diff)
downloadms-tpm-20-ref-e37233fd873a64053aa024c77eac13372f4e4c82.tar.gz
Rebranch of the WolfCrypt work.
Signed-off-by: LordOfDorks <mail@LordOfDorks.com>
-rw-r--r--.gitignore2
-rw-r--r--.gitmodules3
-rw-r--r--TPMCmd/Platform/platform.vcxproj36
-rw-r--r--TPMCmd/Simulator/simulator.vcxproj36
-rw-r--r--TPMCmd/tpm/Tpm.vcxproj47
-rw-r--r--TPMCmd/tpm/Tpm.vcxproj.filters27
-rw-r--r--TPMCmd/tpm/include/Implementation.h2
-rw-r--r--TPMCmd/tpm/include/LibSupport.h9
-rw-r--r--TPMCmd/tpm/include/VendorString.h10
-rw-r--r--TPMCmd/tpm/include/wolf/TpmToWolfHash.h186
-rw-r--r--TPMCmd/tpm/include/wolf/TpmToWolfMath.h114
-rw-r--r--TPMCmd/tpm/include/wolf/TpmToWolfSym.h123
-rw-r--r--TPMCmd/tpm/include/wolf/user_settings.h42
-rw-r--r--TPMCmd/tpm/src/crypt/wolf/TpmToWolfDesSupport.c101
-rw-r--r--TPMCmd/tpm/src/crypt/wolf/TpmToWolfMath.c569
-rw-r--r--TPMCmd/tpm/src/crypt/wolf/TpmToWolfSupport.c92
m---------external/wolfssl0
17 files changed, 1340 insertions, 59 deletions
diff --git a/.gitignore b/.gitignore
index 70c4d45..36b6a53 100644
--- a/.gitignore
+++ b/.gitignore
@@ -290,3 +290,5 @@ __pycache__/
# TPM simulator run-time/state files
NVChip
RsaKeyCacheCrt.data
+TPMCmd/OsslInclude/*
+TPMCmd/Lib/*
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..d1f75cd
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "external/wolfssl"]
+ path = external/wolfssl
+ url = https://github.com/wolfSSL/wolfssl.git
diff --git a/TPMCmd/Platform/platform.vcxproj b/TPMCmd/Platform/platform.vcxproj
index 4a29cc6..7284d14 100644
--- a/TPMCmd/Platform/platform.vcxproj
+++ b/TPMCmd/Platform/platform.vcxproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Coverage|Win32">
<Configuration>Coverage</Configuration>
@@ -87,86 +87,86 @@
<RootNamespace>platform</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>Platform</ProjectName>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v100</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GCC Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GCC Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|x64'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|Win32'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
<ConfigurationType>Makefile</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
diff --git a/TPMCmd/Simulator/simulator.vcxproj b/TPMCmd/Simulator/simulator.vcxproj
index cbe9763..5b022d6 100644
--- a/TPMCmd/Simulator/simulator.vcxproj
+++ b/TPMCmd/Simulator/simulator.vcxproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Coverage|Win32">
<Configuration>Coverage</Configuration>
@@ -71,86 +71,86 @@
<RootNamespace>simulator</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>Simulator</ProjectName>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v100</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GCC Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GCC Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|x64'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|Win32'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
<ConfigurationType>Makefile</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
diff --git a/TPMCmd/tpm/Tpm.vcxproj b/TPMCmd/tpm/Tpm.vcxproj
index 3246d5b..8633a2f 100644
--- a/TPMCmd/tpm/Tpm.vcxproj
+++ b/TPMCmd/tpm/Tpm.vcxproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Coverage|Win32">
<Configuration>Coverage</Configuration>
@@ -63,76 +63,76 @@
<ProjectGuid>{B7456491-A2ED-4B1C-B59E-41C7B32B7E3B}</ProjectGuid>
<RootNamespace>TPMCmd</RootNamespace>
<Keyword>Win32Proj</Keyword>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v100</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SelfTest|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Coverage|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|x64'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='GccCompile|Win32'">
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v141</PlatformToolset>
<ConfigurationType>Makefile</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -280,7 +280,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>$(ProjectDir)include\;$(ProjectDir)include\prototypes\;$(SolutionDir)Platform\include\;$(SolutionDir)Platform\include\prototypes\;$(SolutionDir)LtcInclude\;$(SolutionDIr)OsslInclude\;$(SolutionDir)MsBnInclude\</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)include\;$(ProjectDir)include\prototypes\;$(SolutionDir)Platform\include\;$(SolutionDir)Platform\include\prototypes\;$(SolutionDir)LtcInclude\;$(SolutionDIr)OsslInclude\;$(SolutionDir)MsBnInclude\;$(SolutionDir)..\external\wolfssl</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@@ -871,6 +871,15 @@
<ClCompile Include="src\crypt\PrimeData.c" />
<ClCompile Include="src\crypt\RsaKeyCache.c" />
<ClCompile Include="src\crypt\Ticket.c" />
+ <ClCompile Include="src\crypt\wolf\TpmToWolfDesSupport.c">
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\external\wolfssl\wolfssl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\external\wolfssl\wolfssl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ </ClCompile>
+ <ClCompile Include="src\crypt\wolf\TpmToWolfMath.c">
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\external\wolfssl\wolfssl;$(ProjectDir)include\;$(ProjectDir)include\prototypes\;$(SolutionDir)Platform\include\;$(SolutionDir)Platform\include\prototypes\;$(SolutionDir)LtcInclude\;$(SolutionDIr)OsslInclude\;$(SolutionDir)MsBnInclude\</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\external\wolfssl\wolfssl;$(ProjectDir)include\;$(ProjectDir)include\prototypes\;$(SolutionDir)Platform\include\;$(SolutionDir)Platform\include\prototypes\;$(SolutionDir)LtcInclude\;$(SolutionDIr)OsslInclude\;$(SolutionDir)MsBnInclude\</AdditionalIncludeDirectories>
+ </ClCompile>
+ <ClCompile Include="src\crypt\wolf\TpmToWolfSupport.c" />
<ClCompile Include="src\events\_TPM_Hash_Data.c" />
<ClCompile Include="src\events\_TPM_Hash_End.c" />
<ClCompile Include="src\events\_TPM_Hash_Start.c" />
@@ -1145,6 +1154,10 @@
<ClInclude Include="include\TpmBuildSwitches.h" />
<ClInclude Include="include\TpmTypes.h" />
<ClInclude Include="include\VendorString.h" />
+ <ClInclude Include="include\wolf\TpmToWolfHash.h" />
+ <ClInclude Include="include\wolf\TpmToWolfMath.h" />
+ <ClInclude Include="include\wolf\TpmToWolfSym.h" />
+ <ClInclude Include="include\wolf\user_settings.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/TPMCmd/tpm/Tpm.vcxproj.filters b/TPMCmd/tpm/Tpm.vcxproj.filters
index 591d116..7a28045 100644
--- a/TPMCmd/tpm/Tpm.vcxproj.filters
+++ b/TPMCmd/tpm/Tpm.vcxproj.filters
@@ -577,6 +577,15 @@
<ClCompile Include="src\crypt\CryptEccData.c">
<Filter>Source Files\Crypt</Filter>
</ClCompile>
+ <ClCompile Include="src\crypt\wolf\TpmToWolfDesSupport.c">
+ <Filter>Source Files\Crypt\wolf</Filter>
+ </ClCompile>
+ <ClCompile Include="src\crypt\wolf\TpmToWolfMath.c">
+ <Filter>Source Files\Crypt\wolf</Filter>
+ </ClCompile>
+ <ClCompile Include="src\crypt\wolf\TpmToWolfSupport.c">
+ <Filter>Source Files\Crypt\wolf</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\BaseTypes.h">
@@ -1284,6 +1293,18 @@
<ClInclude Include="include\ossl\TpmToOsslSym.h">
<Filter>Headers\Crypt\ossl</Filter>
</ClInclude>
+ <ClInclude Include="include\wolf\TpmToWolfHash.h">
+ <Filter>Headers\Crypt\wolf</Filter>
+ </ClInclude>
+ <ClInclude Include="include\wolf\TpmToWolfMath.h">
+ <Filter>Headers\Crypt\wolf</Filter>
+ </ClInclude>
+ <ClInclude Include="include\wolf\TpmToWolfSym.h">
+ <Filter>Headers\Crypt\wolf</Filter>
+ </ClInclude>
+ <ClInclude Include="include\wolf\user_settings.h">
+ <Filter>Headers\Crypt\wolf</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Source Files">
@@ -1316,5 +1337,11 @@
<Filter Include="Headers\Crypt\ossl">
<UniqueIdentifier>{1a979e04-0e58-4286-b6b0-52cb2b86d037}</UniqueIdentifier>
</Filter>
+ <Filter Include="Source Files\Crypt\wolf">
+ <UniqueIdentifier>{17d101a1-3063-43f5-960b-b0df7b0950cc}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Headers\Crypt\wolf">
+ <UniqueIdentifier>{19c87ebb-c1f3-4521-a442-d9120957d238}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/TPMCmd/tpm/include/Implementation.h b/TPMCmd/tpm/include/Implementation.h
index c57243d..b3aad82 100644
--- a/TPMCmd/tpm/include/Implementation.h
+++ b/TPMCmd/tpm/include/Implementation.h
@@ -314,7 +314,7 @@
#define RADIX_BITS 32
#define HASH_ALIGNMENT 4
#define SYMMETRIC_ALIGNMENT 4
-#define HASH_LIB OSSL
+#define HASH_LIB WOLF
#define SYM_LIB OSSL
#define MATH_LIB OSSL
#define BSIZE UINT16
diff --git a/TPMCmd/tpm/include/LibSupport.h b/TPMCmd/tpm/include/LibSupport.h
index 9e76ca5..66b4d8c 100644
--- a/TPMCmd/tpm/include/LibSupport.h
+++ b/TPMCmd/tpm/include/LibSupport.h
@@ -50,6 +50,9 @@
// SYMCRYPT only provides symmetric cryptography so would need to be combined with
// another library that has math support
#define SYMCRYPT 4
+// WolfCrypt from the statically linkable GPL WolfSLL, other commercial licenses
+// also available
+#define WOLF 5
//*********************
#if RADIX_BITS == 32
@@ -69,6 +72,8 @@
# include "ltc/TpmToLtcHash.h"
#elif HASH_LIB == SYMCRYPT
#include "symcrypt/TpmToSymcryptHash.h"
+#elif HASH_LIB == WOLF
+# include "wolf/TpmToWolfHash.h"
#else
# error "No hash library selected"
#endif
@@ -81,6 +86,8 @@
# include "ltc/TpmToLtcSym.h"
#elif SYM_LIB == SYMCRYPT
#include "symcrypt/TpmToSymcryptSym.h"
+#elif SYM_LIB == WOLF
+# include "wolf/TpmToWolfSym.h"
#else
# error "No symmetric library selected"
#endif
@@ -98,6 +105,8 @@
# define MATHLIB_H "ltc/TpmToLtcMath.h"
#elif MATH_LIB == MSBN
#define MATHLIB_H "msbn/TpmToMsBnMath.h"
+#elif MATH_LIB == WOLF
+# define MATHLIB_H "wolf/TpmToWolfMath.h"
#else
# error "No math library selected"
#endif
diff --git a/TPMCmd/tpm/include/VendorString.h b/TPMCmd/tpm/include/VendorString.h
index a7740f9..da2c648 100644
--- a/TPMCmd/tpm/include/VendorString.h
+++ b/TPMCmd/tpm/include/VendorString.h
@@ -40,7 +40,7 @@
// for TPM_PT_MANUFACTURER in TPM2_GetCapability.
// The following line should be un-commented and a vendor specific string
// should be provided here.
-//#define MANUFACTURER "MSFT"
+#define MANUFACTURER "MSFT"
// The following #if macro may be deleted after a proper MANUFACTURER is provided.
#ifndef MANUFACTURER
@@ -57,8 +57,8 @@ manufacturer name.
// The following line should be un-commented and a vendor specific string
//
// A vendor-specific string should be provided here.
-//#define VENDOR_STRING_1 "DPA "
-//#define VENDOR_STRING_2 "fTPM"
+#define VENDOR_STRING_1 "DPA "
+#define VENDOR_STRING_2 "fTPM"
// The vendor strings 2-4 may also be defined as needed.
//#define VENDOR_STRING_3
@@ -75,11 +75,11 @@ string.
// A vendor-specific FIRMWARE_V1 is required here. It is
// the more significant 32-bits of a vendor-specific value
// indicating the version of the firmware
-//#define FIRMWARE_V1 (0x20170615)
+#define FIRMWARE_V1 (0x20170615)
// A vendor-specific FIRMWARE_V2 may be provided here. If present, it is the less
// significant 32-bits of the version of the firmware.
-//#define FIRMWARE_V2 (0x00000000)
+#define FIRMWARE_V2 (0x00000000)
// The following macro is just to insure that a FIRMWARE_V1 value is provided.
#ifndef FIRMWARE_V1
diff --git a/TPMCmd/tpm/include/wolf/TpmToWolfHash.h b/TPMCmd/tpm/include/wolf/TpmToWolfHash.h
new file mode 100644
index 0000000..21bb335
--- /dev/null
+++ b/TPMCmd/tpm/include/wolf/TpmToWolfHash.h
@@ -0,0 +1,186 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+//
+// This header file is used to 'splice' the OpenSSL hash code into the TPM code.
+//
+#ifndef _TPM_TO_WOLF_HASH_H_
+#define _TPM_TO_WOLF_HASH_H_
+
+#if HASH_LIB == WOLF
+
+#define WOLFSSL_USER_SETTINGS
+#include <wolfSSL/wolfCrypt/sha.h>
+#include <wolfSSL/wolfCrypt/sha256.h>
+#include <wolfSSL/wolfCrypt/sha512.h>
+
+
+//***************************************************************
+//** Links to the OpenSSL HASH code
+//***************************************************************
+
+// Redefine the internal name used for each of the hash state structures to the
+// name used by the library.
+// These defines need to be known in all parts of the TPM so that the structure
+// sizes can be properly computed when needed.
+
+#define tpmHashStateSHA1_t wc_Sha
+#define tpmHashStateSHA256_t wc_Sha256
+#define tpmHashStateSHA384_t wc_Sha512
+#define tpmHashStateSHA512_t wc_Sha512
+
+#ifdef TPM_ALG_SM3
+# error "The version of WolfCrypt used by this code does not support SM3"
+#endif
+
+// The defines below are only needed when compiling CryptHash.c or CryptSmac.c.
+// This isolation is primarily to avoid name space collision. However, if there
+// is a real collision, it will likely show up when the linker tries to put things
+// together.
+
+#ifdef _CRYPT_HASH_C_
+
+typedef BYTE *PBYTE;
+typedef const BYTE *PCBYTE;
+
+// Define the interface between CryptHash.c to the functions provided by the
+// library. For each method, define the calling parameters of the method and then
+// define how the method is invoked in CryptHash.c.
+//
+// All hashes are required to have the same calling sequence. If they don't, create
+// a simple adaptation function that converts from the "standard" form of the call
+// to the form used by the specific hash (and then send a nasty letter to the
+// person who wrote the hash function for the library).
+//
+// The macro that calls the method also defines how the
+// parameters get swizzled between the default form (in CryptHash.c)and the
+// library form.
+//
+// Initialize the hash context
+#define HASH_START_METHOD_DEF void (HASH_START_METHOD)(PANY_HASH_STATE state)
+#define HASH_START(hashState) \
+ ((hashState)->def->method.start)(&(hashState)->state);
+
+// Add data to the hash
+#define HASH_DATA_METHOD_DEF \
+ void (HASH_DATA_METHOD)(PANY_HASH_STATE state, \
+ PCBYTE buffer, \
+ size_t size)
+#define HASH_DATA(hashState, dInSize, dIn) \
+ ((hashState)->def->method.data)(&(hashState)->state, dIn, dInSize)
+
+// Finalize the hash and get the digest
+#define HASH_END_METHOD_DEF \
+ void (HASH_END_METHOD)(PANY_HASH_STATE state, BYTE *buffer)
+#define HASH_END(hashState, buffer) \
+ ((hashState)->def->method.end)(&(hashState)->state, buffer)
+
+// Copy the hash context
+// Note: For import, export, and copy, memcpy() is used since there is no
+// reformatting necessary between the internal and external forms.
+#define HASH_STATE_COPY_METHOD_DEF \
+ void (HASH_STATE_COPY_METHOD)(PANY_HASH_STATE to, \
+ PCANY_HASH_STATE from, \
+ size_t size)
+#define HASH_STATE_COPY(hashStateOut, hashStateIn) \
+ ((hashStateIn)->def->method.copy)(&(hashStateOut)->state, \
+ &(hashStateIn)->state, \
+ (hashStateIn)->def->contextSize)
+
+// Copy (with reformatting when necessary) an internal hash structure to an
+// external blob
+#define HASH_STATE_EXPORT_METHOD_DEF \
+ void (HASH_STATE_EXPORT_METHOD)(BYTE *to, \
+ PCANY_HASH_STATE from, \
+ size_t size)
+#define HASH_STATE_EXPORT(to, hashStateFrom) \
+ ((hashStateFrom)->def->method.copyOut) \
+ (&(((BYTE *)(to))[offsetof(HASH_STATE, state)]), \
+ &(hashStateFrom)->state, \
+ (hashStateFrom)->def->contextSize)
+
+// Copy from an external blob to an internal formate (with reformatting when
+// necessary
+#define HASH_STATE_IMPORT_METHOD_DEF \
+ void (HASH_STATE_IMPORT_METHOD)(PANY_HASH_STATE to, \
+ const BYTE *from, \
+ size_t size)
+#define HASH_STATE_IMPORT(hashStateTo, from) \
+ ((hashStateTo)->def->method.copyIn) \
+ (&(hashStateTo)->state, \
+ &(((const BYTE *)(from))[offsetof(HASH_STATE, state)]),\
+ (hashStateTo)->def->contextSize)
+
+
+// Function aliases. The code in CryptHash.c uses the internal designation for the
+// functions. These need to be translated to the function names of the library.
+// Internal External
+// Designation Designation
+#define tpmHashStart_SHA1 wc_InitSha // external name of the
+ // initialization method
+#define tpmHashData_SHA1 wc_ShaUpdate
+#define tpmHashEnd_SHA1 wc_ShaFinal
+#define tpmHashStateCopy_SHA1 memcpy
+#define tpmHashStateExport_SHA1 memcpy
+#define tpmHashStateImport_SHA1 memcpy
+#define tpmHashStart_SHA256 wc_InitSha256
+#define tpmHashData_SHA256 wc_Sha256Update
+#define tpmHashEnd_SHA256 wc_Sha256Final
+#define tpmHashStateCopy_SHA256 memcpy
+#define tpmHashStateExport_SHA256 memcpy
+#define tpmHashStateImport_SHA256 memcpy
+#define tpmHashStart_SHA384 wc_InitSha384
+#define tpmHashData_SHA384 wc_Sha384Update
+#define tpmHashEnd_SHA384 wc_Sha384Final
+#define tpmHashStateCopy_SHA384 memcpy
+#define tpmHashStateExport_SHA384 memcpy
+#define tpmHashStateImport_SHA384 memcpy
+#define tpmHashStart_SHA512 wc_InitSha512
+#define tpmHashData_SHA512 wc_Sha512Update
+#define tpmHashEnd_SHA512 wc_Sha512Final
+#define tpmHashStateCopy_SHA512 memcpy
+#define tpmHashStateExport_SHA512 memcpy
+#define tpmHashStateImport_SHA512 memcpy
+
+#endif // _CRYPT_HASH_C_
+
+#define LibHashInit()
+// This definition would change if there were something to report
+#define HashLibSimulationEnd()
+
+#endif // HASH_LIB == WOLF
+
+#endif //
diff --git a/TPMCmd/tpm/include/wolf/TpmToWolfMath.h b/TPMCmd/tpm/include/wolf/TpmToWolfMath.h
new file mode 100644
index 0000000..4f2ce24
--- /dev/null
+++ b/TPMCmd/tpm/include/wolf/TpmToWolfMath.h
@@ -0,0 +1,114 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+// This file contains the structure definitions used for ECC in the LibTopCrypt
+// version of the code. These definitions would change, based on the library.
+// The ECC-related structures that cross the TPM interface are defined
+// in TpmTypes.h
+//
+
+#ifndef _TPM_TO_WOLF_MATH_H
+#define _TPM_TO_WOLF_MATH_H
+
+#if MATH_LIB == WOLF
+
+#include <openssl/evp.h>
+#include <openssl/ec.h>
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+#include <openssl/bn_lcl.h>
+#endif
+#include <openssl/bn.h>
+
+//** Macros and Defines
+
+// Make sure that the library is using the correct size for a crypt word
+#if defined THIRTY_TWO_BIT && (RADIX_BITS != 32) \
+ || defined SIXTY_FOUR_BIT && (RADIX_BITS != 64)
+# error "Ossl library is using different radix"
+#endif
+
+// Allocate a local BIGNUM value. For the allocation, a bigNum structure is created
+// as is a local BIGNUM. The bigNum is initialized and then the BIGNUM is
+// set to reference the local value.
+#define BIG_VAR(name, bits) \
+ BN_VAR(name##Bn, (bits)); \
+ BIGNUM _##name; \
+ BIGNUM *name = BigInitialized(&_##name, \
+ BnInit(name##Bn, \
+ BYTES_TO_CRYPT_WORDS(sizeof(_##name##Bn.d))))
+
+// Allocate a BIGNUM and initialize with the values in a bigNum initializer
+#define BIG_INITIALIZED(name, initializer) \
+ BIGNUM _##name; \
+ BIGNUM *name = BigInitialized(&_##name, initializer)
+
+
+typedef struct
+{
+ const ECC_CURVE_DATA *C; // the TPM curve values
+ EC_GROUP *G; // group parameters
+ BN_CTX *CTX; // the context for the math (this might not be
+ // the context in which the curve was created>;
+} OSSL_CURVE_DATA;
+
+typedef OSSL_CURVE_DATA *bigCurve;
+
+#define AccessCurveData(E) ((E)->C)
+
+#define CURVE_INITIALIZED(name, initializer) \
+ OSSL_CURVE_DATA _##name; \
+ bigCurve name = BnCurveInitialize(&_##name, initializer)
+
+#include "TpmToOsslSupport_fp.h"
+
+#define CURVE_FREE(E) \
+ if(E != NULL) \
+ { \
+ if(E->G != NULL) \
+ EC_GROUP_free(E->G); \
+ OsslContextLeave(E->CTX); \
+ }
+
+#define OSSL_ENTER() BN_CTX *CTX = OsslContextEnter()
+
+#define OSSL_LEAVE() OsslContextLeave(CTX)
+
+// This definition would change if there were something to report
+#define MathLibSimulationEnd()
+
+#endif // MATH_LIB == WOLF
+
+#endif
diff --git a/TPMCmd/tpm/include/wolf/TpmToWolfSym.h b/TPMCmd/tpm/include/wolf/TpmToWolfSym.h
new file mode 100644
index 0000000..7695a2d
--- /dev/null
+++ b/TPMCmd/tpm/include/wolf/TpmToWolfSym.h
@@ -0,0 +1,123 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+//
+// This header file is used to 'splice' the OpenSSL library into the TPM code.
+//
+// The support required of a library are a hash module, a block cipher module and
+// portions of a big number library.
+
+#ifndef _TPM_TO_WOLF_SYM_H_
+#define _TPM_TO_WOLF_SYM_H_
+
+#if SYM_LIB == WOLF
+
+#include <openssl/aes.h>
+#include <openssl/des.h>
+#include <openssl/bn.h>
+#include <openssl/ossl_typ.h>
+
+//***************************************************************
+//** Links to the OpenSSL AES code
+//***************************************************************
+
+#ifdef TPM_ALG_SM4
+#error "SM4 is not available"
+#endif
+
+#ifdef TPM_ALG_CAMELLIA
+#error "Camellia is not available"
+#endif
+
+// Define the order of parameters to the library functions that do block encryption
+// and decryption.
+typedef void(*TpmCryptSetSymKeyCall_t)(
+ const BYTE *in,
+ BYTE *out,
+ void *keySchedule
+ );
+
+// The Crypt functions that call the block encryption function use the parameters
+// in the order:
+// 1) keySchedule
+// 2) in buffer
+// 3) out buffer
+// Since open SSL uses the order in encryptoCall_t above, need to swizzle the
+// values to the order required by the library.
+#define SWIZZLE(keySchedule, in, out) \
+ (const BYTE *)(in), (BYTE *)(out), (void *)(keySchedule)
+
+// Macros to set up the encryption/decryption key schedules
+//
+// AES:
+#define TpmCryptSetEncryptKeyAES(key, keySizeInBits, schedule) \
+ AES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
+#define TpmCryptSetDecryptKeyAES(key, keySizeInBits, schedule) \
+ AES_set_decrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
+
+// TDES:
+#define TpmCryptSetEncryptKeyTDES(key, keySizeInBits, schedule) \
+ TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
+#define TpmCryptSetDecryptKeyTDES(key, keySizeInBits, schedule) \
+ TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
+
+// Macros to alias encryption calls to specific algorithms. This should be used
+// sparingly. Currently, only used by CryptRand.c
+//
+// When using these calls, to call the AES block encryption code, the caller
+// should use:
+// TpmCryptEncryptAES(SWIZZLE(keySchedule, in, out));
+#define TpmCryptEncryptAES AES_encrypt
+#define TpmCryptDecryptAES AES_decrypt
+#define tpmKeyScheduleAES AES_KEY
+
+
+#define TpmCryptEncryptTDES TDES_encrypt
+#define TpmCryptDecryptTDES TDES_decrypt
+#define tpmKeyScheduleTDES DES_key_schedule
+
+typedef union tpmCryptKeySchedule_t tpmCryptKeySchedule_t;
+
+#ifdef TPM_ALG_TDES
+#include "TpmToOsslDesSupport_fp.h"
+#endif
+
+// This definition would change if there were something to report
+#define SymLibSimulationEnd()
+
+#endif // SYM_LIB == WOLF
+
+#endif // _TPM_TO_WOLF_SYM_H_
diff --git a/TPMCmd/tpm/include/wolf/user_settings.h b/TPMCmd/tpm/include/wolf/user_settings.h
new file mode 100644
index 0000000..5cf6e98
--- /dev/null
+++ b/TPMCmd/tpm/include/wolf/user_settings.h
@@ -0,0 +1,42 @@
+/* settings.h
+ *
+ * Copyright (C) 2006-2017 wolfSSL Inc.
+ *
+ * This file is part of wolfSSL.
+ *
+ * wolfSSL is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * wolfSSL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
+ */
+
+
+/* Place OS specific preprocessor flags, defines, includes here, will be
+ included into every file because types.h includes it */
+
+
+#ifndef WOLF_CRYPT_USER_SETTINGS_H
+#define WOLF_CRYPT_USER_SETTINGS_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define NO_OLD_WC_NAMES
+#define WOLFSSL_SHA384
+#define WOLFSSL_SHA512
+
+#ifdef __cplusplus
+ } /* extern "C" */
+#endif
+
+#endif
diff --git a/TPMCmd/tpm/src/crypt/wolf/TpmToWolfDesSupport.c b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfDesSupport.c
new file mode 100644
index 0000000..b261171
--- /dev/null
+++ b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfDesSupport.c
@@ -0,0 +1,101 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+//
+// The functions in this file are used for initialization of the interface to the
+// OpenSSL library.
+
+//** Defines and Includes
+
+#include "Tpm.h"
+
+#if SYM_LIB == WOLF && defined TPM_ALG_TDES
+
+//**Functions
+//*** TDES_set_encyrpt_key()
+// This function makes creation of a TDES key look like the creation of a key for
+// any of the other OpenSSL block ciphers. It will create three key schedules,
+// one for each of the DES keys. If there are only two keys, then the third schedule
+// is a copy of the first.
+void
+TDES_set_encrypt_key(
+ const BYTE *key,
+ UINT16 keySizeInBits,
+ tpmKeyScheduleTDES *keySchedule
+ )
+{
+ DES_set_key_unchecked((const_DES_cblock *)key, &keySchedule[0]);
+ DES_set_key_unchecked((const_DES_cblock *)&key[8], &keySchedule[1]);
+ // If is two-key, copy the schedule for K1 into K3, otherwise, compute the
+ // the schedule for K3
+ if(keySizeInBits == 128)
+ keySchedule[2] = keySchedule[0];
+ else
+ DES_set_key_unchecked((const_DES_cblock *)&key[16],
+ &keySchedule[2]);
+}
+
+
+//*** TDES_encyrpt()
+// The TPM code uses one key schedule. For TDES, the schedule contains three
+// schedules. OpenSSL wants the schedules referenced separately. This function
+// does that.
+void TDES_encrypt(
+ const BYTE *in,
+ BYTE *out,
+ tpmKeyScheduleTDES *ks
+ )
+{
+ DES_ecb3_encrypt((const_DES_cblock *)in, (DES_cblock *)out,
+ &ks[0], &ks[1], &ks[2],
+ DES_ENCRYPT);
+}
+
+//*** TDES_decrypt()
+// As with TDES_encypt() this function bridges between the TPM single schedule
+// model and the OpenSSL three schedule model.
+void TDES_decrypt(
+ const BYTE *in,
+ BYTE *out,
+ tpmKeyScheduleTDES *ks
+ )
+{
+ DES_ecb3_encrypt((const_DES_cblock *)in, (DES_cblock *)out,
+ &ks[0], &ks[1], &ks[2],
+ DES_DECRYPT);
+}
+
+#endif // SYM_LIB == WOLF
diff --git a/TPMCmd/tpm/src/crypt/wolf/TpmToWolfMath.c b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfMath.c
new file mode 100644
index 0000000..8cbea96
--- /dev/null
+++ b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfMath.c
@@ -0,0 +1,569 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+//
+// This file contains the math functions that are not implemented in the BnMath
+// library (yet). These math functions will call the OpenSSL library to execute
+// the operations. There is a difference between the internal format and the
+// OpenSSL format. To call the OpenSSL function, a BIGNUM structure is created
+// for each passed variable. The sizes in the bignum_t are copied and the 'd'
+// pointer in the BIGNUM is set to point to the 'd' parameter of the bignum_t.
+// On return, SetSizeOsslToTpm is used for each returned variable to make sure that
+// the pointers are not changed. The size of the returned BIGGNUM is copied to
+// bignum_t.
+
+//** Includes and Defines
+#include "Tpm.h"
+
+#if MATH_LIB == WOLF
+
+#include "TpmToOsslMath_fp.h"
+
+//** Functions
+
+//*** OsslToTpmBn()
+// This function converts an OpenSSL BIGNUM to a TPM bignum. In this implementation
+// it is assumed that OpenSSL used the same format for a big number as does the
+// TPM -- an array of native-endian words in little-endian order.
+//
+// If the array allocated for the OpenSSL BIGNUM is not the space within the TPM
+// bignum, then the data is copied. Otherwise, just the size field of the BIGNUM
+// is copied.
+void
+OsslToTpmBn(
+ bigNum bn,
+ BIGNUM *osslBn
+ )
+{
+ if(bn != NULL)
+ {
+ if((crypt_uword_t *)osslBn->d != bn->d)
+ {
+ int i;
+ pAssert((unsigned)osslBn->top <= BnGetAllocated(bn));
+ for(i = 0; i < osslBn->top; i++)
+ bn->d[i] = osslBn->d[i];
+ }
+ BnSetTop(bn, osslBn->top);
+ }
+}
+
+//*** BigInitialized()
+// This function initializes an OSSL BIGNUM from a TPM bignum.
+BIGNUM *
+BigInitialized(
+ BIGNUM *toInit,
+ bigConst initializer
+ )
+{
+ if(toInit == NULL || initializer == NULL)
+ return NULL;
+ toInit->d = (BN_ULONG *)&initializer->d[0];
+ toInit->dmax = initializer->allocated;
+ toInit->top = initializer->size;
+ toInit->neg = 0;
+ toInit->flags = 0;
+ return toInit;
+}
+
+#ifndef OSSL_DEBUG
+# define BIGNUM_PRINT(label, bn, eol)
+# define DEBUG_PRINT(x)
+#else
+# define DEBUG_PRINT(x) printf("%s", x)
+# define BIGNUM_PRINT(label, bn, eol) BIGNUM_print((label), (bn), (eol))
+static
+void BIGNUM_print(
+ const char *label,
+ const BIGNUM *a,
+ BOOL eol
+ )
+{
+ BN_ULONG *d;
+ int i;
+ int notZero = FALSE;
+
+ if(label != NULL)
+ printf("%s", label);
+ if(a == NULL)
+ {
+ printf("NULL");
+ goto done;
+ }
+ if (a->neg)
+ printf("-");
+ for(i = a->top, d = &a->d[i - 1]; i > 0; i--)
+ {
+ int j;
+ BN_ULONG l = *d--;
+ for(j = BN_BITS2 - 8; j >= 0; j -= 8)
+ {
+ BYTE b = (BYTE)((l >> j) & 0xFF);
+ notZero = notZero || (b != 0);
+ if(notZero)
+ printf("%02x", b);
+ }
+ if(!notZero)
+ printf("0");
+ }
+done:
+ if(eol)
+ printf("\n");
+ return;
+}
+#endif
+
+#ifdef LIBRARY_COMPATIBILITY_CHECK
+void
+MathLibraryCompatibilityCheck(
+ void
+ )
+{
+ OSSL_ENTER();
+ BIGNUM *osslTemp = BN_CTX_get(CTX);
+ BN_VAR(tpmTemp, 64 * 8); // allocate some space for a test value
+ crypt_uword_t i;
+ TPM2B_TYPE(TEST, 16);
+ TPM2B_TEST test = {{16, {0x0F, 0x0E, 0x0D, 0x0C,
+ 0x0B, 0x0A, 0x09, 0x08,
+ 0x07, 0x06, 0x05, 0x04,
+ 0x03, 0x02, 0x01, 0x00}}};
+ // Convert the test TPM2B to a bigNum
+ BnFrom2B(tpmTemp, &test.b);
+ // Convert the test TPM2B to an OpenSSL BIGNUM
+ BN_bin2bn(test.t.buffer, test.t.size, osslTemp);
+ // Make sure the values are consistent
+ cAssert(osslTemp->top == (int)tpmTemp->size);
+ for(i = 0; i < tpmTemp->size; i++)
+ cAssert(osslTemp->d[0] == tpmTemp->d[0]);
+ OSSL_LEAVE();
+}
+#endif
+
+//*** BnModMult()
+// Does multiply and divide returning the remainder of the divide.
+LIB_EXPORT BOOL
+BnModMult(
+ bigNum result,
+ bigConst op1,
+ bigConst op2,
+ bigConst modulus
+ )
+{
+ OSSL_ENTER();
+ BIG_INITIALIZED(bnResult, result);
+ BIG_INITIALIZED(bnOp1, op1);
+ BIG_INITIALIZED(bnOp2, op2);
+ BIG_INITIALIZED(bnMod, modulus);
+ BIG_VAR(bnTemp, (LARGEST_NUMBER_BITS * 4));
+ BOOL OK;
+ pAssert(BnGetAllocated(result) >= BnGetSize(modulus));
+ OK = BN_mul(bnTemp, bnOp1, bnOp2, CTX);
+ OK = OK && BN_div(NULL, bnResult, bnTemp, bnMod, CTX);
+ if(OK)
+ {
+ result->size = bnResult->top;
+ OsslToTpmBn(result, bnResult);
+ }
+ OSSL_LEAVE();
+ return OK;
+}
+
+//*** BnMult()
+// Multiplies two numbers
+LIB_EXPORT BOOL
+BnMult(
+ bigNum result,
+ bigConst multiplicand,
+ bigConst multiplier
+ )
+{
+ OSSL_ENTER();
+ BN_VAR(temp, (LARGEST_NUMBER_BITS * 2));
+ BIG_INITIALIZED(bnTemp, temp);
+ BIG_INITIALIZED(bnA, multiplicand);
+ BIG_INITIALIZED(bnB, multiplier);
+ BOOL OK;
+ pAssert(result->allocated >=
+ (BITS_TO_CRYPT_WORDS(BnSizeInBits(multiplicand)
+ + BnSizeInBits(multiplier))));
+ OK = BN_mul(bnTemp, bnA, bnB, CTX);
+ if(OK)
+ {
+ OsslToTpmBn(temp, bnTemp);
+ BnCopy(result, temp);
+ }
+ OSSL_LEAVE();
+ return OK;
+}
+
+//*** BnDiv()
+// This function divides two bigNum values. The function returns FALSE if
+// there is an error in the operation.
+LIB_EXPORT BOOL
+BnDiv(
+ bigNum quotient,
+ bigNum remainder,
+ bigConst dividend,
+ bigConst divisor
+ )
+{
+ OSSL_ENTER();
+ BIG_INITIALIZED(bnQ, quotient);
+ BIG_INITIALIZED(bnR, remainder);
+ BIG_INITIALIZED(bnDend, dividend);
+ BIG_INITIALIZED(bnSor, divisor);
+ BOOL OK;
+ pAssert(!BnEqualZero(divisor));
+ if(BnGetSize(dividend) < BnGetSize(divisor))
+ {
+ if(quotient)
+ BnSetWord(quotient, 0);
+ if(remainder)
+ BnCopy(remainder, dividend);
+ OK = TRUE;
+ }
+ else
+ {
+ pAssert((quotient == NULL)
+ || (quotient->allocated >= (unsigned)(dividend->size
+ - divisor->size)));
+ pAssert((remainder == NULL)
+ || (remainder->allocated >= divisor->size));
+ OK = BN_div(bnQ, bnR, bnDend, bnSor, CTX);
+ if(OK)
+ {
+ OsslToTpmBn(quotient, bnQ);
+ OsslToTpmBn(remainder, bnR);
+ }
+ }
+ DEBUG_PRINT("In BnDiv:\n");
+ BIGNUM_PRINT(" bnDividend: ", bnDend, TRUE);
+ BIGNUM_PRINT(" bnDivisor: ", bnSor, TRUE);
+ BIGNUM_PRINT(" bnQuotient: ", bnQ, TRUE);
+ BIGNUM_PRINT(" bnRemainder: ", bnR, TRUE);
+ OSSL_LEAVE();
+ return OK;
+}
+
+#ifdef TPM_ALG_RSA
+//*** BnGcd()
+// Get the greatest common divisor of two numbers
+LIB_EXPORT BOOL
+BnGcd(
+ bigNum gcd, // OUT: the common divisor
+ bigConst number1, // IN:
+ bigConst number2 // IN:
+ )
+{
+ OSSL_ENTER();
+ BIG_INITIALIZED(bnGcd, gcd);
+ BIG_INITIALIZED(bn1, number1);
+ BIG_INITIALIZED(bn2, number2);
+ BOOL OK;
+ pAssert(gcd != NULL);
+ OK = BN_gcd(bnGcd, bn1, bn2, CTX);
+ if(OK)
+ {
+ OsslToTpmBn(gcd, bnGcd);
+ gcd->size = bnGcd->top;
+ }
+ OSSL_LEAVE();
+ return OK;
+}
+
+//***BnModExp()
+// Do modular exponentiation using bigNum values. The conversion from a bignum_t to
+// a bigNum is trivial as they are based on the same structure
+LIB_EXPORT BOOL
+BnModExp(
+ bigNum result, // OUT: the result
+ bigConst number, // IN: number to exponentiate
+ bigConst exponent, // IN:
+ bigConst modulus // IN:
+ )
+{
+ OSSL_ENTER();
+ BIG_INITIALIZED(bnResult, result);
+ BIG_INITIALIZED(bnN, number);
+ BIG_INITIALIZED(bnE, exponent);
+ BIG_INITIALIZED(bnM, modulus);
+ BOOL OK;
+//
+ OK = BN_mod_exp(bnResult, bnN, bnE, bnM, CTX);
+ if(OK)
+ {
+ OsslToTpmBn(result, bnResult);
+ }
+ OSSL_LEAVE();
+ return OK;
+}
+
+//*** BnModInverse()
+// Modular multiplicative inverse
+LIB_EXPORT BOOL
+BnModInverse(
+ bigNum result,
+ bigConst number,
+ bigConst modulus
+ )
+{
+ OSSL_ENTER();
+ BIG_INITIALIZED(bnResult, result);
+ BIG_INITIALIZED(bnN, number);
+ BIG_INITIALIZED(bnM, modulus);
+ BOOL OK;
+
+ OK = (BN_mod_inverse(bnResult, bnN, bnM, CTX) != NULL);
+ if(OK)
+ {
+ OsslToTpmBn(result, bnResult);
+ }
+ OSSL_LEAVE();
+ return OK;
+}
+#endif // TPM_ALG_RSA
+
+#ifdef TPM_ALG_ECC
+
+//*** PointFromOssl()
+// Function to copy the point result from an OSSL function to a bigNum
+static BOOL
+PointFromOssl(
+ bigPoint pOut, // OUT: resulting point
+ EC_POINT *pIn, // IN: the point to return
+ bigCurve E // IN: the curve
+ )
+{
+ BIGNUM *x = NULL;
+ BIGNUM *y = NULL;
+ BOOL OK;
+ BN_CTX_start(E->CTX);
+//
+ x = BN_CTX_get(E->CTX);
+ y = BN_CTX_get(E->CTX);
+
+ if(y == NULL)
+ FAIL(FATAL_ERROR_ALLOCATION);
+ // If this returns false, then the point is at infinity
+ OK = EC_POINT_get_affine_coordinates_GFp(E->G, pIn, x, y, E->CTX);
+ if(OK)
+ {
+ OsslToTpmBn(pOut->x, x);
+ OsslToTpmBn(pOut->y, y);
+ BnSetWord(pOut->z, 1);
+ }
+ else
+ BnSetWord(pOut->z, 0);
+ BN_CTX_end(E->CTX);
+ return OK;
+}
+
+//*** EcPointInitialized()
+// Allocate and initialize a point.
+static EC_POINT *
+EcPointInitialized(
+ pointConst initializer,
+ bigCurve E
+ )
+{
+ BIG_INITIALIZED(bnX, (initializer != NULL) ? initializer->x : NULL);
+ BIG_INITIALIZED(bnY, (initializer != NULL) ? initializer->y : NULL);
+
+ EC_POINT *P = (initializer != NULL && E != NULL)
+ ? EC_POINT_new(E->G) : NULL;
+ pAssert(E != NULL);
+ if(P != NULL)
+ EC_POINT_set_affine_coordinates_GFp(E->G, P, bnX, bnY, E->CTX);
+ return P;
+}
+
+//*** BnCurveInitialize()
+// This function initializes the OpenSSL group definition
+//
+// It is a fatal error if 'groupContext' is not provided.
+// return type: bigCurve *
+// NULL the TPM_ECC_CURVE is not valid
+// non-NULL points to a structure in 'groupContext'
+bigCurve
+BnCurveInitialize(
+ bigCurve E, // IN: curve structure to initialize
+ TPM_ECC_CURVE curveId // IN: curve identifier
+ )
+{
+ EC_GROUP *group = NULL;
+ EC_POINT *P = NULL;
+ const ECC_CURVE_DATA *C = GetCurveData(curveId);
+ BN_CTX *CTX = NULL;
+ BIG_INITIALIZED(bnP, C != NULL ? C->prime : NULL);
+ BIG_INITIALIZED(bnA, C != NULL ? C->a : NULL);
+ BIG_INITIALIZED(bnB, C != NULL ? C->b : NULL);
+ BIG_INITIALIZED(bnX, C != NULL ? C->base.x : NULL);
+ BIG_INITIALIZED(bnY, C != NULL ? C->base.y : NULL);
+ BIG_INITIALIZED(bnN, C != NULL ? C->order : NULL);
+ BIG_INITIALIZED(bnH, C != NULL ? C->h : NULL);
+ int OK = (C != NULL);
+//
+ OK = OK && ((CTX = OsslContextEnter()) != NULL);
+
+ // initialize EC group, associate a generator point and initialize the point
+ // from the parameter data
+ // Create a group structure
+ OK = OK && (group = EC_GROUP_new_curve_GFp(bnP, bnA, bnB, CTX)) != NULL;
+
+ // Allocate a point in the group that will be used in setting the
+ // generator. This is not needed after the generator is set.
+ OK = OK && ((P = EC_POINT_new(group)) != NULL);
+ // Need to use this in case Montgomery method is being used
+ OK = OK
+ && EC_POINT_set_affine_coordinates_GFp(group, P, bnX, bnY, CTX);
+ // Now set the generator
+ OK = OK && EC_GROUP_set_generator(group, P, bnN, bnH);
+
+ if(P != NULL)
+ EC_POINT_free(P);
+
+ if(!OK && group != NULL)
+ {
+ EC_GROUP_free(group);
+ group = NULL;
+ }
+ if(!OK && CTX != NULL)
+ {
+ OsslContextLeave(CTX);
+ CTX = NULL;
+ }
+
+ E->G = group;
+ E->CTX = CTX;
+ E->C = C;
+
+ return OK ? E : NULL;
+}
+
+//*** BnEccModMult()
+// This function does a point multiply of the form R = [d]S
+// return type: BOOL
+// FALSE failure in operation; treat as result being point at infinity
+LIB_EXPORT BOOL
+BnEccModMult(
+ bigPoint R, // OUT: computed point
+ pointConst S, // IN: point to multiply by 'd' (optional)
+ bigConst d, // IN: scalar for [d]S
+ bigCurve E
+ )
+{
+ EC_POINT *pR = EC_POINT_new(E->G);
+ EC_POINT *pS = EcPointInitialized(S, E);
+ BIG_INITIALIZED(bnD, d);
+
+ if(S == NULL)
+ EC_POINT_mul(E->G, pR, bnD, NULL, NULL, E->CTX);
+ else
+ EC_POINT_mul(E->G, pR, NULL, pS, bnD, E->CTX);
+ PointFromOssl(R, pR, E);
+ EC_POINT_free(pR);
+ EC_POINT_free(pS);
+ return !BnEqualZero(R->z);
+}
+
+//*** BnEccModMult2()
+// This function does a point multiply of the form R = [d]G + [u]Q
+// return type: BOOL
+// FALSE failure in operation; treat as result being point at infinity
+LIB_EXPORT BOOL
+BnEccModMult2(
+ bigPoint R, // OUT: computed point
+ pointConst S, // IN: optional point
+ bigConst d, // IN: scalar for [d]S or [d]G
+ pointConst Q, // IN: second point
+ bigConst u, // IN: second scalar
+ bigCurve E // IN: curve
+ )
+{
+ EC_POINT *pR = EC_POINT_new(E->G);
+ EC_POINT *pS = EcPointInitialized(S, E);
+ BIG_INITIALIZED(bnD, d);
+ EC_POINT *pQ = EcPointInitialized(Q, E);
+ BIG_INITIALIZED(bnU, u);
+
+ if(S == NULL || S == (pointConst)&E->C->base)
+ EC_POINT_mul(E->G, pR, bnD, pQ, bnU, E->CTX);
+ else
+ {
+ const EC_POINT *points[2];
+ const BIGNUM *scalars[2];
+ points[0] = pS;
+ points[1] = pQ;
+ scalars[0] = bnD;
+ scalars[1] = bnU;
+ EC_POINTs_mul(E->G, pR, NULL, 2, points, scalars, E->CTX);
+ }
+ PointFromOssl(R, pR, E);
+ EC_POINT_free(pR);
+ EC_POINT_free(pS);
+ EC_POINT_free(pQ);
+ return !BnEqualZero(R->z);
+}
+
+//** BnEccAdd()
+// This function does addition of two points.
+// return type: BOOL
+// FALSE failure in operation; treat as result being point at infinity
+LIB_EXPORT BOOL
+BnEccAdd(
+ bigPoint R, // OUT: computed point
+ pointConst S, // IN: point to multiply by 'd'
+ pointConst Q, // IN: second point
+ bigCurve E // IN: curve
+ )
+{
+ EC_POINT *pR = EC_POINT_new(E->G);
+ EC_POINT *pS = EcPointInitialized(S, E);
+ EC_POINT *pQ = EcPointInitialized(Q, E);
+//
+ EC_POINT_add(E->G, pR, pS, pQ, E->CTX);
+
+ PointFromOssl(R, pR, E);
+ EC_POINT_free(pR);
+ EC_POINT_free(pS);
+ EC_POINT_free(pQ);
+ return !BnEqualZero(R->z);
+}
+
+#endif // TPM_ALG_ECC
+
+#endif // MATHLIB WOLF \ No newline at end of file
diff --git a/TPMCmd/tpm/src/crypt/wolf/TpmToWolfSupport.c b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfSupport.c
new file mode 100644
index 0000000..542058b
--- /dev/null
+++ b/TPMCmd/tpm/src/crypt/wolf/TpmToWolfSupport.c
@@ -0,0 +1,92 @@
+/* Microsoft Reference Implementation for TPM 2.0
+ *
+ * The copyright in this software is being made available under the BSD License,
+ * included below. This software may be subject to other third party and
+ * contributor rights, including patent rights, and no such rights are granted
+ * under this license.
+ *
+ * Copyright (c) Microsoft Corporation
+ *
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//** Introduction
+//
+// The functions in this file are used for initialization of the interface to the
+// OpenSSL library.
+
+//** Defines and Includes
+
+#include "Tpm.h"
+
+#if MATH_LIB == WOLF
+
+// Used to pass the pointers to the correct sub-keys
+typedef const BYTE *desKeyPointers[3];
+
+//*** SupportLibInit()
+// This does any initialization required by the support library.
+LIB_EXPORT int
+SupportLibInit(
+ void
+ )
+{
+#ifdef LIBRARY_COMPATIBILITY_CHECK
+ MathLibraryCompatibilityCheck();
+#endif
+ return TRUE;
+}
+
+//*** OsslContextEnter()
+// This function is used to initialize an OpenSSL context at the start of a function
+// that will call to an OpenSSL math function.
+BN_CTX *
+OsslContextEnter(
+ void
+ )
+{
+ BN_CTX *context = BN_CTX_new();
+ if(context == NULL)
+ FAIL(FATAL_ERROR_ALLOCATION);
+ BN_CTX_start(context);
+ return context;
+}
+
+//*** OsslContextLeave()
+// This is the companion function to OsslContextEnter().
+void
+OsslContextLeave(
+ BN_CTX *context
+ )
+{
+ if(context != NULL)
+ {
+ BN_CTX_end(context);
+ BN_CTX_free(context);
+ }
+}
+#endif // MATH_LIB == WOLF
+
diff --git a/external/wolfssl b/external/wolfssl
new file mode 160000
+Subproject 82850422fc77dc49a2a423fdcbf0c3559b27add