Skip to content

Commit

Permalink
refactor ghash
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 committed Jan 24, 2023
1 parent afac611 commit 5ad6301
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 301 deletions.
124 changes: 0 additions & 124 deletions tls/tls-2pc-aio/src/ghash/aio.rs

This file was deleted.

117 changes: 0 additions & 117 deletions tls/tls-2pc-aio/src/ghash/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion tls/tls-2pc-aio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod ghash;
// pub mod conn;
// pub mod crypto;
// pub mod error;
Expand Down
4 changes: 1 addition & 3 deletions tls/tls-2pc-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ edition = "2021"
name = "tls_2pc_core"

[features]
default = ["prf", "ghash", "circuits"]
default = ["prf", "circuits"]
prf = []
ghash = []
circuits = ["c1", "c2", "c3", "c4", "c5", "c6", "c7"]
c1 = []
c2 = []
Expand Down Expand Up @@ -38,7 +37,6 @@ once_cell.workspace = true

[dev-dependencies]
criterion.workspace = true
ghash_rc.workspace = true
rand_chacha.workspace = true
hex.workspace = true
num = { workspace = true, features = ["rand"] }
Expand Down
2 changes: 0 additions & 2 deletions tls/tls-2pc-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(feature = "ghash")]
pub mod ghash;
pub mod msgs;
#[cfg(feature = "prf")]
pub mod prf;
Expand Down
45 changes: 45 additions & 0 deletions universal-hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "tlsn-universal-hash"
version = "0.1.0"
edition = "2021"

[features]
default = ["ghash", "mock"]
ghash = []
mock = []

[dependencies]
# tlsn
tlsn-mpc-core = { path = "../mpc/mpc-core" }
tlsn-mpc-aio = { path = "../mpc/mpc-aio" }
tlsn-utils = { path = "../utils/utils" }
tlsn-utils-aio = { path = "../utils/utils-aio" }
share-conversion-core = { path = "../mpc/share-conversion-core" }
share-conversion-aio = { path = "../mpc/share-conversion-aio" }

# rand
rand_chacha = "0.3"
rand = "0.8"
rand_core = "0.6"

# crypto
ghash_rc = { package = "ghash", version = "0.4" }

# async
async-trait = "0.1"
futures = "0.3"
futures-util = "0.3"
tokio = "1.23"
tokio-util = "0.7"

# testing
rstest = "0.16"
criterion = "0.3"

# error/log
thiserror = "1"

# misc
derive_builder = "0.11"
once_cell = "1"
generic-array = "0.14"
11 changes: 11 additions & 0 deletions universal-hash/src/ghash/ghash/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use derive_builder::Builder;

#[derive(Debug, Clone, Builder)]
pub struct GhashConfig {
/// Initial number of block shares to provision
#[builder(default = "1024")]
pub initial_block_count: usize,
/// Maximum number of blocks supported
#[builder(default = "1024")]
pub max_block_count: usize,
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha12Rng;
use share_conversion_aio::gf2_128::{
mock::{mock_converter_pair, Gf2Receiver, Gf2Sender},
recorder::Recorder,
};
use share_conversion_core::gf2_128::{AddShare, MulShare};

use super::Ghash;
use super::{Ghash, GhashConfigBuilder};

pub type MockGhashSender<T, U> = Ghash<Gf2Sender<AddShare, T>, Gf2Sender<MulShare, U>>;
pub type MockGhashReceiver<T, U> = Ghash<Gf2Receiver<AddShare, T>, Gf2Receiver<MulShare, U>>;

/// Create a Ghash sender/receiver pair for testing purpose
pub fn mock_ghash_pair<T: Recorder<AddShare> + Send, U: Recorder<MulShare> + Send>(
hashkey: u128,
message_len: usize,
block_count: usize,
) -> (MockGhashSender<T, U>, MockGhashReceiver<T, U>) {
let mut rng = ChaCha12Rng::from_seed([0; 32]);
let h1: u128 = rng.gen();
let h2 = hashkey ^ h1;

let (sender_a2m, receiver_a2m) = mock_converter_pair::<AddShare, _>();
let (sender_m2a, receiver_m2a) = mock_converter_pair::<MulShare, _>();

let config = GhashConfigBuilder::default()
.initial_block_count(block_count)
.build()
.unwrap();

let (sender, receiver) = (
Ghash::new(h1, message_len, sender_a2m, sender_m2a).unwrap(),
Ghash::new(h2, message_len, receiver_a2m, receiver_m2a).unwrap(),
Ghash::new(config.clone(), sender_a2m, sender_m2a),
Ghash::new(config, receiver_a2m, receiver_m2a),
);

(sender, receiver)
Expand Down
Loading

0 comments on commit 5ad6301

Please sign in to comment.