Skip to content

Commit

Permalink
Merge pull request #1195 from filecoin-project/feistel-test
Browse files Browse the repository at this point in the history
test: test if permutation is valid #1193
  • Loading branch information
porcuquine authored Jul 2, 2020
2 parents 0cfe65f + a54138e commit 00a8d95
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions storage-proofs/core/src/crypto/feistel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fn feistel(right: Index, key: Index, right_mask: Index) -> Index {
#[cfg(test)]
mod tests {
use super::*;
use rayon::prelude::*;

// Some sample n-values which are not powers of four and also don't coincidentally happen to
// encode/decode correctly.
Expand Down Expand Up @@ -225,4 +226,21 @@ mod tests {
}
}
}

#[test]
#[ignore]
fn test_feistel_valid_permutation() {
let n = (1u64 << 30) as Index;
let mut flags = vec![false; n as usize];
let precomputed = precompute(n);
let perm: Vec<Index> = (0..n)
.into_par_iter()
.map(|i| permute(n, i, &[1, 2, 3, 4], precomputed))
.collect();
for i in perm {
assert!(i < n, "output number is too big");
flags[i as usize] = true;
}
assert!(flags.iter().all(|f| *f), "output isn't a permutation");
}
}

0 comments on commit 00a8d95

Please # to comment.