Rusty RSA
Many of our software vulnerabilities are caused by the C programming language, and these are typically caused by the usage of memory pointers. If we want to create more robust code, we must thus move to a programming language which checks the code before it is built. Thus Rust is proposed as one of the most robust around, so let’s do some RSA code with Rust. The great advantage with Rust over Python is that it produces robust machine level executables.
How RSA Works
With RSA, we create two prime numbers (P and Q), and then compute the modulus (N):
N=PQ
And then select e and d. Our public key is:
Pub=(e,N)
and private key (d is the inverse of e, mod N):
Priv=(d,N)
If we have a message of M, then the encrypted content is:
Enc=M^e (mod N)
and we decrypt with:
Dec=Enc^d (modN)
Implementing RSA in Rust
First we create the Rust project with:
cargo new rsa
We then go into the rsa folder, and add the following to the cargo.toml file:
[package]name = "rsa"
version = "0.1.0"
authors = ["billatnapier"]…