TLS, like most cryptographic protocols, depend on random numbers to generate keying material. These numbers should come from a trusted and truly random source. While this is necessary for production use, for testing purposes it is beneficial to use a pseudorandom number generator (PRNG). By seeding the generator with a static and not-random number, each execution of the protocol yields the same bytes which are sent over the network.
Furthermore, each execution gives the exactly same coverage, if the edges in the implementation of the protocol depend on random values. This is helpful for fuzzing, such that each run yields deterministic results.
OpenSSL internally uses an interface which is called rand.h. This API allows setting custom methods for generating random number.
I use this implementation of an OpenSSL random method which is based on the
srand functions of the C standard library.
By utilizing this random number generator we are able to generate deterministic random numbers. To use this library from Rust we create a public library which sets the above
I’m statically linking OpenSSL against my fuzzer which is called
tlspuffin. That means by utilizing
extern "C", we can easily call into C code.
We can call
make_openssl_deterministic from Rust and directly seed our random number generator with the number
I integrated this functionality into
openssl-src-rs, which builds OpenSSL using the build system of Rust. If you are interested you can take a look here.
There is also the C compilation flag:
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION which is used for fuzzing. A quick search through the OpenSSL code reveals though that the goal of this flag is not to make random number generation deterministic, but change the behavior of OpenSSL for fuzzing. It mostly skips error messages like in cmp_msg.c. Sadly, there is no official documentation which does into detail what the benefits of using the flag are.