Skip to content

Commit

Permalink
Modify twitter example documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuroitaki committed Aug 15, 2023
2 parents 9ee129a + f1841e2 commit f8ad85e
Show file tree
Hide file tree
Showing 91 changed files with 1,889 additions and 572 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy

- uses: Swatinem/rust-cache@v2.5.0
with:
Expand All @@ -66,3 +67,6 @@ jobs:
- name: "Integration Test"
if: ${{ matrix.release == true }}
run: cargo test --release --tests

- name: "Clippy"
run: cargo clippy --all-features -- -D warnings
11 changes: 11 additions & 0 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

for package in components/uid-mux components/actors/actor-ot components/cipher components/universal-hash components/aead components/key-exchange components/point-addition components/prf components/tls tlsn; do
pushd $package
# cargo update
cargo clean
cargo build
cargo test
cargo clippy --all-features -- -D warnings || exit
popd
done
6 changes: 3 additions & 3 deletions components/actors/actor-ot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
mpz-ot-core = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-ot = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-core = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-ot-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
mpz-ot = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
mpz-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
tlsn-utils-aio = { git = "https://github.com/tlsnotary/tlsn-utils" }
async-trait = "0.1"
derive_builder = "0.11"
Expand Down
18 changes: 15 additions & 3 deletions components/actors/actor-ot/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl Handler<Split> for KOSReceiverActor {

// These messages should not start being processed until after setup
// so this is a fatal error
let State::Setup{ receiver, child_receivers } = state else {
let State::Setup {
receiver,
child_receivers,
} = state
else {
return Err(OTError::Other("KOSReceiverActor is not setup".to_string()));
};

Expand Down Expand Up @@ -235,7 +239,11 @@ impl Handler<SendBackReceiver> for KOSReceiverActor {

// These messages should not start being processed until after setup
// so this is a fatal error
let State::Setup{ receiver, mut child_receivers } = state else {
let State::Setup {
receiver,
mut child_receivers,
} = state
else {
return Err(OTError::Other("KOSReceiverActor is not setup".to_string()));
};

Expand Down Expand Up @@ -266,7 +274,11 @@ impl Handler<Verify> for KOSReceiverActor {

// These messages should not start being processed until after setup
// so this is a fatal error
let State::Setup{ receiver, mut child_receivers } = state else {
let State::Setup {
receiver,
mut child_receivers,
} = state
else {
return Err(OTError::Other("KOSReceiverActor is not setup".to_string()));
};

Expand Down
14 changes: 11 additions & 3 deletions components/actors/actor-ot/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ impl Handler<GetSender> for KOSSenderActor {
// in case of early returns
let state = std::mem::replace(&mut self.state, State::Error);

let State::Setup{sender, child_senders} = state else {
let State::Setup {
sender,
child_senders,
} = state
else {
return Err(OTError::Other("KOSSenderActor is not setup".to_string()));
};

Expand Down Expand Up @@ -173,7 +177,7 @@ impl Handler<Reveal> for KOSSenderActor {
// Leave actor in error state
let state = std::mem::replace(&mut self.state, State::Error);

let State::Setup{child_senders, ..} = state else {
let State::Setup { child_senders, .. } = state else {
return Err(OTError::Other("KOSSenderActor is not setup".to_string()));
};
ctx.stop_self();
Expand All @@ -198,7 +202,11 @@ impl Handler<SendBackSender> for KOSSenderActor {
// Leave actor in error state
let state = std::mem::replace(&mut self.state, State::Error);

let State::Setup{sender, mut child_senders} = state else {
let State::Setup {
sender,
mut child_senders,
} = state
else {
return Err(OTError::Other("KOSSenderActor is not setup".to_string()));
};

Expand Down
6 changes: 3 additions & 3 deletions components/aead/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ tracing = ["dep:tracing"]
tlsn-block-cipher = { path = "../cipher/block-cipher" }
tlsn-stream-cipher = { path = "../cipher/stream-cipher" }
tlsn-universal-hash = { path = "../universal-hash" }
mpz-core = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-garble = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
mpz-garble = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
tlsn-utils-aio = { git = "https://github.com/tlsnotary/tlsn-utils" }

async-trait = "0.1"
Expand All @@ -32,5 +32,5 @@ serde = "1"
tracing = { version = "0.1", optional = true }

[dev-dependencies]
tokio = "1"
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"]}
aes-gcm = "0.10"
28 changes: 7 additions & 21 deletions components/cipher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
[workspace]
members = ["stream-cipher", "block-cipher"]
resolver = "2"

[workspace.dependencies]
# tlsn
mpz-circuits = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-core = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-garble-core = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-garble = { git = "https://github.com/tlsnotary/mpz", rev = "5a66465" }
mpz-circuits = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
mpz-garble = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "86f1687" }
tlsn-utils = { git = "https://github.com/tlsnotary/tlsn-utils" }
tlsn-utils-aio = { git = "https://github.com/tlsnotary/tlsn-utils" }

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

# crypto
aes = "0.8"
Expand All @@ -23,22 +16,15 @@ cipher = "0.4.3"
# async
async-trait = "0.1"
futures = "0.3"
futures-util = "0.3"
tokio = { version = "1", default-features = false }
tokio-util = "0.7"

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

# serialization
prost = "0.9"
rstest = "0.17"
criterion = "0.5"

# error/log
thiserror = "1"
tracing = "0.1"

# misc
rayon = "1"
derive_builder = "0.11"
once_cell = "1"
generic-array = "0.14"
derive_builder = "0.12"
14 changes: 7 additions & 7 deletions components/cipher/block-cipher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[package]
name = "tlsn-block-cipher"
authors = ["TLSNotary Team"]
description = "2PC block cipher implementation"
keywords = ["tls", "mpc", "2pc", "block-cipher"]
categories = ["cryptography"]
license = "MIT OR Apache-2.0"
version = "0.1.0"
edition = "2021"

Expand All @@ -8,28 +13,23 @@ name = "block_cipher"

[features]
default = ["mock"]
tracing = ["dep:tracing"]
mock = []

[dependencies]
mpz-circuits.workspace = true
mpz-garble.workspace = true
tlsn-utils.workspace = true

async-trait.workspace = true
futures.workspace = true
thiserror.workspace = true
derive_builder.workspace = true
tracing = { workspace = true, optional = true }

[dev-dependencies]
aes.workspace = true
ctr.workspace = true
cipher.workspace = true
rand_chacha.workspace = true
tokio = { workspace = true, features = [
"macros",
"io-util",
"rt",
"rt-multi-thread",
] }
rstest = { workspace = true, features = ["async-timeout"] }
criterion = { workspace = true, features = ["async_tokio"] }
17 changes: 17 additions & 0 deletions components/cipher/block-cipher/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ where
///
/// * `config` - The configuration for the block cipher
/// * `executor` - The executor to use for the MPC
#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "info", skip(executor))
)]
pub fn new(config: BlockCipherConfig, executor: E) -> Self {
let execution_id = NestedId::new(&config.id).append_counter();
Self {
Expand All @@ -55,10 +59,15 @@ where
C: BlockCipherCircuit,
E: Memory + Execute + Decode + DecodePrivate + Send + Sync + Send,
{
#[cfg_attr(feature = "tracing", tracing::instrument(level = "info", skip(self)))]
fn set_key(&mut self, key: ValueRef) {
self.state.key = Some(key);
}

#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "debug", skip(self, plaintext), err)
)]
async fn encrypt_private(&mut self, plaintext: Vec<u8>) -> Result<Vec<u8>, BlockCipherError> {
let len = plaintext.len();
let block: C::BLOCK = plaintext
Expand Down Expand Up @@ -95,6 +104,10 @@ where
Ok(ciphertext.into())
}

#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "debug", skip(self), err)
)]
async fn encrypt_blind(&mut self) -> Result<Vec<u8>, BlockCipherError> {
let key = self.state.key.clone().ok_or(BlockCipherError::KeyNotSet)?;

Expand Down Expand Up @@ -126,6 +139,10 @@ where
Ok(ciphertext.into())
}

#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "debug", skip(self, plaintext), err)
)]
async fn encrypt_share(&mut self, plaintext: Vec<u8>) -> Result<Vec<u8>, BlockCipherError> {
let len = plaintext.len();
let block: C::BLOCK = plaintext
Expand Down
2 changes: 1 addition & 1 deletion components/cipher/block-cipher/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait BlockCipherCircuit: Default + Clone + Send + Sync {
/// The length of the block
const BLOCK_LEN: usize;

/// Returns circuit
/// Returns the circuit of the cipher
fn circuit() -> Arc<Circuit>;
}

Expand Down
15 changes: 8 additions & 7 deletions components/cipher/stream-cipher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
[package]
name = "tlsn-stream-cipher"
authors = ["TLSNotary Team"]
description = "2PC stream cipher implementation"
keywords = ["tls", "mpc", "2pc", "stream-cipher"]
categories = ["cryptography"]
license = "MIT OR Apache-2.0"
version = "0.1.0"
edition = "2021"

[features]
default = ["mock"]
tracing = ["dep:tracing"]
mock = []

[dependencies]
mpz-circuits.workspace = true
mpz-garble.workspace = true
tlsn-utils.workspace = true

aes.workspace = true

async-trait.workspace = true
tokio = { workspace = true, default-features = false, features = ["sync"] }
futures.workspace = true
rand.workspace = true
thiserror.workspace = true
derive_builder.workspace = true
tracing = { workspace = true, optional = true }

[dev-dependencies]
ctr.workspace = true
cipher.workspace = true
rand_chacha.workspace = true
futures.workspace = true
tokio = { workspace = true, features = [
"macros",
"io-util",
"rt",
"rt-multi-thread",
] }
Expand Down
3 changes: 2 additions & 1 deletion components/cipher/stream-cipher/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub trait CtrCircuit: Default + Clone + Send + Sync + 'static {
+ Copy
+ Send
+ Sync
+ std::fmt::Debug
+ 'static;

/// The length of the key
Expand All @@ -48,7 +49,7 @@ pub trait CtrCircuit: Default + Clone + Send + Sync + 'static {
/// The length of the nonce
const NONCE_LEN: usize;

/// Returns circuit
/// Returns the circuit of the cipher
fn circuit() -> Arc<Circuit>;
}

Expand Down
Loading

0 comments on commit f8ad85e

Please sign in to comment.