3 Implementing and exploiting RNGs
This chapter covers
- Implementing cryptographically secure pseudorandom number generators (CSPRNGs)
- How CSPRNGs can be compromised via weaknesses in their underlying algorithms
In the previous chapter, we saw how pseudorandom number generators (PRNGs) work in theory. Figure 3.1 shows a PRNG described by three operations:
Init(Seed)
transforms the seed to generateState
0
.Next(State
N
)
transformsState
N
to generateState
N+1
.Output(State
N
)
transformsState
N
to generateOutput
N
.
In this chapter, we will see how these functions are implemented for two widely known RNGs and then write code to exploit them. One is a CSPRNG that was recommended by the National Institute of Standards and Technology (NIST) for almost a decade! (Cryptographic implementations widely rely on algorithms and constants defined by NIST standards.)
Figure 3.1 PRNGs mutate the previous state to generate the next one.
