Skip to content

how to: random byte generator

amir zamani edited this page Aug 5, 2016 · 2 revisions

this feature is based on counter mode deterministic random byte generator (CTR_DRBG) by AES-256 (NIST SP 800-90) and internally uses an entropy collection modules. this approach is known to be secure and safe.

rnd_generator rgen;
auto random_data1 = rgen.make(64); // in bytes
// entropy and ctr_drbg are not so cheap, reuse them:
auto iv = rgen.make(16);  // in bytes

// update internal state with custom data (may helps entropy)
rgen.update(some_random_volatile_data);
auto nonce = rgen.make<QByteArray>(32);

warning: a not-so-secure random generator is a serious flaw for security. never ever use a generator if it's not been specially certified for cryptography or prepare for the eventual disaster.

warning: entropy and random byte generator are not so cheap and fast by the their nature and depend on OS, hardware, amount of available entropy to the system at runtime and ... the execution time may differs a lot. so use them efficiently.

see rnd_generator.hpp

Clone this wiki locally