Randomness
Where Passgen gets its random data from, and how to change it.
Passgen needs secure random data to generate sequences. By default, it uses the best source of randomness available on the system:
- On Linux, the getrandom system call. This is the most secure source of randomness on the platform.
- On macOS, arc4random_buf, which is equally secure.
- On other systems, including the WebAssembly build, it reads
from
/dev/urandom.
These pool randomness from various sources, such as jitter, interrupt timings and the random number generator built into the CPU.
Other sources
The --random flag selects a different source of randomness. Some sources take an
argument.
| Source | Description |
|---|---|
system | The system random number generator. This is the default. |
file:/path/to/file | Reads random data from the given file. This can be a device, such as /dev/random or a hardware randomness generator. |
master:VERSION:LEVEL:PASS:SEED:DOMAIN:USER | What master-passphrase mode uses, without needing a configuration. |
chacha20:KEY[:IV] | The ChaCha20 stream cipher. The key is 64 hex digits, and the optional initialization vector is 16. |
xorshift:SEED | Xorshift, seeded with a number from 1 to 264-1. Produces very poor quality randomness. |
zero | Returns only zeroes instead of random data. Only useful for testing. |
For deterministic output that is still secure, use a master passphrase instead.
The master source
The master source generates the same as --master, with everything given on the
command line instead of in the configuration:
$ passgen -r 'master:1:2:mymasterpass::example.com:username' -p apple2
eINh6m-RhafGJ-JgiKM0
All six fields have to be there. The seed, the domain and the user can be empty,
as the seed is here. The seed is written in hex. A colon or a backslash inside a
field is written as \: or \\.
Before 0.5.0, this source was called chacha20-argon2. It no longer exists, and
master generates different passphrases.
Streams and offsets
The master, chacha20, xorshift and zero sources are deterministic: the same
source always gives the same output. Each of them has many independent streams of
random data, numbered from 0.
With --amount, every sequence is generated from its own stream. The first comes
from stream 0, the second from stream 1, and so on. A sequence therefore only
depends on its number, and not on the sequences before it.
With --offset N, Passgen starts at stream N instead of 0. So --offset 2
generates what the third sequence of --amount 3 is:
$ passgen -r xorshift:1 -a 3 '[a-z]{8}'
kgkrcixk
bbjffbrn
vosbtqbt
$ passgen -r xorshift:1 --offset 2 '[a-z]{8}'
vosbtqbt
The system and files have no streams, so --offset cannot be used with them.
Before 0.5.0, all sequences came from a single stream. With --amount, every
sequence after the first one is different from what older versions generated.