8 releases

0.1.7 Feb 20, 2025
0.1.6 Feb 19, 2025
0.1.0 Jan 31, 2025

#1702 in Cryptography

Download history 108/week @ 2025-01-29 132/week @ 2025-02-05 229/week @ 2025-02-12 578/week @ 2025-02-19 20/week @ 2025-02-26

965 downloads per month
Used in module-lwe

MIT and AGPL-3.0-or-later

32KB
435 lines

ring-LWE

example workflow License: MIT Crates.io

Implmentation of lattice-based encryption method ring-LWE in pure Rust.

Description: This provides the basic PKE (keygen, encryption, and decryption) operations for the ring learning-with-errors scheme.

Disclaimer: This is not secure. It is not written in constant-time nor resistant to other side-channel attacks. This is intended for educational use and not for real-world applications.

Usage: In the src directory,

cargo build

To build the binary.

cargo test

  • Performs keygen/encrypt/decrypt for a test message.
  • Checks homomorphic addition and multiplcation hold for small values.

Note: Parameters optional via

  • --params <n> <q> <t> for ring-LWE

where n is the polynomial degree, q is the ciphertext modulus, t is the plaintext modulus.

If ommitted, the default parameters will be used.

cargo run -- keygen

This will generate a public/secret keypair.

cargo run -- encrypt <public_key> <message>

Generates the ciphertext.

cargo run -- decrypt <secret_key> <ciphertext>

Decrypts the ciphertext given a secret key, printing the plaintext message.

Benchmarks:

n q t keygen encrypt decrypt keygen_string encrypt_string decrypt_string
256 12289 2 41.565 µs 70.024 µs 29.741 µs 69.703 µs 99.181 µs 43.751 µs
512 12289 2 84.940 µs 150.17 µs 65.439 µs 141.31 µs 210.94 µs 95.640 µs
1024 12289 2 183.50 µs 326.54 µs 145.40 µs 293.69 µs 445.11 µs 200.24 µs

Dependencies

~3.5MB
~79K SLoC