Author: Alessandro Conti - AlessandroConti11
License: MIT license.
Tags: #/dev/random
, #C
, #computer_engineering
, #computer_security
, #Linux
, #random_number
.
The project aims to generate unpredictable random numbers using the Linux Kernel's special device /dev/random.
To ensure that the project works properly, you must compile it and run it in a Unix environment from the terminal by following these steps:
- install gcc
sudo apt-get install gcc
- compile the project
gcc -Wall -Werror -O2 -g3 main.c -o EXECUTABLE
- run the project
- with entering the arguments from the command line
./EXECUTABLE MIN MAX
- without entering the arguments from the command line
./EXECUTABLE # at the beginning you will be asked to enter the minimum and maximum value
- with entering the arguments from the command line
The Makefile in the repository can also be used to compile the code.
- this option allows you to compile with the following tags: -Wall -Werror -O2 -g3
make compile
- if you want to specify different tags, you can set them
make compile CFLAGS=YOUR_FLAGS
- if you want to use Address SANitizer
make asan
Random number generation functions, such as the rand function of the standard C library, produce pseudo-random numbers. These numbers, although satisfying many of the desired properties of randomness, can be reproduced if the initial seed of the generated sequence is known. This reproducibility can pose a risk, especially in sensitive contexts such as cryptography, where a predictable sequence can compromise security.
To obtain truly random numbers, it is necessary to draw on external sources of randomness. The Linux Kernel relies on user input as a source of randomness. Special devices such as /dev/random and /dev/urandom exploit the delay between user actions, such as typing and mouse movements, to generate random numbers.
Linux offers two ways to access randomness. With /dev/random, if an attempt is made to read a large amount of data without further input from the user, the read operation is blocked, as the kernel has no further data from which to continue the random sequence. On the other hand, with /dev/urandom, the kernel uses a cryptographic algorithm to continue generating random numbers even in the absence of new input, ensuring that the read operation is not blocked. However, it is important to note that in this case the numbers generated can be considered pseudo-random, since they are derived from a previous sequence.