Skip to content

Commit f3278cd

Browse files
authored
Merge pull request #6 from robinhundt/new-kos-consistency-check
New kos consistency check This implements the new consistency check from Sec. 4 of the updated KOS paper. The implementation is based on this commit in libOTe. However, because we have a configurable batch size, the iteration through the matrices T and V is done differently. Instead of iterating the columns, we iterate the rows. This is a more cache efficient iteration.
2 parents dd5c933 + 41cc896 commit f3278cd

File tree

5 files changed

+274
-127
lines changed

5 files changed

+274
-127
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
target
2-
profile.json
2+
profile.json*
33
perf.data*
44

55
.flyio

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cryprot-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rand_core_0_6.workspace = true
3131
rayon = { workspace = true, optional = true }
3232
serde = { workspace = true, features = ["derive"] }
3333
subtle.workspace = true
34+
thiserror.workspace = true
3435
tokio = { workspace = true, features = ["sync"], optional = true }
3536
tracing = { workspace = true }
3637
tracing-subscriber = { workspace = true, optional = true }

cryprot-core/src/block.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bytemuck::{Pod, Zeroable};
1111
use rand::{Rng, distr::StandardUniform, prelude::Distribution};
1212
use serde::{Deserialize, Serialize};
1313
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
14+
use thiserror::Error;
1415
use wide::u8x16;
1516

1617
use crate::random_oracle::{self, RandomOracle};
@@ -336,6 +337,20 @@ impl From<&u128> for Block {
336337
}
337338
}
338339

340+
#[derive(Debug, Error)]
341+
#[error("slice must have length of 16")]
342+
pub struct WrongLength;
343+
344+
impl TryFrom<&[u8]> for Block {
345+
type Error = WrongLength;
346+
347+
#[inline]
348+
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
349+
let arr = value.try_into().map_err(|_| WrongLength)?;
350+
Ok(Self::new(arr))
351+
}
352+
}
353+
339354
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
340355
mod from_arch_impls {
341356
#[cfg(target_arch = "x86")]
@@ -472,4 +487,13 @@ mod tests {
472487
assert_eq!(false, rest);
473488
}
474489
}
490+
491+
#[test]
492+
fn test_from_choices() {
493+
let mut choices = vec![Choice::from(0); 128];
494+
choices[2] = Choice::from(1);
495+
choices[16] = Choice::from(1);
496+
let blk = Block::from_choices(&choices);
497+
assert_eq!(Block::from(1_u128 << 2 | 1_u128 << 16), blk);
498+
}
475499
}

0 commit comments

Comments
 (0)