rspec/rules/S6432/common/fix/randomized-nonce.adoc
Egon Okerman b0968585b4
Modify rule S6432: update to LaYC format (APPSEC-974) (#2972)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-08-31 15:05:45 +02:00

8 lines
890 B
Plaintext

==== Generating nonces using random number generation
When using a randomized approach, NIST recommends a nonce of at least 96 bits using a cryptographically secure pseudorandom number generator (CSPRNG.) Such a generator can create output with a sufficiently low probability of the same number being output twice (also called a __collision__) for a long time. However, after 2^32^ generated numbers for the same key, NIST recommends rotating this key for a new one. After that amount of generated numbers, the probability of a collision is high enough to be considered insecure.
The code example above demonstrates how CSPRNGs can be used to generate nonces.
Be careful to use a random number generator that is sufficiently secure. Default (non-cryptographically secure) RNGs might be more prone to collisions in their output, which is catastrophic for counter-based encryption modes.