Skip to content

Commit

Permalink
Remove unused prg and owcf modules
Browse files Browse the repository at this point in the history
  • Loading branch information
myl7 committed Apr 9, 2024
1 parent 48c8086 commit d28a4d2
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 268 deletions.
10 changes: 5 additions & 5 deletions src/dcf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ pub enum BoundState {
mod tests {
use rand::prelude::*;

use super::prg::Aes256HirosePrg;
use super::*;
use crate::group::byte::ByteGroup;
use crate::prg::Aes256HirosePrgBytes;

const KEYS: &[&[u8; 32]] = &[
b"j9\x1b_\xb3X\xf33\xacW\x15\x1b\x0812K\xb3I\xb9\x90r\x1cN\xb5\xee9W\xd3\xbb@\xc6d",
Expand All @@ -319,7 +319,7 @@ mod tests {

#[test]
fn test_dcf_gen_then_eval() {
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 2>::new(std::array::from_fn(|i| KEYS[i]));
let dcf = DcfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {

#[test]
fn test_dcf_gen_gt_beta_then_eval() {
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 2>::new(std::array::from_fn(|i| KEYS[i]));
let dcf = DcfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {

#[test]
fn test_dcf_gen_then_eval_not_zeros() {
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 2>::new(std::array::from_fn(|i| KEYS[i]));
let dcf = DcfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
Expand All @@ -407,7 +407,7 @@ mod tests {
#[test]
fn test_dcf_full_domain_eval() {
let x: [u8; 2] = ALPHAS[2][..2].try_into().unwrap();
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 2>::new(std::array::from_fn(|i| KEYS[i]));
let dcf = DcfImpl::<2, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
Expand Down
35 changes: 0 additions & 35 deletions src/dcf/prg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bitvec::prelude::*;

use super::Prg;
use crate::utils::{xor, xor_inplace};
use crate::PrgBytes;

/// Hirose double-block-length one-way compression function with AES256 and precreated keys.
/// Integrated impl of [`Prg`] with a good performance.
Expand Down Expand Up @@ -126,31 +125,9 @@ impl<const LAMBDA: usize, const N: usize> Prg<LAMBDA> for Aes128MatyasMeyerOseas
}
}

impl<const LAMBDA: usize, P> Prg<LAMBDA> for P
where
P: PrgBytes,
{
fn gen(&self, seed: &[u8; LAMBDA]) -> [([u8; LAMBDA], [u8; LAMBDA], bool); 2] {
let mut buf = vec![0; 4 * LAMBDA];
PrgBytes::gen(self, &mut buf, seed);
let mut iter = buf.into_iter().array_chunks::<LAMBDA>();
let mut sl = iter.next().unwrap();
let vl = iter.next().unwrap();
let mut sr = iter.next().unwrap();
let vr = iter.next().unwrap();
assert_eq!(iter.next(), None);
let tl = sl.view_bits::<Lsb0>()[0];
sl[LAMBDA - 1].view_bits_mut::<Lsb0>().set(0, false);
let tr = sr.view_bits::<Lsb0>()[0];
sr[LAMBDA - 1].view_bits_mut::<Lsb0>().set(0, false);
[(sl, vl, tl), (sr, vr, tr)]
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::prg::Aes256HirosePrgBytes;

const KEYS: [&[u8; 32]; 2] = [
b"j9\x1b_\xb3X\xf33\xacW\x15\x1b\x0812K\xb3I\xb9\x90r\x1cN\xb5\xee9W\xd3\xbb@\xc6d",
Expand All @@ -169,16 +146,4 @@ mod tests {
assert_ne!(xor(&[&out[i].1, SEED]), [0; 16]);
});
}

#[test]
fn test_prg_bytes_gen_not_zeros() {
let prg = Aes256HirosePrgBytes::new(&KEYS.iter().map(|&k| k).collect::<Vec<_>>());
let out = Prg::gen(&prg, SEED);
(0..2).for_each(|i| {
assert_ne!(out[i].0, [0; 16]);
assert_ne!(out[i].1, [0; 16]);
assert_ne!(xor(&[&out[i].0, SEED]), [0; 16]);
assert_ne!(xor(&[&out[i].1, SEED]), [0; 16]);
});
}
}
8 changes: 4 additions & 4 deletions src/dpf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ where
mod tests {
use rand::prelude::*;

use super::prg::Aes256HirosePrg;
use super::*;
use crate::group::byte::ByteGroup;
use crate::prg::Aes256HirosePrgBytes;

const KEYS: &[&[u8; 32]] =
&[b"j9\x1b_\xb3X\xf33\xacW\x15\x1b\x0812K\xb3I\xb9\x90r\x1cN\xb5\xee9W\xd3\xbb@\xc6d"];
Expand All @@ -250,7 +250,7 @@ mod tests {

#[test]
fn test_dpf_gen_then_eval() {
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 1>::new(std::array::from_fn(|i| KEYS[i]));
let dpf = DpfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = PointFn {
Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {

#[test]
fn test_dpf_gen_then_eval_not_zeros() {
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 1>::new(std::array::from_fn(|i| KEYS[i]));
let dpf = DpfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = PointFn {
Expand All @@ -304,7 +304,7 @@ mod tests {
#[test]
fn test_dpf_full_domain_eval() {
let x: [u8; 2] = ALPHAS[2][..2].try_into().unwrap();
let prg = Aes256HirosePrgBytes::new(KEYS);
let prg = Aes256HirosePrg::<16, 1>::new(std::array::from_fn(|i| KEYS[i]));
let dpf = DpfImpl::<2, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = PointFn {
Expand Down
31 changes: 0 additions & 31 deletions src/dpf/prg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bitvec::prelude::*;

use super::Prg;
use crate::utils::{xor, xor_inplace};
use crate::PrgBytes;

/// Hirose double-block-length one-way compression function with AES256 and precreated keys.
/// Integrated impl of [`Prg`] with a good performance.
Expand Down Expand Up @@ -107,29 +106,9 @@ impl<const LAMBDA: usize, const N: usize> Prg<LAMBDA> for Aes128MatyasMeyerOseas
}
}

impl<const LAMBDA: usize, P> Prg<LAMBDA> for P
where
P: PrgBytes,
{
fn gen(&self, seed: &[u8; LAMBDA]) -> [([u8; LAMBDA], bool); 2] {
let mut buf = vec![0; 2 * LAMBDA];
PrgBytes::gen(self, &mut buf, seed);
let mut iter = buf.into_iter().array_chunks::<LAMBDA>();
let mut sl = iter.next().unwrap();
let mut sr = iter.next().unwrap();
assert_eq!(iter.next(), None);
let tl = sl.view_bits::<Lsb0>()[0];
sl[LAMBDA - 1].view_bits_mut::<Lsb0>().set(0, false);
let tr = sr.view_bits::<Lsb0>()[0];
sr[LAMBDA - 1].view_bits_mut::<Lsb0>().set(0, false);
[(sl, tl), (sr, tr)]
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::prg::Aes256HirosePrgBytes;

const KEYS: [&[u8; 32]; 1] =
[b"j9\x1b_\xb3X\xf33\xacW\x15\x1b\x0812K\xb3I\xb9\x90r\x1cN\xb5\xee9W\xd3\xbb@\xc6d"];
Expand All @@ -144,14 +123,4 @@ mod tests {
assert_ne!(xor(&[&out[i].0, SEED]), [0; 16]);
});
}

#[test]
fn test_prg_bytes_gen_not_zeros() {
let prg = Aes256HirosePrgBytes::new(&KEYS.iter().map(|&k| k).collect::<Vec<_>>());
let out = Prg::gen(&prg, SEED);
(0..2).for_each(|i| {
assert_ne!(out[i].0, [0; 16]);
assert_ne!(xor(&[&out[i].0, SEED]), [0; 16]);
});
}
}
16 changes: 0 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use group::Group;
pub mod dcf;
pub mod dpf;
pub mod group;
pub mod owcf;
#[cfg(feature = "prg")]
pub mod prg;
pub mod utils;

/// Point function.
Expand Down Expand Up @@ -45,19 +42,6 @@ macro_rules! decl_prg_trait {
}
pub(crate) use decl_prg_trait;

/// Pseudorandom generator to generate bytes
///
/// The output and input sizes are related with the sizes set by users.
/// They should be checked by the implementation.
///
/// Requires `Sync` for multi-threading, which should be still easy for even single-threaded
///
/// NOTICE: The trait with the impls still has performance issues.
/// Use [`crate::dpf::prg`] or [`crate::dcf::prg`] instead.
pub trait PrgBytes: Sync {
fn gen(&self, buf: &mut [u8], src: &[u8]);
}

/// `Cw`. Correclation word.
#[derive(Clone)]
pub struct Cw<const LAMBDA: usize, G>
Expand Down
44 changes: 0 additions & 44 deletions src/owcf.rs

This file was deleted.

Loading

0 comments on commit d28a4d2

Please sign in to comment.