Fortuna PRNG C++ Source Code

Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CitadelSoftwareInc Namespace Reference


Classes

class  Counter128
 128 Bit Counter, uses two int64's More...

class  CryptoRand
 Wrapper for Win32 Crypto API, ensures handle to context is released. More...

class  CTRNonceCounter
 64 Bit Nonce and 64 Bit Counter used for CTR Encryption Mode More...

class  DelayedWriteFile
class  FastList
 Fast singly linked list used to hold vector contents in non continguous memory, also contains erase which writes over bytes of each value with rand() 256. More...

struct  FastList::ListItem
class  Fortuna
 Top Level Object for the PRNG, users create and interact with this to generate PRN's. More...

class  Generator
 Generator which generates the random numbers, requests reseed from the PoolMgr. More...

class  NCColln
 Templated collection class to store data non continguously. Uses a map internally. More...

class  NCColln::ListItem
class  Pool
 Threadshafe Pool object which runs on it's own thread, accumulates entropy from sources, and compacts the pool using SHA-256 when the pool requires compacting. The hash is done on the pool's thread. More...

class  PoolMgr
 Creates, Deletes and gives access to the Pools. More...

class  ProcessData
 Contains a snapshot of the Process data for a single process. Used to determine the change in process data when the next snapshot is taken. More...

class  ProcessInfoBase
class  ProcessInfoIoCounter
class  ProcessInfoMemory
class  ProcessInfoPerformance
class  ProcessInfoQueryWorkingSet
class  ProcessInfoTimes
class  SeedFile
class  Source
class  SourceClsid
class  SourceCryptoRand
class  SourceMgr
class  SourcePing
class  SourceProcess
class  SourceRegistryWalker
class  SourceTest
struct  tagECHOREPLY
struct  tagECHOREQUEST
struct  tagICMPHDR
struct  tagIPHDR
class  Timer

Typedefs

typedef std::vector< unsigned
char > 
vecuc
typedef std::vector< std::vector<
unsigned char > > 
vecvecuc
typedef std::deque< unsigned
char > 
dequc
typedef std::vector< std::pair<
unsigned char, int > > 
vecucint
typedef unsigned short u_short
typedef CitadelSoftwareInc::tagIPHDR IPHDR
typedef CitadelSoftwareInc::tagIPHDRPIPHDR
typedef CitadelSoftwareInc::tagICMPHDR ICMPHDR
typedef CitadelSoftwareInc::tagICMPHDRPICMPHDR
typedef CitadelSoftwareInc::tagECHOREQUEST ECHOREQUEST
typedef CitadelSoftwareInc::tagECHOREQUESTPECHOREQUEST
typedef CitadelSoftwareInc::tagECHOREPLY ECHOREPLY
typedef CitadelSoftwareInc::tagECHOREPLYPECHOREPLY

Functions

bool TestFastList001 ()
bool TestFastList ()
void AddFileTimeData (vecuc &vData, const FILETIME &filetime)
void AddFileTimeData2 (vecuc &vData, const FILETIME &filetime, const FILETIME &oldfiletime)
void AddString (vecuc &vData, const unsigned char *pString)
void AddBinaryData2 (vecuc &vData, const unsigned char *pData, const DWORD dwSize, const unsigned char *pOldData)
void AddBinaryData3 (vecuc &vData, const unsigned char *pData, const DWORD dwSize)
void AddStringData (vecuc &vData, const unsigned char *pData, const DWORD dwSize2)
void AddBinaryData (vecuc &vData, const unsigned char *pData, const DWORD dwSize)
void AddTimeData (vecuc &vData)
void EraseVector (vecuc &vData)
void EraseString (std::string &sString)
void EraseHash (sha256_ctx ctx[1])
bool EncryptCTRMode (vecuc &vInOut, vecuc &vKey, CTRNonceCounter &nonceCounter)
void InitRand (void *pVoid)
int ExtractVector (dequc &deqData, vecuc &vData)
void HashVector (vecuc &vData, vecuc &vHash)
void HashVector (vecuc &vData)
 Hash the contents of vData and return with the hash in the vector.

bool InitWinsock (unsigned char major, unsigned char minor)
template<typename T> void AddChaoticBytes (vecuc &vData, const T &t)
template<typename T> void GetRandomValue (T &t)
template<typename T> void AddToVector (vecuc &vData, const T &t)
template<typename T> void AddToVector2 (vecuc &vData, const T &t)
template<typename T> void AddToVector (std::vector< T > &target, std::vector< T > &source)
template<typename T> T GetFromVector (vecuc &vData)
template<typename T> T ExtractValue (dequc &deqData)
void AddProcessData (vecuc &vData)
void AddComputerName (vecuc &vData)
void AddWindowsVersion (vecuc &vData)
void AddSystemInfo (vecuc &vData)
void AddCurrentHwProfile (vecuc &vData)
void AddEnvStringData (vecuc &vData)
void AddMacAddresses (vecuc &vData)
void AddStartupInfo (vecuc &vData)
void AddGlobalMemoryStatus (vecuc &vData)
void AddWindowingInfo (vecuc &vData)
void GetMachineSignature (vecuc &vData)
 Get a hash of quantities that will provide a machine signature, such as mac address, current process info etc.

void FillinGuid (const char *pData, unsigned char guidvec[16])

Typedef Documentation

typedef std::deque<unsigned char> CitadelSoftwareInc::dequc
 

Definition at line 13 of file FortunaTypes.h.

Referenced by CitadelSoftwareInc::Fortuna::CheckHMac(), ExtractValue(), ExtractVector(), and CitadelSoftwareInc::Fortuna::ReadSeedFile().

typedef struct CitadelSoftwareInc::tagECHOREPLY CitadelSoftwareInc::ECHOREPLY
 

Referenced by CitadelSoftwareInc::SourcePing::RecvEchoReply().

typedef struct CitadelSoftwareInc::tagECHOREQUEST CitadelSoftwareInc::ECHOREQUEST
 

Referenced by CitadelSoftwareInc::SourcePing::SendEchoRequest().

typedef struct CitadelSoftwareInc::tagICMPHDR CitadelSoftwareInc::ICMPHDR
 

typedef struct CitadelSoftwareInc::tagIPHDR CitadelSoftwareInc::IPHDR
 

typedef struct CitadelSoftwareInc::tagECHOREPLY * CitadelSoftwareInc::PECHOREPLY
 

typedef struct CitadelSoftwareInc::tagECHOREQUEST * CitadelSoftwareInc::PECHOREQUEST
 

typedef struct CitadelSoftwareInc::tagICMPHDR * CitadelSoftwareInc::PICMPHDR
 

typedef struct CitadelSoftwareInc::tagIPHDR * CitadelSoftwareInc::PIPHDR
 

typedef unsigned short CitadelSoftwareInc::u_short
 

Definition at line 23 of file SourcePing.h.

Referenced by CitadelSoftwareInc::SourcePing::in_cksum(), and CitadelSoftwareInc::SourcePing::SendEchoRequest().

typedef std::vector<unsigned char> CitadelSoftwareInc::vecuc
 

Definition at line 10 of file FortunaTypes.h.

Referenced by AddBinaryData(), AddBinaryData2(), AddBinaryData3(), AddChaoticBytes(), AddComputerName(), AddCurrentHwProfile(), CitadelSoftwareInc::Timer::AddElapsedTime(), CitadelSoftwareInc::Timer::AddElapsedTimeDifference(), AddEnvStringData(), AddFileTimeData(), AddFileTimeData2(), AddGlobalMemoryStatus(), CitadelSoftwareInc::SeedFile::AddHMac(), AddMacAddresses(), CitadelSoftwareInc::Pool::AddMachineSignatureToPool(), CitadelSoftwareInc::SourceProcess::AddModuleData(), CitadelSoftwareInc::SourceProcess::AddModuleData2(), AddProcessData(), CitadelSoftwareInc::SourceProcess::AddProcessInfo(), CitadelSoftwareInc::FastList< unsigned char >::AddRandomData(), AddStartupInfo(), AddString(), AddStringData(), AddSystemInfo(), AddTimeData(), AddToVector(), CitadelSoftwareInc::CTRNonceCounter::AddToVector(), AddToVector2(), AddWindowingInfo(), AddWindowsVersion(), CitadelSoftwareInc::Fortuna::CheckHMac(), CitadelSoftwareInc::Pool::CompactPool(), CitadelSoftwareInc::SeedFile::CreateFileState(), EncryptCTRMode(), EraseVector(), ExtractVector(), CitadelSoftwareInc::SourceTest::GetChaoticData(), CitadelSoftwareInc::SourceRegistryWalker::GetChaoticData(), CitadelSoftwareInc::SourceProcess::GetChaoticData(), CitadelSoftwareInc::SourceCryptoRand::GetChaoticData(), CitadelSoftwareInc::Generator::GetCounter(), CitadelSoftwareInc::Generator::GetCurrentKey(), CitadelSoftwareInc::ProcessInfoQueryWorkingSet::GetData(), CitadelSoftwareInc::ProcessInfoPerformance::GetData(), CitadelSoftwareInc::ProcessInfoMemory::GetData(), CitadelSoftwareInc::ProcessInfoTimes::GetData(), CitadelSoftwareInc::ProcessInfoIoCounter::GetData(), GetFromVector(), GetMachineSignature(), CitadelSoftwareInc::Fortuna::GetSeedFileKey(), HashVector(), CitadelSoftwareInc::SourceRegistryWalker::LookForNextSubkey(), CitadelSoftwareInc::Fortuna::ReadSeedFile(), CitadelSoftwareInc::Generator::SetCounter(), CitadelSoftwareInc::Pool::SetHashPoolState(), CitadelSoftwareInc::Generator::SetKey(), CitadelSoftwareInc::Counter128::SetState(), and TestFastList001().

typedef std::vector<std::pair<unsigned char, int> > CitadelSoftwareInc::vecucint
 

Definition at line 15 of file FortunaTypes.h.

typedef std::vector<std::vector<unsigned char> > CitadelSoftwareInc::vecvecuc
 

Definition at line 11 of file FortunaTypes.h.

Function Documentation

void CitadelSoftwareInc::AddBinaryData vecuc &  vData,
const unsigned char *  pData,
const DWORD  dwSize
 

Definition at line 112 of file FortunaUtils.cpp.

References vecuc.

Referenced by AddCurrentHwProfile(), AddGlobalMemoryStatus(), AddMacAddresses(), CitadelSoftwareInc::Pool::AddMachineSignatureToPool(), CitadelSoftwareInc::SourceProcess::AddModuleData2(), AddStartupInfo(), AddSystemInfo(), AddTimeData(), AddWindowsVersion(), CitadelSoftwareInc::SourceRegistryWalker::GetChaoticData(), and CitadelSoftwareInc::ProcessInfoTimes::GetData().

00115 {
00116         unsigned char uc=0;
00117         for (int i=0; i<(int)dwSize; ++i)
00118         {
00119                 uc = pData[i];
00120                 
00121                 if (uc != 0x00 && uc != 0xff)
00122                         vData.push_back(uc);
00123         }
00124 }

void CitadelSoftwareInc::AddBinaryData2 vecuc &  vData,
const unsigned char *  pData,
const DWORD  dwSize,
const unsigned char *  pOldData
 

Definition at line 66 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::ProcessInfoQueryWorkingSet::GetData(), CitadelSoftwareInc::ProcessInfoPerformance::GetData(), and CitadelSoftwareInc::ProcessInfoMemory::GetData().

00070 {
00071         for (DWORD i=0; i<dwSize; ++i)
00072         {
00073                 if (pData[i] || pOldData[i])
00074                 {
00075                         vData.push_back(pData[i]);
00076                 }
00077         }
00078 }

void CitadelSoftwareInc::AddBinaryData3 vecuc &  vData,
const unsigned char *  pData,
const DWORD  dwSize
 

Definition at line 80 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::SourcePing::GetChaoticData(), CitadelSoftwareInc::ProcessInfoQueryWorkingSet::GetData(), CitadelSoftwareInc::ProcessInfoPerformance::GetData(), CitadelSoftwareInc::ProcessInfoMemory::GetData(), and CitadelSoftwareInc::Source::SendDataToPools().

00083 {
00084         for (DWORD i=0; i<dwSize; ++i)
00085         {
00086                 if (pData[i])
00087                 {
00088                         vData.push_back(pData[i]);
00089                 }
00090         }
00091 }

template<typename T>
void AddChaoticBytes vecuc &  vData,
const T &  t
 

Definition at line 44 of file FortunaUtils.h.

References vecuc.

00045         {
00046                 const int numBytes = sizeof(T);
00047                 const unsigned char* p = (const unsigned char*)(&t);
00048                 for (int i=0; i<numBytes; ++i)
00049                 {
00050                         vData.push_back(*p++);
00051                 }
00052         }

void AddComputerName vecuc &  vData  ) 
 

Definition at line 85 of file MachineSig.cpp.

References AddString(), and vecuc.

Referenced by GetMachineSignature().

00086 {
00087         COMPUTER_NAME_FORMAT names[8] = {ComputerNameNetBIOS, ComputerNameDnsHostname, ComputerNameDnsDomain, ComputerNameDnsFullyQualified,
00088                                                                          ComputerNamePhysicalNetBIOS, ComputerNamePhysicalDnsHostname, ComputerNamePhysicalDnsDomain,
00089                                                                          ComputerNamePhysicalDnsFullyQualified};
00090 
00091         const int MAXSIZE=1024;
00092         char buffer[MAXSIZE+1];
00093         memset(buffer,0,sizeof(buffer));
00094         DWORD dwSize = MAXSIZE;
00095 
00096         BOOL bStatus = TRUE;
00097         for(int i=0; i<8; ++i)
00098         {
00099                 dwSize = MAXSIZE;
00100                 bStatus = GetComputerNameEx(names[i], buffer, &dwSize);
00101                 if (bStatus)
00102                 {
00103                         AddString(vData, (const unsigned char*)buffer);
00104                 }
00105         }
00106 
00107 }

void AddCurrentHwProfile vecuc &  vData  ) 
 

Definition at line 139 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00140 {
00141         HW_PROFILE_INFO info;
00142         memset(&info, 0, sizeof(HW_PROFILE_INFO));
00143         BOOL bStatus = GetCurrentHwProfile(&info);
00144 
00145         if(bStatus)
00146         {
00147                 const unsigned char* pData = (unsigned char*)&info;
00148                 int size = sizeof(HW_PROFILE_INFO);
00149                 AddBinaryData(vData, pData, size);
00150         }
00151 
00152 }

void AddEnvStringData vecuc &  vData  ) 
 

Definition at line 154 of file MachineSig.cpp.

References vecuc.

Referenced by GetMachineSignature().

00155 {
00156         char* pVoid = GetEnvironmentStrings();
00157 
00158         if (!pVoid)
00159                 return;
00160 
00161         unsigned char uc=0;
00162         const char* pString = (const char*)pVoid;
00163 
00164         for (; *pString; ++pString)
00165         {
00166                 while(*pString)
00167                 {
00168                         uc = *pString++;
00169                         vData.push_back(uc);
00170                 }
00171         }
00172 
00173         BOOL bStatus = FreeEnvironmentStrings(pVoid);
00174         if (!bStatus)
00175         {
00176                 assert(0);
00177         }
00178 }

void CitadelSoftwareInc::AddFileTimeData vecuc &  vData,
const FILETIME &  filetime
 

Definition at line 24 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::SourceRegistryWalker::GetChaoticData(), and CitadelSoftwareInc::SourceRegistryWalker::LookForNextSubkey().

00025 {
00026         AddChaoticBytes<DWORD>(vData, filetime.dwHighDateTime);
00027         AddChaoticBytes<DWORD>(vData, filetime.dwLowDateTime);
00028 
00029 }

void CitadelSoftwareInc::AddFileTimeData2 vecuc &  vData,
const FILETIME &  filetime,
const FILETIME &  oldfiletime
 

Definition at line 31 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::ProcessInfoTimes::GetData().

00032 {
00033         const unsigned char *pNewData = (unsigned char*)(&filetime);
00034         const unsigned char *pOldData = (unsigned char*)(&oldfiletime);
00035 
00036         const int size = sizeof(FILETIME);
00037         for (int i=0; i<size; ++i)
00038         {
00039                 if (pNewData[i] || pOldData[i])
00040                 {
00041                         vData.push_back(pNewData[i]);
00042                 }
00043         }
00044 }

void AddGlobalMemoryStatus vecuc &  vData  ) 
 

Definition at line 223 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00224 {
00225 
00226         MEMORYSTATUSEX status;
00227         status.dwLength = sizeof(MEMORYSTATUSEX);
00228         BOOL bStatus = GlobalMemoryStatusEx(&status);
00229         if (bStatus)
00230         {
00231                 int size = sizeof(MEMORYSTATUSEX);
00232                 const unsigned char* pData = (unsigned char*)&status;
00233                 AddBinaryData(vData, pData, size);
00234         }
00235 }

void AddMacAddresses vecuc &  vData  ) 
 

Definition at line 181 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00182 {
00183         IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information 
00184                                            // for up to 16 NICs
00185         DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer
00186 
00187         DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
00188                         AdapterInfo,                   // [out] buffer to receive data
00189                         &dwBufLen);                    // [in] size of receive data buffer
00190   
00191         assert(dwStatus == ERROR_SUCCESS);  // Verify return value is 
00192                                         // valid, no buffer overflow
00193 
00194   PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
00195 
00196   int size = sizeof(IP_ADAPTER_INFO);
00197   
00198   do {
00199         const unsigned char* pData = (unsigned char*)pAdapterInfo;
00200 
00201         AddBinaryData(vData, pData, size);
00202 
00203     pAdapterInfo = pAdapterInfo->Next;    // Progress through 
00204                                           // linked list
00205   }
00206   while(pAdapterInfo);                    
00207 
00208 
00209 }

void AddProcessData vecuc &  vData  ) 
 

Definition at line 24 of file MachineSig.cpp.

References CitadelSoftwareInc::Timer::AddElapsedTime(), EraseVector(), CitadelSoftwareInc::ProcessInfoPerformance::GetData(), CitadelSoftwareInc::ProcessInfoMemory::GetData(), CitadelSoftwareInc::ProcessInfoTimes::GetData(), CitadelSoftwareInc::ProcessInfoIoCounter::GetData(), HashVector(), CitadelSoftwareInc::Timer::Start(), CitadelSoftwareInc::Timer::Stop(), and vecuc.

Referenced by GetMachineSignature().

00025 {
00026         Timer hpTimer;
00027 
00028         DWORD dwNeeded = 0;
00029         const int MAXSIZE=1024;
00030         std::vector<DWORD>dwPids;
00031         dwPids.resize(MAXSIZE);
00032 
00033         hpTimer.Start();
00034         BOOL bStatus = EnumProcesses(&dwPids[0], MAXSIZE*sizeof(DWORD), &dwNeeded);
00035         hpTimer.Stop();
00036         hpTimer.AddElapsedTime(vData);
00037 
00038         if (!bStatus)
00039                 return;
00040 
00041         DWORD dwNumPids = dwNeeded / sizeof(DWORD);
00042 
00043         DWORD dwPid=0;
00044         DWORD i=0;
00045         for (i=0; i<dwNumPids; ++i)
00046         {
00047                 dwPid = dwPids[i];
00048                 ProcessInfoIoCounter piioc;
00049                 hpTimer.Start();
00050                 piioc.GetData(vData, dwPid, NULL);
00051                 hpTimer.Stop();
00052                 hpTimer.AddElapsedTime(vData);
00053 
00054                 // next...
00055                 ProcessInfoTimes pitimes;
00056                 hpTimer.Start();
00057                 pitimes.GetData(vData, dwPid, NULL);
00058                 hpTimer.Stop();
00059                 hpTimer.AddElapsedTime(vData);
00060 
00061                 ProcessInfoMemory pim;
00062                 hpTimer.Start();
00063                 pim.GetData(vData, dwPid, NULL);
00064                 hpTimer.Stop();
00065                 hpTimer.AddElapsedTime(vData);
00066 
00067                 ProcessInfoPerformance pip;
00068                 hpTimer.Start();
00069                 pip.GetData(vData, dwPid, NULL);
00070                 hpTimer.Stop();
00071                 hpTimer.AddElapsedTime(vData);
00072         }
00073 
00074         // hash the process data
00075         vecuc vHash;
00076         HashVector(vData, vHash);
00077         EraseVector(vData);
00078 
00079         // copy the hash to vData and then erase vHash
00080         vData.resize(vHash.size());
00081         std::copy(vHash.begin(), vHash.end(), vData.begin());
00082         EraseVector(vHash);
00083 }

void AddStartupInfo vecuc &  vData  ) 
 

Definition at line 211 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00212 {
00213         STARTUPINFO info;
00214         info.cb = sizeof(STARTUPINFO);
00215 
00216         GetStartupInfo(&info);
00217 
00218         int size = sizeof(info);
00219         const unsigned char* pData =(unsigned char*)&info;
00220         AddBinaryData(vData, pData, size);
00221 }

void CitadelSoftwareInc::AddString vecuc &  vData,
const unsigned char *  pString
 

Definition at line 55 of file FortunaUtils.cpp.

References vecuc.

Referenced by AddComputerName(), and GetMachineSignature().

00056 {
00057         if (!pString)
00058                 return;
00059 
00060         while(*pString)
00061         {
00062                 vData.push_back(*pString++);
00063         }
00064 }

void CitadelSoftwareInc::AddStringData vecuc &  vData,
const unsigned char *  pData,
const DWORD  dwSize
 

Definition at line 95 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::SourceProcess::AddModuleData2(), CitadelSoftwareInc::SourceProcess::AddProcessInfo(), CitadelSoftwareInc::SourceRegistryWalker::GetChaoticData(), and CitadelSoftwareInc::SourceRegistryWalker::LookForNextSubkey().

00098 {
00099         if (!pData)
00100                 return;
00101 
00102         size_t dwSize = (size_t)dwSize2;
00103         if (dwSize2 == 0)
00104                 dwSize = strlen((const char*)pData);
00105 
00106         for (int i=0; i<(int)dwSize; ++i)
00107         {
00108                 vData.push_back(pData[i]);
00109         }
00110 }

void AddSystemInfo vecuc &  vData  ) 
 

Definition at line 126 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00127 {
00128         SYSTEM_INFO info;
00129         memset(&info,0,sizeof(SYSTEM_INFO));
00130 
00131         GetSystemInfo(&info);
00132 
00133         const unsigned char* pData = (unsigned char*)&info;
00134         int size = sizeof(SYSTEM_INFO);
00135 
00136         AddBinaryData(vData, pData, size);
00137 }

void CitadelSoftwareInc::AddTimeData vecuc &  vData  ) 
 

Definition at line 127 of file FortunaUtils.cpp.

References AddBinaryData(), and vecuc.

Referenced by CitadelSoftwareInc::SourceProcess::AddProcessInfo(), and GetMachineSignature().

00128 {
00129         // local time, wall clock local time, year, month, day, hour, minute, sec, ms
00130         SYSTEMTIME systemtime;
00131         GetLocalTime(&systemtime);
00132         AddBinaryData(vData, (const unsigned char*)&systemtime, sizeof(SYSTEMTIME));
00133 
00134         // ms since the sytem was started
00135         DWORD dwTime = GetTickCount();
00136         AddBinaryData(vData, (const unsigned char*)&dwTime, sizeof(DWORD));
00137 
00138         // high performance timer if available
00139         LARGE_INTEGER performanceCount;
00140         BOOL bTimer = QueryPerformanceCounter(&performanceCount);
00141 
00142         if (bTimer)
00143                 AddBinaryData(vData, (const unsigned char*)&performanceCount, sizeof(LARGE_INTEGER));
00144 
00145 }

template<typename T>
void AddToVector std::vector< T > &  target,
std::vector< T > &  source
 

Definition at line 96 of file FortunaUtils.h.

00097         {
00098                 std::vector<T>::iterator iter     = source.begin();
00099                 std::vector<T>::iterator end_iter = source.end();
00100                 for (; iter != end_iter; ++iter)
00101                 {
00102                         target.push_back(*iter);
00103                 }
00104         }

template<typename T>
void AddToVector vecuc &  vData,
const T &  t
 

Definition at line 66 of file FortunaUtils.h.

References vecuc.

Referenced by CitadelSoftwareInc::Pool::AddMachineSignatureToPool(), CitadelSoftwareInc::SeedFile::CreateFileState(), and GetMachineSignature().

00067         {
00068                 unsigned char uc=0;
00069                 T temp(t);
00070                 unsigned char* pData = (unsigned char*)&t;
00071                 int numBytes = sizeof(T);
00072                 for (int i=0; i<numBytes; ++i)
00073                 {
00074                         // LITTLE ENDIAN (lowest byte first)
00075                         uc = (unsigned char)(temp & 0xff);
00076                         vData.push_back(uc);
00077                         temp = temp >> 8;
00078                 }
00079         }

template<typename T>
void AddToVector2 vecuc &  vData,
const T &  t
 

Definition at line 82 of file FortunaUtils.h.

References vecuc.

Referenced by AddWindowingInfo(), and GetMachineSignature().

00083         {
00084                 unsigned char* pData = (unsigned char*)&t;
00085                 int numBytes = sizeof(T);
00086                 for (int i=0; i<numBytes; ++i)
00087                 {
00088                         if (pData[i])
00089                                 vData.push_back(pData[i]);
00090                 }
00091         }

void AddWindowingInfo vecuc &  vData  ) 
 

Definition at line 238 of file MachineSig.cpp.

References AddToVector2(), and vecuc.

Referenced by GetMachineSignature().

00239 {
00240         AddToVector2(vData, GetActiveWindow());
00241         AddToVector2(vData, GetCapture());
00242         AddToVector2(vData, GetClipboardOwner());
00243         AddToVector2(vData, GetClipboardViewer());
00244         AddToVector2(vData, GetCurrentProcess());
00245         AddToVector2(vData, GetCurrentProcessId());
00246         AddToVector2(vData, GetCurrentThread());
00247         AddToVector2(vData, GetCurrentProcessId());
00248         AddToVector2(vData, GetDesktopWindow());
00249         AddToVector2(vData, GetFocus());
00250         AddToVector2(vData, GetInputState());
00251         AddToVector2(vData, GetMessagePos());
00252         AddToVector2(vData, GetMessageTime());
00253         AddToVector2(vData, GetOpenClipboardWindow());
00254         AddToVector2(vData, GetProcessHeap());
00255         AddToVector2(vData, GetProcessWindowStation());
00256         AddToVector2(vData, GetQueueStatus(QS_ALLEVENTS));
00257         AddToVector2(vData, GetTickCount());
00258 }

void AddWindowsVersion vecuc &  vData  ) 
 

Definition at line 109 of file MachineSig.cpp.

References AddBinaryData(), and vecuc.

Referenced by GetMachineSignature().

00110 {
00111         OSVERSIONINFO version;
00112         memset(&version,0,sizeof(OSVERSIONINFO));
00113         version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00114 
00115         BOOL bStatus = GetVersionEx(&version);
00116 
00117         if (bStatus)
00118         {
00119                 int size = sizeof(OSVERSIONINFO);
00120                 const unsigned char* pData = (unsigned char*)&version;
00121                 AddBinaryData(vData, pData, size);
00122         }
00123 
00124 }

bool CitadelSoftwareInc::EncryptCTRMode vecuc &  vInOut,
vecuc &  vEncKey,
CTRNonceCounter &  nonceCounter
 

Definition at line 187 of file FortunaUtils.cpp.

References CitadelSoftwareInc::CTRNonceCounter::GetState(), CitadelSoftwareInc::CTRNonceCounter::Next(), and vecuc.

Referenced by CitadelSoftwareInc::SeedFile::CreateFileState(), and CitadelSoftwareInc::Fortuna::ReadSeedFile().

00190 {
00191         if (vInOut.size() == 0)
00192                 return true;                    // nothing to do
00193 
00194         if(vKey.size() != 32)
00195         {
00196                 assert(0);
00197                 return false;
00198         }
00199 
00200                 // use aes to encrypt the counter using the seed as a key
00201         AESencrypt aes;
00202         std::vector<unsigned char> vSeed;
00203 
00204         std::vector<unsigned char> outBlk;
00205         outBlk.resize(16);
00206 
00207         aes.key256(&vKey[0]);
00208 
00209         size_t numBytes = vInOut.size();
00210         size_t numBlocks = numBytes / 16;
00211         size_t numExtra =  numBytes - numBlocks*16;
00212 
00213         const unsigned char* pCounter = nonceCounter.GetState();
00214 
00215         size_t i=0;
00216         size_t iBlock=0;
00217         for (iBlock=0; iBlock<numBlocks; ++iBlock)
00218         {
00219                 aes.encrypt(pCounter,&outBlk[0]);
00220 
00221                 // use the encrypted cipher text as a stream cipher
00222                 for (i=0; i<16; ++i)
00223                         vInOut[iBlock*16+i] ^= outBlk[i];
00224                 nonceCounter.Next();
00225         }
00226         
00227         if (numExtra)
00228         {
00229                 aes.encrypt(pCounter, &outBlk[0]);
00230                 for (i=0; i<numExtra; ++i)
00231                         vInOut[numBlocks*16+i] ^= outBlk[i];
00232         }
00233 
00234 
00235         return true;
00236 }

void CitadelSoftwareInc::EraseHash sha256_ctx  ctx[1]  ) 
 

Definition at line 173 of file FortunaUtils.cpp.

Referenced by CitadelSoftwareInc::Pool::CompactPool(), HashVector(), and CitadelSoftwareInc::Fortuna::SetSeedFile().

00174 {
00175         // overwrite the data in ctx
00176         for (int i=0; i<8; ++i)
00177                 ctx[0].hash[i] = rand();
00178 
00179         for (i=0; i<16; ++i)
00180                 ctx[0].wbuf[i] = rand();
00181 }

void CitadelSoftwareInc::EraseString std::string &  sString  ) 
 

Definition at line 162 of file FortunaUtils.cpp.

Referenced by CitadelSoftwareInc::Fortuna::SetSeedFile().

00163 {
00164         size_t size = sString.size();
00165         for(size_t i=0; i<size; ++i)
00166         {
00167                 sString[i] = rand() % 128;
00168         }
00169         sString.clear();
00170 }

void CitadelSoftwareInc::EraseVector vecuc &  vData  ) 
 

Definition at line 148 of file FortunaUtils.cpp.

References vecuc.

Referenced by CitadelSoftwareInc::SeedFile::AddHMac(), CitadelSoftwareInc::Pool::AddMachineSignatureToPool(), AddProcessData(), CitadelSoftwareInc::Fortuna::CheckHMac(), CitadelSoftwareInc::SeedFile::CreateFileState(), GetMachineSignature(), CitadelSoftwareInc::Fortuna::GetSeedFileKey(), HashVector(), and CitadelSoftwareInc::Fortuna::ReadSeedFile().

00149 {
00150         int i=0;
00151         std::vector<unsigned char>::iterator iter = vData.begin();
00152         std::vector<unsigned char>::iterator end_iter = vData.end();
00153         for (; iter != end_iter; ++iter, ++i)
00154         {
00155                 vData[i] = rand() % 256;
00156         }
00157 
00158         vData.clear();
00159 }

template<typename T>
T ExtractValue dequc &  deqData  ) 
 

Definition at line 149 of file FortunaUtils.h.

References dequc.

00150         {
00151                 T t=0;
00152                 unsigned char uc=0;
00153                 unsigned char* pData = (unsigned char*)&t;
00154                 const size_t numBytes = sizeof(T);
00155 
00156                 if (numBytes > deqData.size())
00157                 {
00158                         assert(0);
00159                         return 0;
00160                 }
00161 
00162                 for (int i=0; i<numBytes; ++i)
00163                 {
00164                         uc = deqData[0];
00165                         pData[i] = uc;
00166                         deqData.pop_front();
00167 //  this doesn't work under Visual C++ 7.0 for __int64, it appears that you can't left shift more than 24 bits
00168 //                      uc = deqData[0];
00169 //                      T temp = (T)(uc << (i*8));
00170 //                      t += temp;
00171 //                      deqData.pop_front();
00172                 }
00173 
00174                 return t;
00175         }

int CitadelSoftwareInc::ExtractVector dequc &  deqData,
vecuc &  vData
 

Definition at line 259 of file FortunaUtils.cpp.

References dequc, and vecuc.

Referenced by CitadelSoftwareInc::Fortuna::ReadSeedFile().

00260         {
00261                 size_t deqSize = deqData.size();
00262                 size_t vecSize = vData.size();
00263 
00264                 if (vData.empty())
00265                         return 0;
00266 
00267                 if (vecSize > deqSize)
00268                 {
00269                         assert(0);
00270                         return 0;
00271                 }
00272 
00273                 for (size_t i=0; i<vecSize; ++i)
00274                 {
00275                         vData[i] = deqData[0];
00276                         deqData.pop_front();
00277                 }
00278 
00279                 return (int)vecSize;
00280         }

void FillinGuid const char *  pData,
unsigned char  guidvec[16]
 

Definition at line 19 of file SourceClsid.cpp.

Referenced by CitadelSoftwareInc::SourceClsid::GetChaoticData().

00020 {
00021         char sbuf[3];
00022         sbuf[2] = '\0';
00023 
00024         // strip out the { and } and - chars
00025         char buffer[40];
00026         memset(buffer,0,sizeof(buffer));
00027         int target=0;
00028 
00029         memset(guidvec,0,sizeof(guidvec));
00030 
00031         char c;
00032         while (*pData)
00033         {
00034                 // all guids in the clsid section of the registry have the same format
00035                 c = *pData;
00036                 if (c == '{' || c == '}' || c == '-')
00037                         ;
00038                 else
00039                         buffer[target++] = c;
00040 
00041                 ++pData;
00042         }
00043 
00044         unsigned int uc=0;
00045         for (int i=0; i<16; ++i)
00046         {
00047                 sbuf[0] = buffer[2*i];
00048                 sbuf[1] = buffer[2*i+1];
00049                 sbuf[2] = '\0';
00050                 sscanf(sbuf, "%x", &uc);
00051                 guidvec[i] = (unsigned char)uc;
00052         }
00053 
00054 }

template<typename T>
T GetFromVector vecuc &  vData  ) 
 

Definition at line 107 of file FortunaUtils.h.

References vecuc.

00108         {
00109                 T t=0;
00110         
00111                 unsigned char uc=0;
00112                 unsigned char* pData = (unsigned char*)&t;
00113                 int numBytes = sizeof(T);
00114                 for (int i=0; i<numBytes; ++i)
00115                 {
00116                         uc = vData[i];
00117                         t = t + (uc << (i*8));
00118                 }
00119 
00120                 return t;
00121         }

void CitadelSoftwareInc::GetMachineSignature vecuc &  vData  ) 
 

Get a hash of quantities that will provide a machine signature, such as mac address, current process info etc.

This is used after the seed file is processed to add something diffent to the pool hashes stored in the machine file to avoid provlems with reusing the same seed file.

Definition at line 264 of file MachineSig.cpp.

References AddComputerName(), AddCurrentHwProfile(), CitadelSoftwareInc::Timer::AddElapsedTime(), CitadelSoftwareInc::Timer::AddElapsedTimeDifference(), AddEnvStringData(), AddGlobalMemoryStatus(), AddMacAddresses(), AddProcessData(), AddStartupInfo(), AddString(), AddSystemInfo(), AddTimeData(), AddToVector(), AddToVector2(), AddWindowingInfo(), AddWindowsVersion(), EraseVector(), HashVector(), CitadelSoftwareInc::Timer::Start(), CitadelSoftwareInc::Timer::Stop(), and vecuc.

Referenced by CitadelSoftwareInc::Fortuna::ReadSeedFile().

00265         {
00266                 {
00267                         unsigned int count = 0;
00268                         Timer hpTimer;
00269                         for (int i=0; i<100; ++i)
00270                         {
00271                                 hpTimer.Start();
00272                                 Sleep(0);
00273                                 hpTimer.Stop();
00274                                 count += hpTimer.AddElapsedTimeDifference(vData);
00275                         }
00276                         assert(count);
00277                 }
00278 
00279 
00280                 Timer hpTimer;
00281                 hpTimer.Start();
00282 
00283                 vData.clear();
00284                 vData.reserve(10240);
00285 
00286                 // add in the current time data
00287                 AddTimeData(vData);
00288 
00289                 // add in the frequency of the high performance timer
00290                 LARGE_INTEGER liTemp;
00291                 BOOL bStatus = QueryPerformanceFrequency(&liTemp);
00292                 if (bStatus)
00293                 {
00294                         AddToVector2(vData, liTemp);
00295                 }
00296 
00297                 // add in the user name
00298                 char buffer[1025];
00299                 memset(buffer,0,sizeof(buffer));
00300                 DWORD dwSize = 1024;
00301                 bStatus = GetUserName(buffer, &dwSize);
00302                 if (bStatus)
00303                 {
00304                         AddString(vData, (const unsigned char*)buffer);
00305                 }
00306 
00307                 hpTimer.Start();
00308                 AddProcessData(vData);
00309                 hpTimer.Stop();
00310                 hpTimer.AddElapsedTime(vData);
00311 
00312                 hpTimer.Start();
00313                 AddComputerName(vData);
00314                 hpTimer.Stop();
00315                 hpTimer.AddElapsedTime(vData);
00316 
00317                 hpTimer.Start();
00318                 AddWindowsVersion(vData);
00319                 hpTimer.Stop();
00320                 hpTimer.AddElapsedTime(vData);
00321 
00322                 hpTimer.Start();
00323                 AddSystemInfo(vData);
00324                 hpTimer.Stop();
00325                 hpTimer.AddElapsedTime(vData);
00326 
00327                 hpTimer.Start();
00328                 AddCurrentHwProfile(vData);
00329                 hpTimer.Stop();
00330                 hpTimer.AddElapsedTime(vData);
00331 
00332                 hpTimer.Start();
00333                 AddEnvStringData(vData);
00334                 hpTimer.Stop();
00335                 hpTimer.AddElapsedTime(vData);
00336 
00337                 hpTimer.Start();
00338                 AddMacAddresses(vData);
00339                 hpTimer.Stop();
00340                 hpTimer.AddElapsedTime(vData);
00341 
00342                 hpTimer.Start();
00343                 AddStartupInfo(vData);
00344                 hpTimer.Stop();
00345                 hpTimer.AddElapsedTime(vData);
00346 
00347                 hpTimer.Start();
00348                 AddGlobalMemoryStatus(vData);
00349                 hpTimer.Stop();
00350                 hpTimer.AddElapsedTime(vData);
00351 
00352                 hpTimer.Start();
00353                 AddWindowingInfo(vData);
00354                 hpTimer.Stop();
00355                 hpTimer.AddElapsedTime(vData);
00356 
00357                 vecuc vHash;
00358                 HashVector(vData, vHash);
00359                 EraseVector(vData);
00360                 AddToVector(vData,vHash);
00361                 EraseVector(vHash);
00362         }

template<typename T>
void GetRandomValue T &  t  ) 
 

Definition at line 55 of file FortunaUtils.h.

00056         {
00057                 unsigned char* pData = (unsigned char*)&t;
00058                 int numBytes = sizeof(T);
00059                 for (int i=0; i<numBytes; ++i)
00060                 {
00061                         pData[i] = rand() % 256;
00062                 }
00063         }

void CitadelSoftwareInc::HashVector vecuc &  vData  ) 
 

Hash the contents of vData and return with the hash in the vector.

Definition at line 302 of file FortunaUtils.cpp.

References EraseVector(), HashVector(), and vecuc.

00303 {
00304         vecuc vHash;
00305         HashVector(vData, vHash);
00306 
00307         EraseVector(vData);
00308         vData.resize(vHash.size());
00309 
00310         std::copy(vHash.begin(), vHash.end(), vData.begin());
00311 
00312         EraseVector(vHash);
00313 }

void CitadelSoftwareInc::HashVector vecuc &  vData,
vecuc &  vHash
 

Definition at line 284 of file FortunaUtils.cpp.

References EraseHash(), EraseVector(), and vecuc.

Referenced by CitadelSoftwareInc::Pool::AddMachineSignatureToPool(), AddProcessData(), GetMachineSignature(), HashVector(), and CitadelSoftwareInc::Source::SendDataToPools().

00285 {
00286         EraseVector(vHash);
00287 
00288         size_t size = vData.size();
00289         vHash.resize(32);
00290 
00291         sha256_ctx ctx[1];
00292     sha256_begin(ctx);
00293 
00294         sha256_hash(&vData[0], (unsigned long)size, ctx);
00295 
00296         sha256_end(&vHash[0], ctx);
00297 
00298         EraseHash(ctx);
00299 }

void CitadelSoftwareInc::InitRand void *  pVoid  ) 
 

Definition at line 239 of file FortunaUtils.cpp.

References CitadelSoftwareInc::Timer::Curr(), and CitadelSoftwareInc::Timer::m_currTime.

Referenced by CitadelSoftwareInc::SeedFile::ThreadHandlerProc().

00240 {
00241         unsigned int seed = GetCurrentThreadId();
00242 #pragma warning(disable:4311)
00243         seed += (unsigned int)pVoid;
00244         seed += (unsigned int)time(NULL);
00245 
00246         Timer hpTimer;
00247         hpTimer.Curr();
00248 
00249         seed += hpTimer.m_currTime.LowPart;
00250         seed += hpTimer.m_currTime.HighPart;
00251 
00252         seed += GetCurrentProcessId();
00253 
00254         srand(seed);
00255 }

bool CitadelSoftwareInc::InitWinsock unsigned char  major,
unsigned char  minor
 

Definition at line 316 of file FortunaUtils.cpp.

Referenced by CitadelSoftwareInc::Fortuna::Fortuna().

00317 {
00318         WORD wVersionRequested;
00319         WSADATA wsaData;
00320         int err;
00321          
00322         wVersionRequested = MAKEWORD( major, minor );
00323          
00324         err = WSAStartup( wVersionRequested, &wsaData );
00325         if ( err != 0 ) {
00326                 /* Tell the user that we could not find a usable */
00327                 /* WinSock DLL.                                  */
00328                 return false;
00329         }
00330          
00331         /* Confirm that the WinSock DLL supports 2.2.*/
00332         /* Note that if the DLL supports versions greater    */
00333         /* than 2.2 in addition to 2.2, it will still return */
00334         /* 2.2 in wVersion since that is the version we      */
00335         /* requested.                                        */
00336          
00337         if ( LOBYTE( wsaData.wVersion ) != major ||
00338                         HIBYTE( wsaData.wVersion ) != minor ) {
00339                 /* Tell the user that we could not find a usable */
00340                 /* WinSock DLL.                                  */
00341                 WSACleanup( );
00342                 return false; 
00343         }
00344 
00345 
00346         return true;
00347 }

bool CitadelSoftwareInc::TestFastList  ) 
 

Definition at line 84 of file FastList.cpp.

References TestFastList001().

00085 {
00086         bool b1 = TestFastList001();
00087 
00088         return b1;
00089 }

bool TestFastList001  ) 
 

Definition at line 17 of file FastList.cpp.

References CitadelSoftwareInc::FastList< T >::Add(), CitadelSoftwareInc::FastList< T >::Extract(), CitadelSoftwareInc::FastList< T >::ExtractAndErase(), CitadelSoftwareInc::FastList< T >::Size(), and vecuc.

Referenced by TestFastList().

00018 {
00019         FastList<unsigned char> fl;
00020 
00021         unsigned char i=0;
00022         for(i=0; i<10; ++i)
00023                 fl.Add(i);
00024 
00025 //      std::vector<unsigned char> ucvec;
00026         vecuc ucvec;
00027 
00028         fl.Extract(ucvec);
00029 
00030         unsigned char uc = 0;
00031         for (i=0; i<10; ++i)
00032         {
00033                 uc = ucvec[i];
00034                 assert(uc == i);
00035         }
00036 
00037         fl.ExtractAndErase(ucvec);
00038 
00039         uc = 0;
00040         for (i=0; i<10; ++i)
00041         {
00042                 uc = ucvec[i];
00043                 assert(uc == i);
00044         }
00045 
00046         assert(fl.Size() == 0);
00047 
00048         // reuse the list - there should be no new allocations
00049         for(i=0; i<10; ++i)
00050                 fl.Add(i+10);
00051         
00052         fl.Extract(ucvec);
00053 
00054         uc = 0;
00055         for (i=0; i<10; ++i)
00056         {
00057                 uc = ucvec[i];
00058                 assert(uc-10 == i);
00059         }
00060 
00061         // add in 10 new items
00062         for(i=0; i<10; ++i)
00063                 fl.Add(i+20);
00064         
00065         fl.Extract(ucvec);
00066 
00067         uc = 0;
00068         for (i=0; i<10; ++i)
00069         {
00070                 uc = ucvec[i];
00071                 assert(uc-10 == i);
00072         }
00073 
00074         for (i=10; i<20; ++i)
00075         {
00076                 uc = ucvec[i];
00077                 assert(uc-20 == i-10);
00078         }
00079 
00080 
00081         return true;
00082 }

Generated on Sat Feb 28 17:24:41 2004 for Fortuna by doxygen 1.3.5