Skip to content

Commit

Permalink
require extend count to be a multiple of 64
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 committed Feb 12, 2024
1 parent 4ea2509 commit 9f021ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ot/mpz-ot-core/src/kos/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
pub enum SenderError {
#[error("invalid state: expected {0}")]
InvalidState(String),
#[error("invalid count, must be a multiple of 64: {0}")]
InvalidCount(usize),
#[error("count mismatch: expected {0}, got {1}")]
CountMismatch(usize, usize),
#[error("id mismatch: expected {0}, got {1}")]
Expand All @@ -22,6 +24,8 @@ pub enum SenderError {
pub enum ReceiverError {
#[error("invalid state: expected {0}")]
InvalidState(String),
#[error("invalid count, must be a multiple of 64: {0}")]
InvalidCount(usize),
#[error("count mismatch: expected {0}, got {1}")]
CountMismatch(usize, usize),
#[error("id mismatch: expected {0}, got {1}")]
Expand Down
9 changes: 6 additions & 3 deletions ot/mpz-ot-core/src/kos/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ impl Receiver<state::Extension> {

/// Perform the IKNP OT extension.
///
/// The provided count _must_ be a multiple of 64, otherwise an error will be returned.
///
/// # Sacrificial OTs
///
/// Performing the consistency check sacrifices 256 OTs, so be sure to
Expand All @@ -132,16 +134,17 @@ impl Receiver<state::Extension> {
///
/// # Arguments
///
/// * `count` - The number of OTs to extend.
/// * `count` - The number of OTs to extend (must be a multiple of 64).
pub fn extend(&mut self, count: usize) -> Result<Extend, ReceiverError> {
if self.state.extended {
return Err(ReceiverError::InvalidState(
"extending more than once is currently disabled".to_string(),
));
}

// Round up the OTs to extend to the nearest multiple of 64 (matrix transpose optimization).
let count = (count + 63) & !63;
if count % 64 != 0 {
return Err(ReceiverError::InvalidCount(count));
}

const NROWS: usize = CSP;
let row_width = count / 8;
Expand Down
11 changes: 7 additions & 4 deletions ot/mpz-ot-core/src/kos/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ impl Sender<state::Extension> {

/// Perform the IKNP OT extension.
///
/// The provided count _must_ be a multiple of 64, otherwise an error will be returned.
///
/// # Sacrificial OTs
///
/// Performing the consistency check sacrifices 256 OTs, so be sure to extend enough to
Expand All @@ -112,17 +114,18 @@ impl Sender<state::Extension> {
///
/// # Arguments
///
/// * `count` - The number of additional OTs to extend
/// * `extend` - The receiver's setup message
/// * `count` - The number of additional OTs to extend (must be a multiple of 64).
/// * `extend` - The receiver's setup message.
pub fn extend(&mut self, count: usize, extend: Extend) -> Result<(), SenderError> {
if self.state.extended {
return Err(SenderError::InvalidState(
"extending more than once is currently disabled".to_string(),
));
}

// Round up the OTs to extend to the nearest multiple of 64 (matrix transpose optimization).
let count = (count + 63) & !63;
if count % 64 != 0 {
return Err(SenderError::InvalidCount(count));
}

const NROWS: usize = CSP;
let row_width = count / 8;
Expand Down

0 comments on commit 9f021ac

Please sign in to comment.