MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / GetRnd

Function GetRnd

Libraries/unrar/crypt.cpp:113–134  ·  view source on GitHub ↗

Fill buffer with random data.

Source from the content-addressed store, hash-verified

111
112// Fill buffer with random data.
113void GetRnd(byte *RndBuf,size_t BufSize)
114{
115 bool Success=false;
116#if defined(_WIN_ALL)
117 HCRYPTPROV hProvider = 0;
118 if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
119 {
120 Success=CryptGenRandom(hProvider, (DWORD)BufSize, RndBuf) == TRUE;
121 CryptReleaseContext(hProvider, 0);
122 }
123#elif defined(_UNIX)
124 FILE *rndf = fopen("/dev/urandom", "r");
125 if (rndf!=NULL)
126 {
127 Success=fread(RndBuf, BufSize, 1, rndf) == BufSize;
128 fclose(rndf);
129 }
130#endif
131 // We use this code only as the last resort if code above failed.
132 if (!Success)
133 TimeRandomize(RndBuf,BufSize);
134}

Callers

nothing calls this directly

Calls 1

TimeRandomizeFunction · 0.85

Tested by

no test coverage detected