34 #if defined( _MSC_VER )
36 #define cpuid __asm _emit 0x0F __asm _emit 0xA2
37 #define rdtsc __asm _emit 0x0F __asm _emit 0x31
39 #define xstore_rng __asm _emit 0x0F __asm _emit 0xA7 __asm _emit 0xC0
40 #define rdrand_eax __asm _emit 0x0F __asm _emit 0xC7 __asm _emit 0xF0
42 #if defined __BORLANDC__
43 #define cpuid } __emit__( 0x0F, 0xA2 ); __asm {
44 #define rdtsc } __emit__( 0x0F, 0x31 ); __asm {
45 #define xstore_rng } __emit__( 0x0F, 0xA7, 0xC0 ); __asm {
46 #define rdrand_eax } __emit__( 0x0F, 0xC7, 0xF0 ); __asm {
52 #if defined( _MSC_VER ) && ( _MSC_VER >= 1400 )
53 #define addRandomHandle( randomState, handle ) \
54 addRandomLong( randomState, PtrToUlong( handle ) )
56 #define addRandomHandle addRandomValue
61 #define RANDOM_BUFSIZE 4096
62 #if RANDOM_BUFSIZE > MAX_INTLENGTH_SHORT
63 #error RANDOM_BUFSIZE exceeds randomness accumulator size
72 static unsigned int threadID;
82 #define SYSTEMRNG_BYTES 64
86 #define PROV_INTEL_SEC 22
87 #define INTEL_DEF_PROV "Intel Hardware Cryptographic Service Provider"
91 #define HCRYPTPROV HANDLE
112 typedef BOOL ( WINAPI *RTLGENRANDOM )( PVOID RandomBuffer,
119 static CRYPTACQUIRECONTEXT pCryptAcquireContext = NULL;
120 static CRYPTGENRANDOM pCryptGenRandom = NULL;
121 static CRYPTRELEASECONTEXT pCryptReleaseContext = NULL;
122 static RTLGENRANDOM pRtlGenRandom = NULL;
126 static BOOLEAN systemRngAvailable;
172 static void initSystemRNG(
void )
174 systemRngAvailable =
FALSE;
176 if( ( hAdvAPI32 = GetModuleHandle(
"AdvAPI32.dll" ) ) == NULL )
184 pCryptAcquireContext = ( CRYPTACQUIRECONTEXT ) GetProcAddress( hAdvAPI32,
185 "CryptAcquireContextA" );
186 pCryptGenRandom = ( CRYPTGENRANDOM ) GetProcAddress( hAdvAPI32,
188 pCryptReleaseContext = ( CRYPTRELEASECONTEXT ) GetProcAddress( hAdvAPI32,
189 "CryptReleaseContext" );
193 pRtlGenRandom = ( RTLGENRANDOM ) GetProcAddress( hAdvAPI32,
194 "SystemFunction036" );
202 if( ( pCryptAcquireContext == NULL || \
203 pCryptGenRandom == NULL || pCryptReleaseContext == NULL || \
206 ( pRtlGenRandom == NULL ) )
214 systemRngAvailable =
TRUE;
221 static void readSystemRNG(
void )
226 if( !systemRngAvailable )
275 CRYPT_IATTRIBUTE_ENTROPY );
281 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
289 static void endSystemRNG(
void )
293 pCryptReleaseContext( hProv, 0 );
316 #define SensorType char
325 unsigned char ssName[ 12 ];
326 char sspadding1[ 3 ];
331 char sspadding2[ 4 ];
333 char sspadding3[ 6 ];
343 unsigned char siSMB_Name[ 41 ];
354 unsigned char sdStart[ 41 ];
364 static void readMBMData(
void )
369 if( ( hMBMData = OpenFileMapping( FILE_MAP_READ,
FALSE,
370 "$M$B$M$5$S$D$" ) ) == NULL )
373 MapViewOfFile( hMBMData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
376 static const int quality = 20;
381 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
384 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
385 UnmapViewOfFile( mbmDataPtr );
387 CloseHandle( hMBMData );
396 static void readEverestData(
void )
399 const void *everestDataPtr;
401 if( ( hEverestData = OpenFileMapping( FILE_MAP_READ,
FALSE,
402 "EVEREST_SensorValues" ) ) == NULL )
404 if( ( everestDataPtr = MapViewOfFile( hEverestData,
405 FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
407 const int length = strlen( everestDataPtr );
412 static const int quality = 40;
415 min( length, 2048 ) );
417 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
420 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
422 UnmapViewOfFile( everestDataPtr );
424 CloseHandle( hEverestData );
440 #define SH_MEM_MAX_SENSORS 128
448 WCHAR m_section[ 64 ];
463 static void readSysToolData(
void )
468 if( ( hSysToolData = OpenFileMapping( FILE_MAP_READ,
FALSE,
469 "SysToolSensors" ) ) == NULL )
472 MapViewOfFile( hSysToolData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
475 static const int quality = 40;
480 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
483 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
484 UnmapViewOfFile( sysToolDataPtr );
486 CloseHandle( hSysToolData );
517 static void readRivaTunerData(
void )
522 if( ( hRivaTunerData = OpenFileMapping( FILE_MAP_READ,
FALSE,
523 "RTHMSharedMemory" ) ) == NULL )
526 MapViewOfFile( hRivaTunerData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
529 rivaTunerHeaderPtr->
dwVersion >= 0x10001 )
532 const BYTE *entryPtr = ( (
BYTE * ) rivaTunerHeaderPtr ) + \
534 const int entryTotalSize = rivaTunerHeaderPtr->
dwNumEntries * \
535 rivaTunerHeaderPtr->dwEntrySize;
536 static const int quality = 10;
539 min( entryTotalSize, 2048 ) );
541 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
544 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
546 UnmapViewOfFile( rivaTunerHeaderPtr );
548 CloseHandle( hRivaTunerData );
565 static void readHMonitorData(
void )
570 if( ( hHMonitorData = OpenFileMapping( FILE_MAP_READ,
FALSE,
571 "Hmonitor_Counters_Block" ) ) == NULL )
574 MapViewOfFile( hHMonitorData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
576 if( hMonitorDataPtr->
version >= 0x4100 && \
577 ( hMonitorDataPtr->
length >= 48 && hMonitorDataPtr->
length <= 1024 ) )
580 static const int quality = 40;
584 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
587 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
589 UnmapViewOfFile( hMonitorDataPtr );
591 CloseHandle( hHMonitorData );
620 static void readATITrayToolsData(
void )
625 if( ( hTrayToolsData = OpenFileMapping( FILE_MAP_READ,
FALSE,
626 "ATITRAY_SMEM" ) ) == NULL )
629 MapViewOfFile( hTrayToolsData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
631 if( trayToolsDataPtr->
CurGPU >= 100 && \
635 static const int quality = 10;
640 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
643 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
645 UnmapViewOfFile( trayToolsDataPtr );
647 CloseHandle( hTrayToolsData );
656 unsigned int uiLoad[ 256 ];
657 unsigned int uiTjMax[ 128 ];
670 static void readCoreTempData(
void )
675 if( ( hCoreTempData = OpenFileMapping( FILE_MAP_READ,
FALSE,
676 "CoreTempMappingObject" ) ) == NULL )
679 MapViewOfFile( hCoreTempData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
682 static const int quality = 15;
687 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
690 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
691 UnmapViewOfFile( coreTempDataPtr );
693 CloseHandle( hCoreTempData );
702 #define MAX_RECORDS 128
704 #pragma pack(push, 1)
728 static void readGPUZData(
void )
733 if( ( hGPUZData = OpenFileMapping( FILE_MAP_READ,
FALSE,
734 "GPUZShMem" ) ) == NULL )
737 MapViewOfFile( hGPUZData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
739 if( gpuzDataPtr->
version == 1 )
742 static const int quality = 10;
747 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
750 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
752 UnmapViewOfFile( gpuzDataPtr );
754 CloseHandle( hGPUZData );
770 #define DIGCF_PRESENT 0x02
771 #define DIGCF_ALLCLASSES 0x04
773 #define SPDRP_HARDWAREID 0x01
782 typedef BOOL ( WINAPI *SETUPDIDESTROYDEVICEINFOLIST )( HDEVINFO DeviceInfoSet );
783 typedef BOOL ( WINAPI *SETUPDIENUMDEVICEINFO )( HDEVINFO DeviceInfoSet,
786 typedef HDEVINFO ( WINAPI *SETUPDIGETCLASSDEVS )(
void *ClassGuid,
789 typedef BOOL ( WINAPI *SETUPDIGETDEVICEREGISTRYPROPERTY )( HDEVINFO DeviceInfoSet,
795 static void readPnPData(
void )
799 SETUPDIDESTROYDEVICEINFOLIST pSetupDiDestroyDeviceInfoList = NULL;
800 SETUPDIENUMDEVICEINFO pSetupDiEnumDeviceInfo = NULL;
801 SETUPDIGETCLASSDEVS pSetupDiGetClassDevs = NULL;
802 SETUPDIGETDEVICEREGISTRYPROPERTY pSetupDiGetDeviceRegistryProperty = NULL;
804 if( ( hSetupAPI = DynamicLoad(
"SetupAPI.dll" ) ) == NULL )
812 pSetupDiDestroyDeviceInfoList = ( SETUPDIDESTROYDEVICEINFOLIST ) \
813 GetProcAddress( hSetupAPI,
"SetupDiDestroyDeviceInfoList" );
814 pSetupDiEnumDeviceInfo = ( SETUPDIENUMDEVICEINFO ) \
815 GetProcAddress( hSetupAPI,
"SetupDiEnumDeviceInfo" );
816 pSetupDiGetClassDevs = ( SETUPDIGETCLASSDEVS ) \
817 GetProcAddress( hSetupAPI,
"SetupDiGetClassDevsA" );
818 pSetupDiGetDeviceRegistryProperty = ( SETUPDIGETDEVICEREGISTRYPROPERTY ) \
819 GetProcAddress( hSetupAPI,
"SetupDiGetDeviceRegistryPropertyA" );
820 if( pSetupDiDestroyDeviceInfoList == NULL || \
821 pSetupDiEnumDeviceInfo == NULL || pSetupDiGetClassDevs == NULL || \
822 pSetupDiGetDeviceRegistryProperty == NULL )
824 DynamicUnload( hSetupAPI );
829 hDevInfo = pSetupDiGetClassDevs( NULL, NULL, NULL,
831 if( hDevInfo != INVALID_HANDLE_VALUE )
836 BYTE pnpBuffer[ 512 + 8 ];
838 int deviceCount, iterationCount,
status;
844 memset( &devInfoData, 0,
sizeof( devInfoData ) );
846 for( deviceCount = 0, iterationCount = 0;
847 pSetupDiEnumDeviceInfo( hDevInfo, deviceCount,
850 deviceCount++, iterationCount++ )
852 if( pSetupDiGetDeviceRegistryProperty( hDevInfo, &devInfoData,
854 pnpBuffer, 512, &cbPnPBuffer ) )
855 addRandomData( randomState, pnpBuffer, cbPnPBuffer );
857 ENSURES_V( iterationCount < FAILSAFE_ITERATIONS_MAX );
858 pSetupDiDestroyDeviceInfoList( hDevInfo );
859 endRandomData( randomState, 5 );
862 DynamicUnload( hSetupAPI );
876 FILETIME creationTime, exitTime, kernelTime, userTime;
877 SIZE_T minimumWorkingSetSize, maximumWorkingSetSize;
878 MEMORYSTATUS memoryStatus;
883 int trngValue = 0,
status;
940 GetCaretPos( &point );
941 addRandomData( randomState, &point,
sizeof( POINT ) );
942 GetCursorPos( &point );
943 addRandomData( randomState, &point,
sizeof( POINT ) );
948 memoryStatus.dwLength =
sizeof( MEMORYSTATUS );
949 GlobalMemoryStatus( &memoryStatus );
950 addRandomData( randomState, &memoryStatus,
sizeof( MEMORYSTATUS ) );
954 handle = GetCurrentThread();
955 GetThreadTimes( handle, &creationTime, &exitTime, &kernelTime, &userTime );
956 addRandomData( randomState, &creationTime,
sizeof( FILETIME ) );
957 addRandomData( randomState, &exitTime,
sizeof( FILETIME ) );
958 addRandomData( randomState, &kernelTime,
sizeof( FILETIME ) );
959 addRandomData( randomState, &userTime,
sizeof( FILETIME ) );
960 handle = GetCurrentProcess();
961 GetProcessTimes( handle, &creationTime, &exitTime, &kernelTime, &userTime );
962 addRandomData( randomState, &creationTime,
sizeof( FILETIME ) );
963 addRandomData( randomState, &exitTime,
sizeof( FILETIME ) );
964 addRandomData( randomState, &kernelTime,
sizeof( FILETIME ) );
965 addRandomData( randomState, &userTime,
sizeof( FILETIME ) );
968 GetProcessWorkingSetSize( handle, &minimumWorkingSetSize,
969 &maximumWorkingSetSize );
975 if( !addedFixedItems )
977 STARTUPINFO startupInfo;
981 startupInfo.cb =
sizeof( STARTUPINFO );
982 GetStartupInfo( &startupInfo );
983 addRandomData( randomState, &startupInfo,
sizeof( STARTUPINFO ) );
986 addedFixedItems =
TRUE;
1077 #if defined( __WIN64__ )
1079 unsigned __int64
value;
1083 addRandomData( randomState, &value,
sizeof( __int64 ) );
1089 unsigned long value;
1102 LARGE_INTEGER performanceCount;
1104 if( QueryPerformanceCounter( &performanceCount ) )
1105 addRandomData( randomState, &performanceCount,
1106 sizeof( LARGE_INTEGER ) );
1126 struct alignStruct {
1130 struct alignStruct *rngBuffer = (
struct alignStruct * ) buffer;
1131 void *bufPtr = rngBuffer->buffer;
1149 mov [byteCount], eax
1155 addRandomData( randomState, bufPtr, byteCount );
1161 unsigned long buffer[ 8 + 8 ];
1170 mov [buffer+ecx], eax
1174 mov [byteCount], ecx
1179 addRandomData( randomState, buffer, byteCount );
1185 unsigned long value = 0;
1192 and eax, 0110000000000b
1193 cmp eax, 0010000000000b
1207 endRandomData( randomState, 34 + trngValue );
1224 #if VC_GE_2005( _MSC_VER )
1225 #define THREAD_ID ULONG_PTR
1227 #define THREAD_ID DWORD
1236 typedef BOOL ( WINAPI *HEAPNEXT )( LPHEAPENTRY32
lphe );
1243 static CREATESNAPSHOT pCreateToolhelp32Snapshot = NULL;
1244 static MODULEWALK pModule32First = NULL;
1245 static MODULEWALK pModule32Next = NULL;
1246 static PROCESSWALK pProcess32First = NULL;
1247 static PROCESSWALK pProcess32Next = NULL;
1248 static THREADWALK pThread32First = NULL;
1249 static THREADWALK pThread32Next = NULL;
1250 static HEAPLISTWALK pHeap32ListFirst = NULL;
1251 static HEAPLISTWALK pHeap32ListNext = NULL;
1252 static HEAPFIRST pHeap32First = NULL;
1253 static HEAPNEXT pHeap32Next = NULL;
1258 #define BIG_RANDOM_BUFSIZE ( RANDOM_BUFSIZE * 4 )
1259 #if BIG_RANDOM_BUFSIZE > MAX_INTLENGTH_SHORT
1260 #error BIG_RANDOM_BUFSIZE exceeds randomness accumulator size
1263 static void slowPollWin95(
void )
1266 PROCESSENTRY32 pe32;
1273 int iterationCount,
status;
1277 if( !addedFixedItems )
1280 addedFixedItems =
TRUE;
1284 if( pCreateToolhelp32Snapshot == NULL )
1290 if( ( hKernel = GetModuleHandle(
"Kernel32.dll" ) ) == NULL )
1294 pCreateToolhelp32Snapshot = ( CREATESNAPSHOT ) GetProcAddress( hKernel,
1295 "CreateToolhelp32Snapshot" );
1296 pModule32First = ( MODULEWALK ) GetProcAddress( hKernel,
1298 pModule32Next = ( MODULEWALK ) GetProcAddress( hKernel,
1300 pProcess32First = ( PROCESSWALK ) GetProcAddress( hKernel,
1302 pProcess32Next = ( PROCESSWALK ) GetProcAddress( hKernel,
1304 pThread32First = ( THREADWALK ) GetProcAddress( hKernel,
1306 pThread32Next = ( THREADWALK ) GetProcAddress( hKernel,
1308 pHeap32ListFirst = ( HEAPLISTWALK ) GetProcAddress( hKernel,
1309 "Heap32ListFirst" );
1310 pHeap32ListNext = ( HEAPLISTWALK ) GetProcAddress( hKernel,
1312 pHeap32First = ( HEAPFIRST ) GetProcAddress( hKernel,
1314 pHeap32Next = ( HEAPNEXT ) GetProcAddress( hKernel,
1318 if( pModule32First == NULL || pModule32Next == NULL || \
1319 pProcess32First == NULL || pProcess32Next == NULL || \
1320 pThread32First == NULL || pThread32Next == NULL || \
1321 pHeap32ListFirst == NULL || pHeap32ListNext == NULL || \
1322 pHeap32First == NULL || pHeap32Next == NULL || \
1323 pCreateToolhelp32Snapshot == NULL )
1327 pCreateToolhelp32Snapshot = NULL;
1340 hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
1369 hl32.dwSize =
sizeof( HEAPLIST32 );
1370 if( pHeap32ListFirst( hSnapshot, &hl32 ) )
1382 CloseHandle( hSnapshot );
1385 addRandomData( randomState, &hl32,
sizeof( HEAPLIST32 ) );
1389 he32.dwSize =
sizeof( HEAPENTRY32 );
1390 if( pHeap32First( &he32, hl32.th32ProcessID, hl32.th32HeapID ) )
1398 CloseHandle( hSnapshot );
1401 addRandomData( randomState, &he32,
1402 sizeof( HEAPENTRY32 ) );
1404 while( entryCount++ < 20 && pHeap32Next( &he32 ) );
1407 while( listCount++ < 20 && pHeap32ListNext( hSnapshot, &hl32 ) );
1411 pe32.dwSize =
sizeof( PROCESSENTRY32 );
1413 if( pProcess32First( hSnapshot, &pe32 ) )
1419 CloseHandle( hSnapshot );
1422 addRandomData( randomState, &pe32,
sizeof( PROCESSENTRY32 ) );
1424 while( pProcess32Next( hSnapshot, &pe32 ) && \
1429 te32.dwSize =
sizeof( THREADENTRY32 );
1431 if( pThread32First( hSnapshot, &te32 ) )
1437 CloseHandle( hSnapshot );
1440 addRandomData( randomState, &te32,
sizeof( THREADENTRY32 ) );
1442 while( pThread32Next( hSnapshot, &te32 ) && \
1447 me32.dwSize =
sizeof( MODULEENTRY32 );
1449 if( pModule32First( hSnapshot, &me32 ) )
1455 CloseHandle( hSnapshot );
1458 addRandomData( randomState, &me32,
sizeof( MODULEENTRY32 ) );
1460 while( pModule32Next( hSnapshot, &me32 ) && \
1465 CloseHandle( hSnapshot );
1470 endRandomData( randomState, 100 );
1491 typedef DWORD ( WINAPI *NETAPIBUFFERFREE )( LPVOID
lpBuffer );
1495 typedef DWORD ( WINAPI *NTQUERYSYSTEMINFORMATION )(
DWORD systemInformationClass,
1499 typedef DWORD ( WINAPI *NTQUERYINFORMATIONPROCESS )(
HANDLE processHandle,
1504 typedef DWORD ( WINAPI *NTPOWERINFORMATION )(
DWORD powerInformationClass,
1512 static NETSTATISTICSGET pNetStatisticsGet = NULL;
1513 static NETAPIBUFFERSIZE pNetApiBufferSize = NULL;
1514 static NETAPIBUFFERFREE pNetApiBufferFree = NULL;
1515 static NTQUERYSYSTEMINFORMATION pNtQuerySystemInformation = NULL;
1516 static NTQUERYINFORMATIONPROCESS pNtQueryInformationProcess = NULL;
1517 static NTPOWERINFORMATION pNtPowerInformation = NULL;
1524 #define PERFORMANCE_BUFFER_SIZE 65536
1525 #define PERFORMANCE_BUFFER_STEP 16384
1527 static void registryPoll(
void )
1530 PPERF_DATA_BLOCK pPerfData;
1532 DWORD dwSize, dwStatus;
1618 pPerfData = ( PPERF_DATA_BLOCK )
clAlloc(
"slowPollNT", cbPerfData );
1619 while( pPerfData != NULL && iterations++ < 10 )
1621 dwSize = cbPerfData;
1622 dwStatus = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
"Global", NULL,
1623 NULL, ( LPBYTE ) pPerfData, &dwSize );
1624 if( dwStatus == ERROR_SUCCESS )
1626 if( !memcmp( pPerfData->Signature, L
"PERF", 8 ) )
1628 static const int quality = 100;
1633 CRYPT_IATTRIBUTE_ENTROPY );
1638 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
1640 clFree(
"slowPollWinNT", pPerfData );
1645 if( dwStatus == ERROR_MORE_DATA )
1647 PPERF_DATA_BLOCK pTempPerfData;
1650 pTempPerfData = ( PPERF_DATA_BLOCK ) realloc( pPerfData, cbPerfData );
1651 if( pTempPerfData == NULL )
1655 clFree(
"slowPollWinNT", pPerfData );
1659 pPerfData = pTempPerfData;
1669 RegCloseKey( HKEY_PERFORMANCE_DATA );
1672 static void slowPollWinNT(
void )
1680 DWORD dwType, dwSize, dwResult;
1682 int nDrive, noResults = 0,
status;
1689 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
1690 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
1691 0, KEY_READ, &hKey ) == ERROR_SUCCESS )
1693 BYTE szValue[ 32 + 8 ];
1696 isWorkstation =
TRUE;
1697 if( RegQueryValueEx( hKey,
"ProductType", 0, NULL, szValue,
1698 &dwSize ) == ERROR_SUCCESS && \
1699 dwSize >= 5 &&
strCompare( szValue,
"WinNT", 5 ) )
1704 isWorkstation =
FALSE;
1707 RegCloseKey( hKey );
1713 if( !addedFixedItems )
1716 addedFixedItems =
TRUE;
1720 if( hNetAPI32 == NULL )
1723 if( ( hNetAPI32 = DynamicLoad(
"NetAPI32.dll" ) ) != NULL )
1726 pNetStatisticsGet = ( NETSTATISTICSGET ) GetProcAddress( hNetAPI32,
1727 "NetStatisticsGet" );
1728 pNetApiBufferSize = ( NETAPIBUFFERSIZE ) GetProcAddress( hNetAPI32,
1729 "NetApiBufferSize" );
1730 pNetApiBufferFree = ( NETAPIBUFFERFREE ) GetProcAddress( hNetAPI32,
1731 "NetApiBufferFree" );
1734 if( pNetStatisticsGet == NULL ||
1735 pNetApiBufferSize == NULL ||
1736 pNetApiBufferFree == NULL )
1739 DynamicUnload( hNetAPI32 );
1746 if( hNTAPI == NULL && \
1747 ( hNTAPI = GetModuleHandle(
"NTDll.dll" ) ) != NULL )
1750 pNtQuerySystemInformation = ( NTQUERYSYSTEMINFORMATION ) \
1751 GetProcAddress( hNTAPI,
"NtQuerySystemInformation" );
1752 pNtQueryInformationProcess = ( NTQUERYINFORMATIONPROCESS ) \
1753 GetProcAddress( hNTAPI,
"NtQueryInformationProcess" );
1754 if( pNtQuerySystemInformation == NULL || \
1755 pNtQueryInformationProcess == NULL )
1757 pNtPowerInformation = ( NTPOWERINFORMATION ) \
1758 GetProcAddress( hNTAPI,
"NtPowerInformation" );
1768 if( hNetAPI32 != NULL &&
1769 pNetStatisticsGet( NULL,
1770 isWorkstation ? L
"LanmanWorkstation" : L
"LanmanServer",
1771 0, 0, &lpBuffer ) == 0 )
1773 pNetApiBufferSize( lpBuffer, &dwSize );
1776 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
1777 pNetApiBufferFree( lpBuffer );
1783 BYTE diskPerformance[ 256 + 8 ];
1784 char szDevice[ 32 + 8 ];
1787 sprintf_s( szDevice, 32,
"\\\\.\\PhysicalDrive%d", nDrive );
1788 hDevice = CreateFile( szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
1789 NULL, OPEN_EXISTING, 0, NULL );
1790 if( hDevice == INVALID_HANDLE_VALUE )
1811 dwSize =
sizeof( diskPerformance );
1812 if( DeviceIoControl( hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0,
1813 &diskPerformance, 256, &dwSize, NULL ) )
1817 CloseHandle( hDevice );
1822 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
1824 CloseHandle( hDevice );
1842 if( ( hNTAPI == NULL ) || \
1861 for( dwType = 0; dwType < 64; dwType++ )
1865 if( dwType == 26 || dwType == 27 || dwType == 38 || \
1866 dwType == 38 || dwType == 46 || dwType == 47 || \
1867 dwType == 48 || dwType == 52 )
1885 dwResult = pNtQuerySystemInformation( dwType, buffer,
1888 if( dwResult != ERROR_SUCCESS )
1897 ulSize = 6 *
sizeof( ULONG );
1899 ulSize = 5 *
sizeof( ULONG );
1910 clFree(
"slowPollWinNT", buffer );
1916 CRYPT_IATTRIBUTE_ENTROPY );
1929 for( dwType = 0; dwType < 32; dwType++ )
1931 static const struct {
int type;
int size; } processInfo[] = {
1936 for( i = 0; processInfo[ i ].type !=
CRYPT_ERROR && \
1940 dwResult = pNtQueryInformationProcess( GetCurrentProcess(),
1941 processInfo[ i ].
type, buffer,
1942 processInfo[ i ].
size, &ulSize );
1943 if( dwResult != ERROR_SUCCESS )
1951 clFree(
"slowPollWinNT", buffer );
1957 CRYPT_IATTRIBUTE_ENTROPY );
1962 ENSURES( i < FAILSAFE_ITERATIONS_SMALL );
1971 if( pNtPowerInformation != NULL )
1973 static const struct {
int type;
int size; } powerInfo[] = {
1984 for( i = 0; powerInfo[ i ].type !=
CRYPT_ERROR && \
1988 dwResult = pNtPowerInformation( powerInfo[ i ].
type, NULL, 0, buffer,
1990 if( dwResult != ERROR_SUCCESS )
1994 clFree(
"slowPollWinNT", buffer );
2000 CRYPT_IATTRIBUTE_ENTROPY );
2004 ENSURES_V( i < FAILSAFE_ITERATIONS_MED );
2006 clFree(
"slowPollWinNT", buffer );
2010 if( noResults > 15 )
2012 static const int quality = 100;
2018 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
2034 typedef BOOL ( WINAPI *CREATERESTRICTEDTOKEN )(
HANDLE ExistingTokenHandle,
2036 PSID_AND_ATTRIBUTES SidsToDisable,
2037 DWORD DeletePrivilegeCount,
2038 PLUID_AND_ATTRIBUTES PrivilegesToDelete,
2039 DWORD RestrictedSidCount,
2040 PSID_AND_ATTRIBUTES SidsToRestrict,
2041 PHANDLE NewTokenHandle );
2042 static CREATERESTRICTEDTOKEN pCreateRestrictedToken = NULL;
2061 const HINSTANCE hAdvAPI32 = GetModuleHandle(
"AdvAPI32.dll" );
2063 pCreateRestrictedToken = ( CREATERESTRICTEDTOKEN ) \
2064 GetProcAddress( hAdvAPI32,
"CreateRestrictedToken" );
2068 if( pCreateRestrictedToken != NULL )
2070 HANDLE hToken, hNewToken;
2072 ImpersonateSelf( SecurityImpersonation );
2073 OpenThreadToken( GetCurrentThread(),
2074 TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | \
2075 TOKEN_QUERY | TOKEN_ADJUST_DEFAULT | \
2076 TOKEN_IMPERSONATE,
TRUE, &hToken );
2077 CreateRestrictedToken( hToken, DISABLE_MAX_PRIVILEGE, 0, NULL, 0, NULL,
2078 0, NULL, &hNewToken );
2079 SetThreadToken( &hThread, hNewToken );
2085 if( pCreateRestrictedToken != NULL )
2105 readRivaTunerData();
2107 readATITrayToolsData();
2116 if( hThread != NULL )
2125 NULL, 0, &threadID );
2148 hThread = (
HANDLE ) _beginthreadex( NULL, 0,
2150 NULL, 0, &threadID );
2165 const DWORD timeout = force ? 2000 : 300000L;
2175 if( hThread == NULL )
2182 dwResult = WaitForSingleObject( hThread, timeout );
2183 if( dwResult != WAIT_OBJECT_0 )
2187 DEBUG_DIAG((
"Error %lX waiting for object", dwResult ));
2191 assert( dwResult != WAIT_FAILED );
2197 if( hThread != NULL )
2199 CloseHandle( hThread );
2213 hAdvAPI32 = hNetAPI32 = hThread = NULL;
2219 assert( hThread == NULL );
2222 DynamicUnload( hNetAPI32 );