From 8b5a62ca2766d579800e34ca61487c8fb3f2e018 Mon Sep 17 00:00:00 2001 From: Christian Berkhoff Date: Wed, 3 Apr 2024 16:09:09 -0700 Subject: [PATCH] Removed unused structures to help with coverage --- ipa-core/src/bin/ipa_bench/models.rs | 104 +----------------- ipa-core/src/helpers/transport/query/mod.rs | 17 --- .../helpers/transport/query/oprf_shuffle.rs | 4 - 3 files changed, 1 insertion(+), 124 deletions(-) delete mode 100644 ipa-core/src/helpers/transport/query/oprf_shuffle.rs diff --git a/ipa-core/src/bin/ipa_bench/models.rs b/ipa-core/src/bin/ipa_bench/models.rs index 5391ac959..6f2fb2a01 100644 --- a/ipa-core/src/bin/ipa_bench/models.rs +++ b/ipa-core/src/bin/ipa_bench/models.rs @@ -1,15 +1,12 @@ use std::{ fmt::{Debug, Formatter}, - io::{Error as IoError, ErrorKind as IoErrorKind}, ops::Range, }; -use rand::{CryptoRng, Rng, RngCore}; use serde::{Deserialize, Serialize}; // Type aliases to indicate whether the parameter should be encrypted, secret shared, etc. // Underlying types are temporalily assigned for PoC. -pub type CipherText = Vec; type PlainText = String; pub type MatchKey = u64; pub type Number = u32; @@ -20,104 +17,6 @@ pub type Epoch = u8; /// An offset in seconds into a given epoch. Using an 32-bit value > 20-bit > 604,800 seconds. pub type Offset = u32; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SecretShare { - ss: [CipherText; 3], -} - -impl SecretShare { - fn combine(&self) -> Vec { - let mut result = Vec::new(); - - assert!(self.ss[0].len() == self.ss[1].len()); - assert!(self.ss[0].len() == self.ss[2].len()); - - for i in 0..self.ss[0].len() { - result.push(self.ss[0][i] ^ self.ss[1][i] ^ self.ss[2][i]); - } - - result - } - - // TODO: Add Shamir's SS - - fn xor(data: &[u8], rng: &mut R) -> Self { - let mut ss = [Vec::new(), Vec::new(), Vec::new()]; - - for x in data { - let ss1 = rng.gen::(); - let ss2 = rng.gen::(); - let ss3 = ss1 ^ ss2 ^ x; - - ss[0].push(ss1); - ss[1].push(ss2); - ss[2].push(ss3); - } - - SecretShare { ss } - } -} - -pub trait SecretSharable { - /// Splits the number into secret shares - fn xor_split(&self, rng: &mut R) -> SecretShare; - - /// Combines the given secret shares back to [Self] - /// # Errors - /// if the combined data overflows [Self] - fn combine(data: &SecretShare) -> Result - where - Self: Sized; -} - -impl SecretSharable for u32 { - fn xor_split(&self, rng: &mut R) -> SecretShare { - SecretShare::xor(&self.to_be_bytes(), rng) - } - - fn combine(data: &SecretShare) -> Result { - let ss = data.combine(); - - let mut high = ss[0..ss.len() - 4].to_vec(); - high.retain(|x| *x != 0); - - if ss.len() > 4 && !high.is_empty() { - return Err(IoError::from(IoErrorKind::InvalidData)); - } - - let mut bytes = [0u8; 4]; - for (i, v) in ss[ss.len() - 4..].iter().enumerate() { - bytes[i] = *v; - } - - Ok(u32::from_be_bytes(bytes)) - } -} - -impl SecretSharable for u64 { - fn xor_split(&self, rng: &mut R) -> SecretShare { - SecretShare::xor(&self.to_be_bytes(), rng) - } - - fn combine(data: &SecretShare) -> Result { - let ss = data.combine(); - - let mut high = ss[0..ss.len() - 8].to_vec(); - high.retain(|x| *x != 0); - - if ss.len() > 8 && !high.is_empty() { - return Err(IoError::from(IoErrorKind::InvalidData)); - } - - let mut bytes = [0u8; 8]; - for (i, v) in ss[ss.len() - 8..].iter().enumerate() { - bytes[i] = *v; - } - - Ok(u64::from_be_bytes(bytes)) - } -} - #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] /// A timestamp of a source/trigger report represented by epoch and offset. /// @@ -313,8 +212,7 @@ impl Debug for TriggerFanoutQuery { #[cfg(all(test, unit_test))] mod tests { - use super::EventTimestamp; - use crate::models::Epoch; + use super::{EventTimestamp, Epoch}; #[test] fn event_timestamp_new() { diff --git a/ipa-core/src/helpers/transport/query/mod.rs b/ipa-core/src/helpers/transport/query/mod.rs index d123f7be4..4d0df9df5 100644 --- a/ipa-core/src/helpers/transport/query/mod.rs +++ b/ipa-core/src/helpers/transport/query/mod.rs @@ -1,5 +1,3 @@ -pub mod oprf_shuffle; - use std::{ fmt::{Debug, Display, Formatter}, num::NonZeroU32, @@ -312,18 +310,3 @@ impl std::fmt::Display for ContributionBits { write!(f, "{}", self.0) } } - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct SparseAggregateQueryConfig { - pub contribution_bits: ContributionBits, - pub num_contributions: u32, -} - -impl Default for SparseAggregateQueryConfig { - fn default() -> Self { - Self { - contribution_bits: ContributionBits::default(), - num_contributions: 8, - } - } -} diff --git a/ipa-core/src/helpers/transport/query/oprf_shuffle.rs b/ipa-core/src/helpers/transport/query/oprf_shuffle.rs deleted file mode 100644 index ac9ea5673..000000000 --- a/ipa-core/src/helpers/transport/query/oprf_shuffle.rs +++ /dev/null @@ -1,4 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] -pub struct QueryConfig {}