Contents
- Cryptographic randomness means unpredictability
- Entropy and number of bytes are different quantities
- Use the system generator via supported APIs
- Common random, seed and reproducibility
- The nonce is not always a secret, but it has precise rules
- How to verify implementation without a false sense of security
- Check when selecting an application or library
- Frequently asked questions
Cryptographic randomness means unpredictability
When creating a private key or reset token, you want the value to be practically impossible for an attacker to predict. It's not enough that the output looks messy or that the values don't usually repeat. A common pseudorandom generator for simulations can have good statistical properties and still be unsuitable for security secrets.
A cryptographically secure generator typically combines a true source of unpredictability with secure state propagation. Its output may be generated by deterministic computation, but it must have appropriate security properties and a high-quality initial state. Therefore, a simple division into true and computational randomness does not capture the practical design of a system CSPRNG.
Entropy and number of bytes are different quantities
A long string can be generated from an easily guessed input and not provide a corresponding amount of unpredictability. Expanding a timestamp hash to 32 bytes does not make the time a 256-bit secret. An attacker can try a limited space of possible times and compute the same outputs.
Likewise, handwritten sentences, device identifiers, or process numbers are not a good substitute for initialization. Hashing does not increase the number of initially possible secret states. For an application, a trusted system interface is usually the right choice, rather than collecting a few easily observable values and mixing them in-house.
Use the system generator via supported APIs
The operating system provides an interface for cryptographic bytes. On Linux, an example is getrandom, which has a defined behavior towards initializing the system generator. In common languages, use their security API, which relies on the system resource. Don't write your own generator just to avoid calling a library.
# Python: bezpečnostní token z místního systémového zdroje.
import secrets
token = secrets.token_urlsafe(32)This example creates a token from 32 random bytes and encodes it for transmission in a URL. This is not a universal command for generating every type of cryptographic key. For keys, use the library's API, which will correctly create a valid structure and distribution of values for the appropriate algorithm.
Common random, seed and reproducibility
Generators for simulations often intentionally have repeatable output when given the same seed. This is useful for testing, but dangerous for production secrets. If an attacker can derive the state or seed, they can predict other values. Don't just solve this by adding more statistical tests of the output.
A hard seed can be part of an isolated, reproducible test of a cryptographic library, as long as it is clearly separated from the production path. However, it must not accidentally get into the generation of raw keys. Use clearly synthetic identities in test data and ensure that they are never authorized in a real environment.
The nonce is not always a secret, but it has precise rules
The nonce or initialization vector may be public, yet repeating it or having the wrong size can seriously compromise security. The requirement depends on the design: in some cases uniqueness is important, in others unpredictability, and in some cases both. It is not correct to use the same rule for every encryption mode and every signature algorithm.
Use the recommended high-level API that manages the necessary parameters, and respect limits on the number of operations under a single key. Good randomness alone will not protect the algorithm if the application restores the old state and repeats a critical value. Consider initialization and state management when snapshotting virtual machines or cloning devices.
How to verify implementation without a false sense of security
A statistical test may reveal an obvious flaw, but it will not usually prove cryptographic unpredictability. Even the output of a secure cipher with a fixed, known key can appear random. The audit should therefore start with the origin of the bytes, the API used, error handling, and the entire lifecycle of the generator.
A system resource failure must not lead to a silent switch to time or regular random. Also, check that keys or tokens are not logged and that the program does not export them unnecessarily. A publicly displayed entropy monitor or illustrative animation is not itself a source for secret keys. A graphical explanation cannot be mistaken for a security design.
Check when selecting an application or library
- The source of the random bytes is specifically designated and trusted.
- The keys are generated by the corresponding cryptographic API.
- Solid test seeds are separate from production.
- Generation failure is visible and safely terminates the operation.
- The nonce and usage limits correspond to the chosen algorithm.
For a generator in CH-J Tools or another product, consider the actual implementation and release. Neither the name of the algorithm nor the long export prove high-quality randomness. The correct procedure also protects the generated material: an unpredictable key that subsequently appears in an unsecured log will no longer ensure the intended secrecy.
Frequently asked questions
Is it enough to hash the current time?
No. The length of the hash will not create unpredictability that the input did not have.
Will a statistical test prove a safe generator?
Not by yourself. You need to assess the construction, initialization, and source of entropy.
Is each nonce secret?
No. Its exact requirements depend on the specific cryptographic design.
Detailed documentation
Linux: getrandom and generator initialization →
Python: secrets security module →