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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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!