This project implements a Pseudo-Random Number Generation technique for generating encryption keys. It involves key generation using both system entropy and standard libraries.
This program will iterate through a range of seeds and attempt to decrypt a known ciphertext using the generated keys. If the correct key is found, it will print the seed and the corresponding key.
pseudo_rng/
├── generate_256bit_key
├── generate_256bit_key.c
├── generate_key
├── generate_key.c
├── guess_key
├── guess_key.c
└── README.md
generate_256bit_key.c
:
Generates a 256-bit key using
/dev/urandom
for high-quality randomness.
generate_key.c
:
Generates a 128-bit key using the standard library's
rand()
function seeded with the current time.
guess_key.c
:
Attempts to guess a key by iterating through possible seeds and decrypting known ciphertext using the generated keys.
guess_key
,generate_256bit_key
,generate_key
:
Executable files
- A C compiler (e.g.,
GCC
) - OpenSSL library - for cryptographic functions
- SEED-Ubuntu 20.04 VM (or you can tweak your Ubuntu to have SEED's capabilities)
Create a file for generating a random key
nano generate_key.c
Check
generate_key.c
in the repo
Compile & Run code:
gcc generate_key.c -o generate_key
./generate_key
N|B:
- The function
rand()
will generate a constant sequence of random numbers, whilesrand()
ensures there is a unique pattern every single time the code is executed.
rand()%256 keeps the generated number within the 0 to 255 range
Create a another file for the guessing key function/program
nano guess_key.c
Check
guess_key.c
in the repo
Convert the timestamp given to seconds
date -d "2018-04-17 23:08:49" +%s
Compile code:
gcc guess_key.c -o guess_key
./guess_key
N|B:- Use the EVP API (for encryption/decryption and for the cipher) instead of AES_DECRYPT
Generate the random numbers:
cat /dev/random | hexdump
cat /dev/urandom | hexdump
Monitor entropy:
watch -n 0.1 cat /proc/sys/kernel/random/entropy_avail
Place results in new file:
head -c 1M /dev/random > output.bin
Check output file's details:
ent output.bin
Create a file for generating a random key
nano generate_256bit_key.c
Check
generate_256bit_key.c
in the repo
Compile code & and run the executable file generated:
gcc generate_256bit_key.c -o generate_256bit_key
./generate_256bit_key
+-------------------------------------+ FIN +-----------------------------------+