Пожалуйста, обратите внимание, что пользователь заблокирован
Локеры сосать
У вас должно быть более 300 реакций для просмотра скрытого контента.
Подарочек
C++:
#define INT_TO_BYTES(ptr, index, numPtr) ptr[0 + (index)] = (numPtr >> 24) & 0xFF; \
ptr[1 + (index)] = (numPtr >> 16) & 0xFF; \
ptr[2 + (index)] = (numPtr >> 8) & 0xFF; \
ptr[3 + (index)] = numPtr & 0xFF;
#define LE(p) ( (p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24) )
#define R(x,n) (((x) << (n)) | ((x) >> (32-(n))))
#define quarter(a,b,c,d) do {\
b ^= R(d+a, 7);\
c ^= R(a+b, 9);\
d ^= R(b+c, 13);\
a ^= R(c+d, 18);\
} while (0)
void salsa20_words(uint32_t *out, uint32_t in[16], uint32_t rounds) {
uint32_t x[4][4];
int i;
for (i = 0; i < 16; ++i) x[i / 4][i % 4] = in[i];
for (i = 0; i < (rounds / 2); ++i) {
quarter(x[0][0], x[1][0], x[2][0], x[3][0]);
quarter(x[1][1], x[2][1], x[3][1], x[0][1]);
quarter(x[2][2], x[3][2], x[0][2], x[1][2]);
quarter(x[3][3], x[0][3], x[1][3], x[2][3]);
quarter(x[0][0], x[0][1], x[0][2], x[0][3]);
quarter(x[1][1], x[1][2], x[1][3], x[1][0]);
quarter(x[2][2], x[2][3], x[2][0], x[2][1]);
quarter(x[3][3], x[3][0], x[3][1], x[3][2]);
}
for (i = 0; i < 16; ++i) out[i] = x[i / 4][i % 4] + in[i];
}
void salsa20_block(BYTE *out, BYTE key[32], uint64_t nonce, uint64_t index, uint32_t rounds) {
static char c[17] = "expand 32-byte k";
uint32_t in[16] = { LE(c), LE(key), LE(key + 4), LE(key + 8),
LE(key + 12), LE(c + 4), nonce & 0xffffffff, nonce >> 32,
index & 0xffffffff, index >> 32, LE(c + 8), LE(key + 16),
LE(key + 20), LE(key + 24), LE(key + 28), LE(c + 12) };
uint32_t wordout[16];
salsa20_words(wordout, in, rounds);
for (int i = 0; i < 64; ++i) out[i] = 0xff & (wordout[i / 4] >> (8 * (i % 4)));
}
void salsa20(BYTE *message, uint64_t mlen, BYTE key[32], uint64_t nonce, uint32_t rounds) {
BYTE block[64];
for (int i = 0; i < mlen; i++) {
if (i % 64 == 0) salsa20_block(block, key, nonce, i / 64, rounds);
message[i] ^= block[i % 64];
}
}
void CSPRNG::genRandom(_Out_ BYTE* buffer, _In_ SIZE_T length) {
BYTE key[32];
DWORD clock1;
DWORD clock2;
DWORD clock3;
FILETIME currentSystemTime;
LARGE_INTEGER perfomanceCounter;
__asm rdtsc;
__asm mov[clock1], eax;
__asm rdtsc;
__asm mov[clock2], eax;
__asm rdtsc;
__asm mov[clock3], eax;
if (DWORD dwId = GetCurrentProcessId()) {
if (DWORD dwThread = GetCurrentThreadId()) {
if (DWORD dwTickCount = GetTickCount()) {
GetSystemTimeAsFileTime(¤tSystemTime);
if (QueryPerformanceCounter(&perfomanceCounter)) {
INT_TO_BYTES(key, 0, dwId);
INT_TO_BYTES(key, 4, dwThread);
INT_TO_BYTES(key, 8, currentSystemTime.dwLowDateTime);
INT_TO_BYTES(key, 12, currentSystemTime.dwHighDateTime);
INT_TO_BYTES(key, 16, perfomanceCounter.QuadPart);
INT_TO_BYTES(key, 20, clock1);
INT_TO_BYTES(key, 24, clock2);
INT_TO_BYTES(key, 28, clock3);
for (int i = 0; i < length; i++) {
DWORD rdtscBuf;
__asm rdtsc;
__asm mov[rdtscBuf], eax;
buffer[i] = rdtscBuf % 0xFF;
}
salsa20(key, 32, key, GetTickCount64(), 4);
salsa20(buffer, length, key, GetTickCount64(), 12);
}
}
}
}
}