Using pseudorandom number generators (PRNGs) is security-sensitive. For example, it has led in the past to the following vulnerabilities:

* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-6386[CVE-2013-6386]
* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3419[CVE-2006-3419]
* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-4102[CVE-2008-4102]

When software generates predictable values in a context requiring unpredictability, it may be possible for an attacker to guess the next value that will be generated, and use this guess to impersonate another user or access sensitive information.

As the functions rely on a pseudorandom number generator, they should not be used for security-critical applications or for protecting sensitive data.

include::../ask-yourself.adoc[]

== Recommended Secure Coding Practices

* Use functions which rely on a strong random number generator such as ``++randombytes_uniform()++`` or ``++randombytes_buf()++`` from ``++libsodium++``, or ``++randomize()++`` from Botan.
* Use the generated random values only once.
* You should not expose the generated random value. If you have to store it, make sure that the database or file is secure.

== Sensitive Code Example

----
#include <random>
// ...

void f() {
  int random_int = std::rand(); // Sensitive
}
----

== Compliant Solution

----
#include <sodium.h>
#include <botan/system_rng.h>
// ...

void f() {
  char random_chars[10];    
  randombytes_buf(random_chars, 10); // Compliant
  uint32_t random_int = randombytes_uniform(10); // Compliant

  uint8_t random_chars[10];
  Botan::System_RNG system;
  system.randomize(random_chars, 10); // Compliant
}
----

include::../see.adoc[]

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
