From 874b506728745cc52289155f366f97a018ba3628 Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Tue, 29 Oct 2024 16:05:45 +0200 Subject: [PATCH] add rayon lib, use par_iter for `encrypt_vote` fn (#71) --- rust/catalyst-voting/Cargo.toml | 1 + rust/catalyst-voting/src/vote_protocol/voter/mod.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/catalyst-voting/Cargo.toml b/rust/catalyst-voting/Cargo.toml index ec47dcdd3..2c23a9165 100644 --- a/rust/catalyst-voting/Cargo.toml +++ b/rust/catalyst-voting/Cargo.toml @@ -23,6 +23,7 @@ rand_chacha = "0.3.1" curve25519-dalek = { version = "4.1.3", features = ["digest", "rand_core"] } ed25519-dalek = { version = "2.1.1", features = ["rand_core"] } blake2b_simd = "1.0.2" +rayon = "1.10.0" [dev-dependencies] criterion = "0.5.1" diff --git a/rust/catalyst-voting/src/vote_protocol/voter/mod.rs b/rust/catalyst-voting/src/vote_protocol/voter/mod.rs index 5635db536..7937faa49 100644 --- a/rust/catalyst-voting/src/vote_protocol/voter/mod.rs +++ b/rust/catalyst-voting/src/vote_protocol/voter/mod.rs @@ -5,6 +5,7 @@ pub mod proof; use anyhow::{anyhow, bail, ensure}; use rand_core::CryptoRngCore; +use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use super::committee::{ElectionPublicKey, ElectionSecretKey}; use crate::crypto::{ @@ -97,8 +98,8 @@ pub fn encrypt_vote( let unit_vector = vote.to_unit_vector(); let ciphers = unit_vector - .iter() - .zip(randomness.0.iter()) + .par_iter() + .zip(randomness.0.par_iter()) .map(|(m, r)| encrypt(m, &public_key.0, r)) .collect();