Pgen / C (secure)

Source ยป

Generates random passwords using the Sodium crypto library (libsodium) via randombytes_uniform(). This is cryptographically secure.

Compilation

Minimal

gcc -lsodium -o pgen.out pgen.c

Recommended (security, retpoline, and debugging)

gcc -Wall -Wconversion -Wextra -pedantic-errors -Wpedantic -lsodium -Ofast -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -mindirect-branch=thunk -mfunction-return=thunk -std=c11 -Wsign-conversion -Wformat-security -Werror -mmitigate-rop -fstack-protector-all -Wstack-protector --param ssp-buffer-size=4 -pie -fPIE -ftrapv -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -o pgen.out pgen.c

pgen.c

$ ./pgen.out --help
Usage: ./pgen.out [OPTION]... LEN

Generate cryptographically secure strings.

Example: ./pgen.out -LN 64

Options:
  -h, --help          display this help text and exit
  -p, --print-sets    print character sets and exit
  -z, --allow-zero    allow zero-length passwords (exiting with success)
  -A, --all           use all character sets (lower, numeric, special, upper)
  -L, --lower         generate lowercase letters
  -N, --numeric       generate numeric digits
  -S, --special       generate special characters
  -U, --upper         generate uppercase letters

Default length is 16, default character set is '--all'

Example

$ ./pgen.out 32 -LN
bdgsxge7njple2lqi2iq1va8k2m8t31h