mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-10 07:07:57 -05:00
switched RNG to ChaCha20
This commit is contained in:
83
Cargo.lock
generated
83
Cargo.lock
generated
@@ -64,6 +64,12 @@ version = "3.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.2.7"
|
||||
@@ -220,6 +226,28 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"digest",
|
||||
"rand_core",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
@@ -236,6 +264,17 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.4"
|
||||
@@ -245,7 +284,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.10.2+wasi-snapshot-preview1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
@@ -395,8 +434,11 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"criterion",
|
||||
"getrandom",
|
||||
"curve25519-dalek",
|
||||
"getrandom 0.2.4",
|
||||
"rand",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rayon",
|
||||
"regex",
|
||||
"rstest",
|
||||
@@ -434,10 +476,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.4"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom 0.1.16",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
@@ -446,9 +489,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
@@ -456,18 +499,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.3"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.1.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.1"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
@@ -613,6 +656,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
@@ -678,6 +727,12 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
@@ -814,3 +869,9 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c88870063c39ee00ec285a2f8d6a966e5b6fb2becc4e8dac77ed0d370ed6006"
|
||||
|
||||
@@ -7,10 +7,12 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
aes = { version="0.7.5", features=[]}
|
||||
#ring = "0.16.20"
|
||||
rand = "0.8.4"
|
||||
rand = "0.7"
|
||||
rand_core = "0.5"
|
||||
rand_chacha = "0.2"
|
||||
regex = "1.5.4"
|
||||
rayon = "1.5"
|
||||
curve25519-dalek = { version = "3" }
|
||||
|
||||
[dev-dependencies]
|
||||
rstest = "0.12.0"
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use pop_mpc::block::Block;
|
||||
use pop_mpc::circuit::Circuit;
|
||||
use pop_mpc::garble::{
|
||||
evaluator::HalfGateEvaluator, generator::half_gate::*, generator::GarbledCircuitGenerator,
|
||||
hash::aes::Aes,
|
||||
};
|
||||
use pop_mpc::rng::{RandomBlock, Rng};
|
||||
use rand::SeedableRng;
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("half_gate_garble_and", move |bench| {
|
||||
let mut prg = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let gen = HalfGateGenerator;
|
||||
|
||||
let mut delta = prg.random_block();
|
||||
let mut delta = Block::random(&mut rng);
|
||||
delta.set_lsb();
|
||||
let x_0 = prg.random_block();
|
||||
let x_0 = Block::random(&mut rng);
|
||||
let x = [x_0, x_0 ^ delta];
|
||||
let y_0 = prg.random_block();
|
||||
let y_0 = Block::random(&mut rng);
|
||||
let y = [y_0, y_0 ^ delta];
|
||||
let gid: usize = 1;
|
||||
|
||||
@@ -27,16 +29,16 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
});
|
||||
|
||||
c.bench_function("half_gate_eval_and", move |bench| {
|
||||
let mut prg = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let gen = HalfGateGenerator;
|
||||
let ev = HalfGateEvaluator;
|
||||
|
||||
let mut delta = prg.random_block();
|
||||
let mut delta = Block::random(&mut rng);
|
||||
delta.set_lsb();
|
||||
let x_0 = prg.random_block();
|
||||
let x_0 = Block::random(&mut rng);
|
||||
let x = [x_0, x_0 ^ delta];
|
||||
let y_0 = prg.random_block();
|
||||
let y_0 = Block::random(&mut rng);
|
||||
let y = [y_0, y_0 ^ delta];
|
||||
let gid: usize = 1;
|
||||
|
||||
@@ -49,12 +51,12 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
});
|
||||
|
||||
c.bench_function("half_gate_aes", move |bench| {
|
||||
let mut prg = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let circ = Circuit::parse("circuits/aes_128_reverse.txt").unwrap();
|
||||
let half_gate = HalfGateGenerator;
|
||||
bench.iter(|| {
|
||||
let gb = half_gate.garble(&h, &mut prg, &circ).unwrap();
|
||||
let gb = half_gate.garble(&h, &mut rng, &circ).unwrap();
|
||||
black_box(gb);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use core::ops::{BitAnd, BitXor, BitXorAssign};
|
||||
use rand::{CryptoRng, Rng, SeedableRng};
|
||||
use std::convert::From;
|
||||
|
||||
#[repr(transparent)]
|
||||
@@ -10,13 +11,15 @@ pub const BLOCK_ZERO: Block = Block { 0: 0 };
|
||||
pub const BLOCK_ONES: Block = Block { 0: u128::MAX };
|
||||
pub const SELECT_MASK: [Block; 2] = [BLOCK_ZERO, BLOCK_ONES];
|
||||
|
||||
//pub const SELECT_MASK: [Block; 2] = [Block(0), Block(u128::MAX)];
|
||||
|
||||
impl Block {
|
||||
pub fn new(b: u128) -> Self {
|
||||
Self(b)
|
||||
}
|
||||
|
||||
pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self {
|
||||
Self::new(rng.gen())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn zero() -> Self {
|
||||
Self(0)
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::errors::EvaluatorError;
|
||||
use crate::garble::circuit::GarbledCircuit;
|
||||
use crate::garble::hash::WireLabelHasher;
|
||||
use crate::gate::Gate;
|
||||
use crate::rng::Rng;
|
||||
|
||||
pub struct HalfGateEvaluator;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::errors::GeneratorError;
|
||||
use crate::garble::circuit::GarbledCircuit;
|
||||
use crate::garble::hash::WireLabelHasher;
|
||||
use crate::gate::Gate;
|
||||
use crate::rng::{RandomBlock, Rng};
|
||||
use rand::{CryptoRng, Rng, SeedableRng};
|
||||
|
||||
pub struct HalfGateGenerator;
|
||||
|
||||
@@ -53,23 +53,23 @@ impl HalfGateGenerator {
|
||||
}
|
||||
|
||||
impl GarbledCircuitGenerator for HalfGateGenerator {
|
||||
fn garble<R: RandomBlock, H: WireLabelHasher>(
|
||||
fn garble<R: Rng + CryptoRng, H: WireLabelHasher>(
|
||||
&self,
|
||||
h: &H,
|
||||
rng: &mut R,
|
||||
circ: &Circuit,
|
||||
) -> Result<GarbledCircuit, GeneratorError> {
|
||||
let mut delta: Block = rng.random_block();
|
||||
let mut delta: Block = Block::random(rng);
|
||||
delta.set_lsb();
|
||||
|
||||
let public_labels = [rng.random_block(), rng.random_block() ^ delta];
|
||||
let public_labels = [Block::random(rng), Block::random(rng) ^ delta];
|
||||
|
||||
let mut input_labels: Vec<[Block; 2]> = Vec::with_capacity(circ.ninput_wires);
|
||||
let mut table: Vec<[Block; 2]> = Vec::with_capacity(circ.nand);
|
||||
let mut cache: Vec<Option<[Block; 2]>> = vec![None; circ.nwires];
|
||||
|
||||
for i in 0..circ.ninput_wires {
|
||||
let z_0 = rng.random_block();
|
||||
let z_0 = Block::random(rng);
|
||||
let z_1 = z_0 ^ delta;
|
||||
let z = [z_0, z_1];
|
||||
input_labels.push(z);
|
||||
@@ -125,11 +125,11 @@ impl GarbledCircuitGenerator for HalfGateGenerator {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::garble::hash::aes::Aes;
|
||||
use crate::rng::Rng;
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
|
||||
#[test]
|
||||
fn test_encode_wire_labels() {
|
||||
let mut rng = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let circ = Circuit::parse("circuits/aes_128_reverse.txt").unwrap();
|
||||
let half_gate = HalfGateGenerator;
|
||||
|
||||
@@ -6,10 +6,10 @@ use crate::circuit::Circuit;
|
||||
use crate::errors::GeneratorError;
|
||||
use crate::garble::circuit::GarbledCircuit;
|
||||
use crate::garble::hash::WireLabelHasher;
|
||||
use crate::rng::RandomBlock;
|
||||
use rand::{CryptoRng, Rng};
|
||||
|
||||
pub trait GarbledCircuitGenerator {
|
||||
fn garble<R: RandomBlock, H: WireLabelHasher>(
|
||||
fn garble<R: Rng + CryptoRng, H: WireLabelHasher>(
|
||||
&self,
|
||||
h: &H,
|
||||
rng: &mut R,
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
mod block;
|
||||
pub mod block;
|
||||
pub mod circuit;
|
||||
pub mod element;
|
||||
pub mod errors;
|
||||
pub mod garble;
|
||||
mod gate;
|
||||
pub mod ot;
|
||||
pub mod rng;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
use crate::block::Block;
|
||||
use rand::rngs::ThreadRng;
|
||||
use rand::{thread_rng, CryptoRng, Rng as RandRng};
|
||||
|
||||
pub struct Rng {
|
||||
rng: ThreadRng,
|
||||
}
|
||||
|
||||
pub trait RandomBlock {
|
||||
fn random_block(&mut self) -> Block;
|
||||
}
|
||||
|
||||
impl Rng {
|
||||
pub fn new() -> Self {
|
||||
Self { rng: thread_rng() }
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomBlock for Rng {
|
||||
fn random_block(&mut self) -> Block {
|
||||
Block::new(self.rng.gen())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
use pop_mpc::{
|
||||
block::Block,
|
||||
circuit::Circuit,
|
||||
garble::{evaluator::*, generator::*, hash::aes::Aes},
|
||||
rng::{RandomBlock, Rng},
|
||||
};
|
||||
use rand::SeedableRng;
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
|
||||
#[test]
|
||||
fn test_and_gate() {
|
||||
let mut rng = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let gen = HalfGateGenerator;
|
||||
let ev = HalfGateEvaluator;
|
||||
|
||||
let mut delta = rng.random_block();
|
||||
let mut delta = Block::random(&mut rng);
|
||||
delta.set_lsb();
|
||||
let x_0 = rng.random_block();
|
||||
let x_0 = Block::random(&mut rng);
|
||||
let x = [x_0, x_0 ^ delta];
|
||||
let y_0 = rng.random_block();
|
||||
let y_0 = Block::random(&mut rng);
|
||||
let y = [y_0, y_0 ^ delta];
|
||||
let gid: usize = 1;
|
||||
|
||||
@@ -29,15 +31,15 @@ fn test_and_gate() {
|
||||
|
||||
#[test]
|
||||
fn test_xor_gate() {
|
||||
let mut rng = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let gen = HalfGateGenerator;
|
||||
let ev = HalfGateEvaluator;
|
||||
|
||||
let mut delta = rng.random_block();
|
||||
let mut delta = Block::random(&mut rng);
|
||||
delta.set_lsb();
|
||||
let x_0 = rng.random_block();
|
||||
let x_0 = Block::random(&mut rng);
|
||||
let x = [x_0, x_0 ^ delta];
|
||||
let y_0 = rng.random_block();
|
||||
let y_0 = Block::random(&mut rng);
|
||||
let y = [y_0, y_0 ^ delta];
|
||||
|
||||
let z = gen.xor_gate(x, y, delta);
|
||||
@@ -50,14 +52,14 @@ fn test_xor_gate() {
|
||||
|
||||
#[test]
|
||||
fn test_inv_gate() {
|
||||
let mut rng = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let gen = HalfGateGenerator;
|
||||
let ev = HalfGateEvaluator;
|
||||
|
||||
let mut delta = rng.random_block();
|
||||
let mut delta = Block::random(&mut rng);
|
||||
delta.set_lsb();
|
||||
let public_labels = [rng.random_block(), rng.random_block() ^ delta];
|
||||
let x_0 = rng.random_block();
|
||||
let public_labels = [Block::random(&mut rng), Block::random(&mut rng) ^ delta];
|
||||
let x_0 = Block::random(&mut rng);
|
||||
let x = [x_0, x_0 ^ delta];
|
||||
|
||||
let z = gen.inv_gate(x, public_labels, delta);
|
||||
@@ -67,7 +69,7 @@ fn test_inv_gate() {
|
||||
|
||||
#[test]
|
||||
fn test_aes_128() {
|
||||
let mut rng = Rng::new();
|
||||
let mut rng = ChaCha20Rng::from_entropy();
|
||||
let h = Aes::new(&[0u8; 16]);
|
||||
let circ = Circuit::parse("circuits/aes_128_reverse.txt").unwrap();
|
||||
let gen = HalfGateGenerator;
|
||||
|
||||
Reference in New Issue
Block a user