Skip to content

Commit

Permalink
add default ferret configs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangxiecrypto committed Aug 21, 2024
1 parent f67b6c0 commit 84399bd
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 26 deletions.
19 changes: 0 additions & 19 deletions crates/mpz-ot-core/src/ferret/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//! An implementation of the [`Ferret`](https://eprint.iacr.org/2020/924.pdf) protocol.
use mpz_core::lpn::LpnParameters;

pub mod cuckoo;
pub mod error;
pub mod mpcot;
Expand All @@ -19,22 +16,6 @@ pub const CUCKOO_HASH_NUM: usize = 3;
/// Trial numbers in Cuckoo hash insertion.
pub const CUCKOO_TRIAL_NUM: usize = 100;

/// LPN parameters with regular noise.
/// Derived from https://github.com/emp-toolkit/emp-ot/blob/master/emp-ot/ferret/constants.h
pub const LPN_PARAMETERS_REGULAR: LpnParameters = LpnParameters {
n: 10_180_608,
k: 124_000,
t: 4_971,
};

/// LPN parameters with uniform noise.
/// Derived from Table 2.
pub const LPN_PARAMETERS_UNIFORM: LpnParameters = LpnParameters {
n: 10_616_092,
k: 588_160,
t: 1_324,
};

/// The type of Lpn parameters.
#[derive(Debug, Clone, Copy, Default)]
pub enum LpnType {
Expand Down
132 changes: 132 additions & 0 deletions crates/mpz-ot/src/ferret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,138 @@ impl FerretConfig {
}
}

/// Ferret config with regular LPN parameters.
/// Parameters for setup with small extension output.
pub const FERRET_REGULAR_SETUP_SMALL: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 102_400,
k: 6_750,
t: 1_600,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with regular LPN parameters.
/// Parameters for extension with small extension output.
pub const FERRET_REGULAR_EXTENSION_SMALL: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 1_740_800,
k: 66_400,
t: 1700,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with regular LPN parameters.
/// Parameters for setup with medium extension output.
pub const FERRET_REGULAR_SETUP_MEDIUM: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 283_648,
k: 18_584,
t: 1_108,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with regular LPN parameters.
/// Parameters for extension with medium extension output.
pub const FERRET_REGULAR_EXTENSION_MEDIUM: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 5_324_800,
k: 240_000,
t: 1_300,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with regular LPN parameters.
/// Parameters for setup with large extension output.
pub const FERRET_REGULAR_SETUP_LARGE: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 518_656,
k: 34_643,
t: 1_013,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with regular LPN parameters.
/// Parameters for extension with large extension output.
pub const FERRET_REGULAR_EXTENSION_LARGE: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 10_485_760,
k: 458_000,
t: 1280,
},
lpn_type: LpnType::Regular,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for setup with small extension output.
pub const FERRET_UNIFORM_SETUP_SMALL: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 98_000,
k: 4_450,
t: 1_600,
},
lpn_type: LpnType::Uniform,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for extension with small extension output.
pub const FERRET_UNIFORM_EXTENSION_SMALL: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 1_071_888,
k: 40_800,
t: 1720,
},
lpn_type: LpnType::Uniform,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for setup with medium extension output.
pub const FERRET_UNIFORM_SETUP_MEDIUM: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 283_648,
k: 18_584,
t: 1_108,
},
lpn_type: LpnType::Uniform,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for extension with medium extension output.
pub const FERRET_UNIFORM_EXTENSION_MEDIUM: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 5_324_800,
k: 240_000,
t: 1_300,
},
lpn_type: LpnType::Uniform,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for setup with large extension output.
pub const FERRET_UNIFORM_SETUP_LARGE: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 545_656,
k: 34_643,
t: 1_050,
},
lpn_type: LpnType::Uniform,
};

/// Ferret config with uniform LPN parameters.
/// Parameters for extension with large extension output.
pub const FERRET_UNIFORM_EXTENSION_LARGE: FerretConfig = FerretConfig {
lpn_parameters: LpnParameters {
n: 10_488_928,
k: 458_000,
t: 1_280,
},
lpn_type: LpnType::Uniform,
};

#[cfg(test)]
mod tests {
use super::*;
Expand Down
9 changes: 2 additions & 7 deletions crates/mpz-ot/src/ferret/spcot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ pub(crate) async fn send<Ctx: Context, RandomCOT: RandomCOTSender<Ctx, Block>>(

let checkfr = ctx.io_mut().expect_next().await?;

let (output, check_msg) = CpuBackend::blocking(move || {
sender
.check(&y_star, checkfr)
})
.await?;
let (output, check_msg) = CpuBackend::blocking(move || sender.check(&y_star, checkfr)).await?;

ctx.io_mut().send(check_msg).await?;

Expand Down Expand Up @@ -128,8 +124,7 @@ pub(crate) async fn receive<Ctx: Context, RandomCOT: RandomCOTReceiver<Ctx, bool
ctx.io_mut().send(checkfr).await?;
let check = ctx.io_mut().expect_next().await?;

let output =
CpuBackend::blocking(move || receiver.check(&z_star, check)).await?;
let output = CpuBackend::blocking(move || receiver.check(&z_star, check)).await?;

Ok(output)
}
Expand Down

0 comments on commit 84399bd

Please sign in to comment.