title: PHP - Replacing mcrypt_create_iv() with openssl_random_pseudo_bytes()
body: <p>I need to up the security of our website, and is currently using the guide here: <a href="http://crackstation.net/hashing-security.htm" rel="noreferrer">http://crackstation.net/hashing-security.htm</a>, and also the generation of random passwords here: <a href="https://defuse.ca/generating-random-passwords.htm" rel="noreferrer">https://defuse.ca/generating-random-passwords.htm</a>. I gather that both uses the function <code>mcrypt_create_iv()</code> for generating random bytes (or bits?), but for some reason, I encounter errors in installing php-mcrypt under CentOS 6. Fortunately, the first link said that <code>openssl_random_pseudo_bytes()</code> is a CSPRNG (and the PHP documentation and other sources also back that claim), and is available on the current server installation of PHP 5.4, so I have no choice but to use that at the moment. With these in mind, I would like to ask the following:</p>
  
  <ol>
  <li><p>Does a direct code substitution suffice without affecting security? (That is, just replacing calls to <code>mcrypt_create_iv()</code> to <code>openssl_random_pseudo_bytes()</code> would do?)</p></li>
  <li><p>About the constants mentioned in the code (http://crackstation.net/hashing-security.htm#properhashing), the guide says that "[m]ake sure your salt is at least as long as the hash function's output." Am I right in assuming that <code>PBKDF2_SALT_BYTES</code> and <code>PBKDF2_HASH_BYTES</code> are both set to 24 bytes since the output of the <code>pbkdf2()</code> function would be just 24 bytes, not 32 (for 256 bits) since the underlying algorithm used is <code>sha256</code>? (Yes, I am using key stretching too.) In a related note, is 24 bytes fine, or should be increased/decreased, and what effect would that have?</p></li>
  </ol>
  
  <p>Advanced thanks for those who will answer.</p>