Formatting / Cleanup
This commit is contained in:
parent
85dc8ed9ad
commit
6ddc684755
31
src/lib.rs
31
src/lib.rs
|
@ -22,14 +22,14 @@ use brute_force::adaptors;
|
|||
#[cfg(feature = "entangled")]
|
||||
use brute_force::brute_force;
|
||||
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
use std::sync::mpsc::channel;
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
use rayon::iter::IndexedParallelIterator;
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
use rayon::iter::ParallelIterator;
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
/// A tag is a probabilistic cryptographic structure. When constructed for a given `TaggingKey`
|
||||
/// it will pass the `DetectionKey::test_tag` 100% of the time. For other tagging keys
|
||||
|
@ -202,9 +202,7 @@ impl<const GAMMA: u8> RootSecret<{ GAMMA }> {
|
|||
let sk_i = Scalar::random(&mut rng);
|
||||
secret.push(sk_i);
|
||||
}
|
||||
RootSecret::<GAMMA> {
|
||||
secret: secret
|
||||
}
|
||||
RootSecret::<GAMMA> { secret: secret }
|
||||
}
|
||||
|
||||
/// extract a detection key for a given false positive (p = 2^-n)
|
||||
|
@ -236,9 +234,7 @@ impl<const GAMMA: u8> RootSecret<{ GAMMA }> {
|
|||
let pk_i = g.mul(sk_i);
|
||||
tagging_key.push(pk_i);
|
||||
}
|
||||
TaggingKey::<GAMMA>{
|
||||
0: tagging_key
|
||||
}
|
||||
TaggingKey::<GAMMA> { 0: tagging_key }
|
||||
}
|
||||
|
||||
/// a hash function that takes 3 ristretto points as a parameter and outputs 0 or 1.
|
||||
|
@ -367,7 +363,6 @@ impl<const GAMMA: u8> DetectionKey<{ GAMMA }> {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// A bulk testing function that takes in an vector of detection keys and returns a vector
|
||||
/// of indexes where the tag matched.
|
||||
#[cfg(feature = "bulk_verify")]
|
||||
|
@ -395,7 +390,7 @@ impl<const GAMMA: u8> DetectionKey<{ GAMMA }> {
|
|||
let (tx, rx) = channel();
|
||||
|
||||
// for each secret part...
|
||||
let mut results : Vec<(usize)> = vec![];
|
||||
let mut results: Vec<usize> = vec![];
|
||||
detection_keys.par_iter().enumerate().for_each_with(tx.clone(), |tx, (index, detection_key)| {
|
||||
let mut result = true;
|
||||
for (i, x_i) in detection_key.0.iter().enumerate() {
|
||||
|
@ -421,7 +416,11 @@ impl<const GAMMA: u8> DetectionKey<{ GAMMA }> {
|
|||
result = result & (b_i == 1);
|
||||
}
|
||||
if result {
|
||||
tx.send(index);
|
||||
match tx.send(index) {
|
||||
_ => {
|
||||
// TODO...surface this error...
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -429,9 +428,7 @@ impl<const GAMMA: u8> DetectionKey<{ GAMMA }> {
|
|||
loop {
|
||||
let result = rx.recv();
|
||||
match result {
|
||||
Ok(index) => {
|
||||
results.push(index)
|
||||
}
|
||||
Ok(index) => results.push(index),
|
||||
_ => {
|
||||
break;
|
||||
}
|
||||
|
@ -574,7 +571,7 @@ impl<const GAMMA: u8> TaggingKey<{ GAMMA }> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{RootSecret, Tag, DetectionKey};
|
||||
use crate::{DetectionKey, RootSecret, Tag};
|
||||
use bit_vec::BitVec;
|
||||
use curve25519_dalek::ristretto::RistrettoPoint;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
|
@ -665,8 +662,8 @@ mod tests {
|
|||
let detection_keys = secrets.iter().map(|x| x.extract_detection_key(16)).collect();
|
||||
|
||||
let results = DetectionKey::test_tag_bulk(&detection_keys, &entangled_tag);
|
||||
for result in results.iter() {
|
||||
assert_eq!(*result, true);
|
||||
for (index, rindex) in results.iter().enumerate() {
|
||||
assert_eq!(index, *rindex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue