A DRSA module capable of generating deterministic keys and a PRBG (Pseudo-Random Byte Generator) done with Python.
Complete documentation in the HTML format built with Sphinx can be found in docs/build/html/index.html
.
Create a Python environment:
python3 -m venv venv
source venv/bin/activate
Install the required requirements:
python3 -m pip install -r requirements.txt
These external libraries are used to:
- Draw charts and images for statistical purposes (Pillow and matplotlib).
- Export the RSA generated keys to the PEM format (rsa).
- Force Python int/long to be limited to 64bit (similar to Java long primitive type) (numpy).
- Optimization of the computations (numpy).
- Documentation (sphinx and sphinx_rtd_theme).
The implemented functionality and logic is not dependent on these libraries.
The randgen module can be used to:
- Perform benchmarking tests on the PRBG setup (may take a long time)
- Output a given ammount of pseudo-random bytes, according to the password, confusion string an iteration count parameters provided.
The program will perform 21 setups of the PRBG for each combination of confusion string size [1-3] / iteration count [1, 5, 10, 20, 50, 100, 200].
The statistical outputs will be saved in the statistics/
folder.
To perform benchmarking, run:
python3 randgen.py --benchmark
Run:
python3 randgen.py --pwd <your_password> --cs <your_confusion_string> --ic <your_iteration_count> --nob <number_of_bytes>
The generator will be setted up according to your parameters, which will influence the setup time. After the setup, the bytes will be outputed through the stdout.
To output an infinite sequence of pseudo-random bytes, choose --nob -1
.
The rsagen module implements the DRSA module, giving it pseudo-random bytes as it's input through stdin and later exporting the resulting DRSA key parameters to the PEM format.
To use it, we can first generate some pseudo-random bytes using the randgen module and then feed it's output to rsagen.
For example, the following commands:
python3 randgen.py --pwd ola --cs o --ic 2 --nob 512 > 512_random_bytes
python3 rsagen.py python_512 < 512_random_bytes
Will save a 4096bit RSA key pair to the files python_512_pub_key.pem
and python_512_priv_key.pem
, as the ones below:
-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAuN4IBvRZvVxw3bj/0nzKUMMhganHabrolqLUSnwKhqtKyLGP
Ezaf3W8sKWpclGgY1QRL9fd4BVQrMjc1YcG3rJzKg8K5n6GQrNgCxh7XmxTLk406
sxgG7lbH+9ARjS87aootL7abH2u6Or4fTRoXHuUl3DB2yitIwd2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Iwd2Ly0geISi+8jycOEh2
E2X1c3mnJ5W/7dt9eBWGmoLf2mXq0F1eLAWVsGxxiCPwPrRL/v0lU4MBNGsNcw1r
7DCjvTNV7jrampHN+CuOvr76/eKfXHmekt9AzBO9ml6fTmBlQXbvZS/58jt0ZcJk
x1Xerdbcejk2S3Q8RZ57r7Z2r7jp88CU/wi3p9qYEllxf+n4/lWfpVt9i9NAzESU
Ry6GJDqGjlCalistvOcrMJ+1gSYb4dCEO35dseRiKWzlOSGziO5I/hwIwsBP3Ahu
bqYGcUQrKPK1qfvA26T8j0PV52E6dRmC1ye4Hh7dJqWm596XS5XY9b7OFIFlraCx
1l8CN93T0KfUc3vIE+Dk9IT7okT6OhrgFnpw+NWSbsninytoJHFZPxHTLEMTrBwl
kNB/icfuGpeTlOm5y5CCWiN8A3+6w+5eZYsJwr76IC+mPrfFIk7heyGiqe0pLe7+
44tmD8y94UhSmsOy/laKtxi7kdgvQQlezID70Jk23U9b8RLrrnvNFKECAwEAAQ==
-----END RSA PUBLIC KEY-----
In this case the rsagen.py
execution was feeded with the randgen.py
outputed pseudo-bytes, but any source of randomness can be tested through the stdin.
The produced private RSA key can be checked with the following command:
openssl rsa -check -noout -in python_512_priv_key.pem -text