sl-paillier
sl-paillier provides a Paillier cryptosystem implementation built on
crypto-bigint.
The crate currently targets Rust 1.88 and ships a 2048-bit configuration as
its main public API.
Main types
SK2048: secret keyPK2048: public keyRawPlaintextRawCiphertext
Features
serde: enables serialization support for the 2048-bit key and ciphertext types, and exposesMinimalSK2048/MinimalPK2048for compact key serialization
Supported operations
- key generation with
SK2048::gen()/SK2048::gen_keys() - plaintext construction with
PK2048::message()andPK2048::into_message() - encryption with
PK2048::encrypt()orPK2048::encrypt_with_r() - decryption with
SK2048::decrypt()and CRT-acceleratedSK2048::decrypt_fast() - additive homomorphism with
PK2048::add() - multiplication by a plaintext scalar with
PK2048::mul()
PK2048::mul_vartime() is also exposed as an explicitly variable-time variant.
Example
use thread_rng;
use SK2048;
let mut rng = thread_rng;
let = SK2048gen_keys;
let m1 = pk.message.unwrap;
let m2 = pk.message.unwrap;
let c1 = pk.encrypt;
let c2 = pk.encrypt;
let sum = pk.add;
let doubled = pk.mul;
assert_eq!;
assert_eq!;
assert_eq!;
Notes
PK2048::message()interprets input bytes in little-endian order and returnsNoneif the resulting integer is not smaller thann.decrypt_fast()uses CRT precomputation and is intended to produce the same result asdecrypt().- Benchmarks live in
benches/sl-paillier.rs.