randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.6k stars 570 forks source link

System_RNG failure after some RandomNumberGenerator::random_vec calls #4334

Closed torres98 closed 2 months ago

torres98 commented 2 months ago

Recently I've started noticing an odd behaviour with the System_RNG in my application. Specifically, after a few calls to Botan:UUID and RandomNumberGenerator::random_vec (using the same rng object), one eventually fails with the following exception:

System_RNG read failed error code 14

This happens everytime, after a fixed amount of calls (but only during `RandomNumberGenerator::random_vec). In my case, I call random_vec with 128 bytes as argument 15 times and then with 32 bytes 5 times. The RNG is initialized as follows:

std::unique_ptr<Botan::RandomNumberGenerator> rng = std::make_unique<Botan::System_RNG>();

This issue occurs on my laptop running Ubuntu 22.04LTS with libbotan-2-dev, and it gets even worse on my server running Ubuntu 24 (in this case it fails even after less calls). Let me know if I can provide you some other important information

torres98 commented 2 months ago

FOund the culprit, bad memory access on my side. Closing this issue