24.11.2016 Views

Not So Random

Not%20So%20Random%20-%20Exploiting%20Unsafe%20Random%20Number%20Generator%20Use

Not%20So%20Random%20-%20Exploiting%20Unsafe%20Random%20Number%20Generator%20Use

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PHP Bounded mt_rand() – Patched Untwister<br />

…<br />

uint32_t PHP_mt19937::random(<br />

{<br />

uint32_t result = genrand_int32(m_mt) >> 1;<br />

if (m_isBounded) {<br />

result = (uint32_t)((m_minBound) + (long) ((double) ( (double) (m_maxBound) -<br />

(m_minBound) + 1.0) * ((result) / ((2147483647) + 1.0))));<br />

}<br />

return result;<br />

}<br />

…<br />

void PHP_mt19937::setBounds(uint32_t min, uint32_t max)<br />

{<br />

m_minBound = min;<br />

m_maxBound = max;<br />

m_isBounded = true;<br />

}<br />

…<br />

<strong>Not</strong> <strong>So</strong> <strong>Random</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!