#![no_std]
#![cfg_attr(feature = "nightly", feature(external_doc))]
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
mod ciphertext;
mod decrypt;
mod encrypt;
use curve25519_dalek::constants::{RISTRETTO_BASEPOINT_POINT, RISTRETTO_BASEPOINT_TABLE, RISTRETTO_BASEPOINT_COMPRESSED};
use curve25519_dalek::ristretto::RistrettoBasepointTable;
pub use curve25519_dalek::scalar::Scalar;
pub use curve25519_dalek::ristretto::RistrettoPoint;
pub use curve25519_dalek::ristretto::CompressedRistretto;
pub use curve25519_dalek::traits::Identity;
pub use curve25519_dalek::traits::IsIdentity;
pub use curve25519_dalek::traits::MultiscalarMul;
pub use ciphertext::Ciphertext;
pub use decrypt::DecryptionKey;
pub use encrypt::EncryptionKey;
pub const GENERATOR_POINT: RistrettoPoint = RISTRETTO_BASEPOINT_POINT;
pub const GENERATOR_POINT_COMPRESSED: CompressedRistretto = RISTRETTO_BASEPOINT_COMPRESSED;
pub const GENERATOR_TABLE: RistrettoBasepointTable = RISTRETTO_BASEPOINT_TABLE;
#[cfg(test)]
mod tests {
use rand::prelude::StdRng;
use rand_core::SeedableRng;
use crate::{DecryptionKey, RistrettoPoint};
#[test]
fn encrypt_decrypt() {
const N: usize = 100;
let mut rng = StdRng::from_entropy();
let dk = DecryptionKey::new(&mut rng);
let ek = dk.encryption_key();
for _ in 0..N {
let m = RistrettoPoint::random(&mut rng);
let ct = ek.encrypt(m, &mut rng);
let decrypted = dk.decrypt(ct);
assert_eq!(m, decrypted);
}
}
#[test]
fn rerandomisation() {
const N: usize = 100;
let mut rng = StdRng::from_entropy();
let dk = DecryptionKey::new(&mut rng);
let ek = dk.encryption_key();
let m = RistrettoPoint::random(&mut rng);
let ct = ek.encrypt(m, &mut rng);
for _ in 0..N {
let ct = ek.rerandomise(ct, &mut rng);
let decrypted = dk.decrypt(ct);
assert_eq!(m, decrypted);
}
}
#[test]
fn homomorphism() {
const N: usize = 100;
let mut rng = StdRng::from_entropy();
let dk = DecryptionKey::new(&mut rng);
let ek = dk.encryption_key();
for _ in 0..N {
let m1 = RistrettoPoint::random(&mut rng);
let m2 = RistrettoPoint::random(&mut rng);
let sum = m1 + m2;
let ct1 = ek.encrypt(m1, &mut rng);
let ct2 = ek.encrypt(m2, &mut rng);
let ct_sum = ct1 + ct2;
let decrypted = dk.decrypt(ct_sum);
assert_eq!(sum, decrypted);
}
}
}