diff --git a/pop-mpc/src/ot/extension.rs b/pop-mpc/src/ot/extension.rs index 001ca0146..19cd7a9e2 100644 --- a/pop-mpc/src/ot/extension.rs +++ b/pop-mpc/src/ot/extension.rs @@ -250,7 +250,7 @@ mod tests { rng.fill_bytes(&mut choice); let choice = u8vec_to_boolvec(&choice); let inputs: Vec<[Block; 2]> = (0..16) - .map(|i| [Block::from(2 * i), Block::from(2 * i + 1)]) + .map(|i| [Block::random(&mut rng), Block::random(&mut rng)]) .collect(); let receiver_setup = receiver.extension_setup(&choice); diff --git a/pop-mpc/src/utils.rs b/pop-mpc/src/utils.rs index 6e6e503f2..344edf3fe 100644 --- a/pop-mpc/src/utils.rs +++ b/pop-mpc/src/utils.rs @@ -20,27 +20,48 @@ pub fn u8vec_to_boolvec(v: &[u8]) -> Vec { } pub fn transpose(m: &Vec>) -> Vec> { - let col_count = m[0].len() * 8; - let row_count = m.len(); + let bits: Vec> = m.iter().map(|row| u8vec_to_boolvec(row)).collect(); + let col_count = bits[0].len(); + let row_count = bits.len(); + let mut bits_: Vec> = vec![vec![false; row_count]; col_count]; let mut m_: Vec> = Vec::with_capacity(col_count); - for j in 0..col_count { - let byte_n = j >> 3; - let bit_idx = j % 8; + for j in 0..row_count { + for i in 0..col_count { + bits_[i][j] = bits[j][i]; + } + } - let mut row_bits: Vec = (0..row_count) - .map(|i| ((m[i][byte_n] >> (7 - bit_idx)) & 1) == 1) - .collect(); - row_bits.reverse(); - let mut row = boolvec_to_u8vec(&row_bits); - row.reverse(); - m_.push(row); + for row in bits_.iter() { + m_.push(boolvec_to_u8vec(row)); } m_ } +// pub fn transpose(m: &Vec>) -> Vec> { +// let col_count = m[0].len() * 8; +// let row_count = m.len(); + +// let mut m_: Vec> = Vec::with_capacity(col_count); + +// for j in 0..col_count { +// let byte_n = j >> 3; +// let bit_idx = j % 8; + +// let mut row_bits: Vec = (0..row_count) +// .map(|i| ((m[i][byte_n] >> (7 - bit_idx)) & 1) == 1) +// .collect(); +// row_bits.reverse(); +// let mut row = boolvec_to_u8vec(&row_bits); +// row.reverse(); +// m_.push(row); +// } + +// m_ +// } + #[cfg(test)] mod tests { use super::*;