Rust One-Time Pad Utilities
Two tools written in Rust for working with one-time pads. The first is used for generating one-time pads, the second is used to encrypt/decrypt files with those pads.
Disclaimer: While the theory of one-time pads is cryptographically sound, I would not necessarily suggest that you use the implementation in this project for anything you consider highly sensitive. There are possibly vulnerabilities in the pad generation or side channels in the file encryption that leak data.
One-Time Pad Generation
The otpgen
tool generates one (or more) one-time pads with a user-specified number of random bytes.
To generate a 1MB pad:
./target/release/otpgen -s 1000000
To generate 10 pads that are 1MB each
./target/release/otpgen -n 10 -s 1000000
Generating 10 one-time pads with 1000000 bytes each [==================================================]: 100.00% Generated pads/0.pad [==================================================]: 100.00% Generated pads/1.pad [==================================================]: 100.00% Generated pads/2.pad [==================================================]: 100.00% Generated pads/3.pad [==================================================]: 100.00% Generated pads/4.pad [==================================================]: 100.00% Generated pads/5.pad [==================================================]: 100.00% Generated pads/6.pad [==================================================]: 100.00% Generated pads/7.pad [==================================================]: 100.00% Generated pads/8.pad [==================================================]: 100.00% Generated pads/9.pad
Documentation
USAGE:
otpgen [OPTIONS] --size <size>
OPTIONS:
-n, --number <number> The number of pads to generate [default: 1]
-s, --size <size> The size of the pads (in bytes)
Encrypting a file
The otpencrypt
tool uses a user-provided one-time pad to encrypt or decrypt an input file's contents, byte by byte. It can be used with any type of file.
To encrypt the file document.txt
using the pad onetimepad
:
./target/release/otpencrypt encrypt --input document.txt --pad onetimepad
This will produce an encrypted file document.txt.encrypted
.
Documentation
USAGE:
otpencrypt encrypt --input <input> --pad <pad>
OPTIONS:
-i, --input <input> The file to be encrypted
-p, --pad <pad> The one-time pad
Decrypting a file
The otpencrypt
tool is also used here.
To decrypt the file document.txt.encrypted
using the pad onetimepad
:
./target/release/otpencrypt decrypt --input document.txt.encrypted --pad onetimepad
This will produce the original document.txt
file if the same pad is used for both operations.
Documentation:
USAGE:
otpencrypt decrypt --input <input> --pad <pad>
OPTIONS:
-i, --input <input> The file to be decrypted
-p, --pad <pad> The one-time pad
The Code
All of the code for this is available on Github.