This project implements a basic homomorphic encryption scheme using RSA in Rust. It demonstrates the ability to perform computations (in this case, addition) directly on encrypted data, ensuring data privacy throughout the process.
- Homomorphic Addition: Add two encrypted numbers without decrypting them first.
- RSA Encryption and Decryption: Utilizes RSA encryption for secure data handling.
- Random Prime Generation: Randomly generates large primes using the Sieve of Eratosthenes algorithm.
- Modular Arithmetic: Implements modular exponentiation and extended Euclidean algorithms for RSA operations.
calc.rs
: Contains mathematical utilities, including the Extended Euclidean Algorithm and modular exponentiation.prime.rs
: Implements the Sieve of Eratosthenes for prime generation and random prime number generation within a specified range.trapdoor.rs
: Handles homomorphic encryption and decryption processes using RSA, performing the homomorphic addition operation.main.rs
: The entry point of the program that allows the user to input two natural numbers and demonstrates homomorphic addition.
- Prime Generation: Two random large prime numbers
p
andq
are generated using therand_prime
function fromprime.rs
. - RSA Setup: Using the generated primes, we compute
n = p * q
and the Euler’s totient functionφ(n)
. A public exponente
(set to 17) is chosen, and the private exponentd
is computed using the extended Euclidean algorithm. - Homomorphic Encryption: The two numbers provided by the user are encrypted individually using RSA encryption. Their encrypted versions are then multiplied to achieve the encrypted sum (homomorphic property).
- Decryption: The encrypted sum is decrypted using the private key
d
to reveal the result of the homomorphic addition.
-
Clone the repository:
git clone https://github.com/nikillxh/rsa-trapdoor cd rsa-trapdoor
-
Build and run the project:
cargo run
-
Input two natural numbers when prompted to perform homomorphic addition.