Skip to content

Commit 347d9b3

Browse files
fixed a bug in HardwareRandomIsPresent()
queried wrong leave
1 parent 909ddbb commit 347d9b3

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed

HWRand.Net.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Global
2424
Release|Any CPU = Release|Any CPU
2525
Release|x64 = Release|x64
2626
Release|x86 = Release|x86
27+
RunCLI|Any CPU = RunCLI|Any CPU
28+
RunCLI|x64 = RunCLI|x64
29+
RunCLI|x86 = RunCLI|x86
2730
EndGlobalSection
2831
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2932
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.Debug|Any CPU.ActiveCfg = Debug|x64
@@ -38,6 +41,12 @@ Global
3841
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.Release|x64.Build.0 = Release|x64
3942
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.Release|x86.ActiveCfg = Release|Win32
4043
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.Release|x86.Build.0 = Release|Win32
44+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|Any CPU.ActiveCfg = RunCLI|x64
45+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|Any CPU.Build.0 = RunCLI|x64
46+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|x64.ActiveCfg = RunCLI|x64
47+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|x64.Build.0 = RunCLI|x64
48+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|x86.ActiveCfg = RunCLI|Win32
49+
{9D45458B-701C-484E-85F7-9C7D7C0EF344}.RunCLI|x86.Build.0 = RunCLI|Win32
4150
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4251
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
4352
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -50,6 +59,12 @@ Global
5059
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Release|x64.Build.0 = Release|Any CPU
5160
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Release|x86.ActiveCfg = Release|Any CPU
5261
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.Release|x86.Build.0 = Release|Any CPU
62+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|Any CPU.ActiveCfg = Release|Any CPU
63+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|Any CPU.Build.0 = Release|Any CPU
64+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|x64.ActiveCfg = Release|Any CPU
65+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|x64.Build.0 = Release|Any CPU
66+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|x86.ActiveCfg = Release|Any CPU
67+
{831A5A0A-7036-40E9-BCAA-A7111F2369C6}.RunCLI|x86.Build.0 = Release|Any CPU
5368
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5469
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Debug|Any CPU.Build.0 = Debug|Any CPU
5570
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -62,6 +77,12 @@ Global
6277
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Release|x64.Build.0 = Release|Any CPU
6378
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Release|x86.ActiveCfg = Release|Any CPU
6479
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.Release|x86.Build.0 = Release|Any CPU
80+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|Any CPU.ActiveCfg = Release|Any CPU
81+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|Any CPU.Build.0 = Release|Any CPU
82+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|x64.ActiveCfg = Release|Any CPU
83+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|x64.Build.0 = Release|Any CPU
84+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|x86.ActiveCfg = Release|Any CPU
85+
{EBCB17F7-5EA3-4F92-BDC1-4D4955652B71}.RunCLI|x86.Build.0 = Release|Any CPU
6586
EndGlobalSection
6687
GlobalSection(SolutionProperties) = preSolution
6788
HideSolutionNode = FALSE

HWRand.Net/CheckHardwareSupport.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace BSS.Random
55
{
6+
/// <summary>
7+
/// Allows you to directly call the RDSEED and RDRAND instruction from C#
8+
/// </summary>
69
public static partial class HWRandom
710
{
811
/// <summary>

HWRand.Net/HWRand.Net.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@
7272
</PropertyGroup>
7373
<PropertyGroup>
7474
<PostBuildEvent>copy ..\..\..\x64\Release\native.dll ..\..\..\Test-CLI-App\bin\Debug\native.dll
75+
copy ..\..\..\x64\Release\native.dll ..\..\..\Test-CLI-App\bin\Release\native.dll
76+
7577
robocopy .\ ..\..\..\Test-CLI-App\bin\Debug\ /xf *.tmp
7678
IF %25ERRORLEVEL%25 GEQ 8 exit 1
79+
80+
robocopy .\ ..\..\..\Test-CLI-App\bin\Release\ /xf *.tmp
81+
IF %25ERRORLEVEL%25 GEQ 8 exit 1
7782
exit 0</PostBuildEvent>
7883
</PropertyGroup>
7984
</Project>

native/native.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ __declspec(dllexport) bool HardwareRandomIsPresent()
4141
return 0;
4242
}
4343

44-
__cpuid(&cpuID, 1);
44+
__cpuid(&cpuID, 7);
4545

46-
if (!((cpuID.EBX & 0x40000) == 0x40000))
46+
if (!(cpuID.EBX & 0x40000) == 0x40000)
4747
{
4848
return 0;
4949
}

native/native.vcxproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
<Configuration>Release</Configuration>
1818
<Platform>x64</Platform>
1919
</ProjectConfiguration>
20+
<ProjectConfiguration Include="RunCLI|Win32">
21+
<Configuration>RunCLI</Configuration>
22+
<Platform>Win32</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfiguration Include="RunCLI|x64">
25+
<Configuration>RunCLI</Configuration>
26+
<Platform>x64</Platform>
27+
</ProjectConfiguration>
2028
</ItemGroup>
2129
<PropertyGroup Label="Globals">
2230
<VCProjectVersion>17.0</VCProjectVersion>
@@ -32,6 +40,12 @@
3240
<PlatformToolset>v143</PlatformToolset>
3341
<CharacterSet>Unicode</CharacterSet>
3442
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|Win32'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>true</UseDebugLibraries>
46+
<PlatformToolset>v143</PlatformToolset>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
3549
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3650
<ConfigurationType>Application</ConfigurationType>
3751
<UseDebugLibraries>false</UseDebugLibraries>
@@ -45,6 +59,12 @@
4559
<PlatformToolset>v143</PlatformToolset>
4660
<CharacterSet>Unicode</CharacterSet>
4761
</PropertyGroup>
62+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|x64'" Label="Configuration">
63+
<ConfigurationType>Application</ConfigurationType>
64+
<UseDebugLibraries>true</UseDebugLibraries>
65+
<PlatformToolset>v143</PlatformToolset>
66+
<CharacterSet>Unicode</CharacterSet>
67+
</PropertyGroup>
4868
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4969
<ConfigurationType>DynamicLibrary</ConfigurationType>
5070
<UseDebugLibraries>false</UseDebugLibraries>
@@ -61,12 +81,18 @@
6181
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
6282
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6383
</ImportGroup>
84+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|Win32'" Label="PropertySheets">
85+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
86+
</ImportGroup>
6487
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
6588
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6689
</ImportGroup>
6790
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
6891
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6992
</ImportGroup>
93+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|x64'" Label="PropertySheets">
94+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
95+
</ImportGroup>
7096
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
7197
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
7298
</ImportGroup>
@@ -75,6 +101,9 @@
75101
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
76102
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)\</IntDir>
77103
</PropertyGroup>
104+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|x64'">
105+
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)\</IntDir>
106+
</PropertyGroup>
78107
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
79108
<ClCompile>
80109
<WarningLevel>Level3</WarningLevel>
@@ -87,6 +116,18 @@
87116
<GenerateDebugInformation>true</GenerateDebugInformation>
88117
</Link>
89118
</ItemDefinitionGroup>
119+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|Win32'">
120+
<ClCompile>
121+
<WarningLevel>Level3</WarningLevel>
122+
<SDLCheck>true</SDLCheck>
123+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<ConformanceMode>true</ConformanceMode>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>Console</SubSystem>
128+
<GenerateDebugInformation>true</GenerateDebugInformation>
129+
</Link>
130+
</ItemDefinitionGroup>
90131
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
91132
<ClCompile>
92133
<WarningLevel>Level3</WarningLevel>
@@ -121,6 +162,24 @@
121162
<SubSystem>Windows</SubSystem>
122163
</Link>
123164
</ItemDefinitionGroup>
165+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RunCLI|x64'">
166+
<ClCompile>
167+
<WarningLevel>Level3</WarningLevel>
168+
<SDLCheck>true</SDLCheck>
169+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
170+
<ConformanceMode>true</ConformanceMode>
171+
<LanguageStandard>stdcpp20</LanguageStandard>
172+
<LanguageStandard_C>stdc17</LanguageStandard_C>
173+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
174+
<CompileAs>CompileAsC</CompileAs>
175+
</ClCompile>
176+
<Link>
177+
<GenerateDebugInformation>true</GenerateDebugInformation>
178+
<TerminalServerAware>true</TerminalServerAware>
179+
<LargeAddressAware>true</LargeAddressAware>
180+
<SubSystem>Console</SubSystem>
181+
</Link>
182+
</ItemDefinitionGroup>
124183
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
125184
<ClCompile>
126185
<WarningLevel>Level3</WarningLevel>

0 commit comments

Comments
 (0)