From 3645668bffe02b6b1f756354b5e40e197a530bc0 Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Mon, 1 Oct 2018 12:25:31 +0200 Subject: [PATCH] Add an API that allows specifying the RNG to be used for encryption. --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e93d88b..1057656 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,9 +101,17 @@ impl PublicKey { self.verify_g2(sig, hash_g2(msg)) } - /// Encrypts the message. + /// Encrypts the message using the OS random number generator. + /// + /// Uses the `OsRng` by default. To pass in a custom random number generator, use + /// `encrypt_with_rng()`. pub fn encrypt>(&self, msg: M) -> Ciphertext { - let r: Fr = OsRng::new().expect(ERR_OS_RNG).gen(); + self.encrypt_with_rng(&mut OsRng::new().expect(ERR_OS_RNG), msg) + } + + /// Encrypts the message. + pub fn encrypt_with_rng>(&self, rng: &mut R, msg: M) -> Ciphertext { + let r: Fr = rng.gen(); let u = G1Affine::one().mul(r); let v: Vec = { let g = self.0.into_affine().mul(r);