Skip to content

Commit

Permalink
Merge pull request #29 from WeBankBlockchain/release-1.2.0
Browse files Browse the repository at this point in the history
release-1.2.0
  • Loading branch information
HaoXuan40404 authored Sep 29, 2021
2 parents 10f314d + 0bb4d0a commit d74440a
Show file tree
Hide file tree
Showing 59 changed files with 3,048 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/default_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
- uses: actions/checkout@v1
- name: Nightly default
run: rustup default nightly
# - name: Generate proto
# run: cd protos && cargo run && cd ../
- name: Build
run: cargo build --verbose
run: cargo build --all --all-targets --verbose
- name: Run tests
run: cargo test --verbose
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ format_strings = true
indent_style = "Block"
match_block_trailing_comma = true
max_width = 80
merge_imports = true
imports_granularity = "Crate"
normalize_comments = true
normalize_doc_attributes = true
overflow_delimited_expr = true
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"crypto/hash/sha2",
"crypto/hash/sha3",
"crypto/hash/sm3",
"crypto/oblivious_transfer/base_ot",
"crypto/signature/ed25519",
"crypto/signature/secp256k1",
"crypto/signature/sm2",
Expand Down
27 changes: 27 additions & 0 deletions crypto/oblivious_transfer/base_ot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "wedpr_l_crypto_ot_base_ot"
version = "0.1.0"
edition = "2018"
license = "Apache-2.0"
description = "Library of WeDPR shared zkp Function implement base ot."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
curve25519-dalek = { version = "1", features = [ "serde" ] }
wedpr_l_crypto_zkp_utils = "1.2.0"
wedpr_l_crypto_hash_sha3 = { version = "1.0.0" }
lazy_static = "1.4.0"
wedpr_l_protos = "1.2.0"
wedpr_l_utils = "1.1.0"
sha3 = "0.8"
rand = "0.6"
rand_core = { version = "0.5", features = ["getrandom"]}

[dev-dependencies]
criterion = "0.3"
rand = "0.6.0"

[[bench]]
name = "base_ot"
harness = false
127 changes: 127 additions & 0 deletions crypto/oblivious_transfer/base_ot/benches/base_ot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0.

#[macro_use]
extern crate criterion;
use criterion::Criterion;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use wedpr_l_crypto_ot_base_ot::{
ot_kv::OtKvKOutOfN,
ot_message::{make_two_ot_messages, OtMessages1OutOf2},
};
use wedpr_l_protos::generated::ot::{BytesToBytesPair, DataDict, IdList};

fn create_base_ot_message_1_out_of_2_helper(c: &mut Criterion, str_len: u64) {
let label = format!(
"create_base_ot_message_1_out_of_2_helper, str_len = {}",
str_len
);
let random_message0: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(str_len as usize)
.collect();
let random_message1: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(str_len as usize)
.collect();
let data = make_two_ot_messages(&random_message0, &random_message1);

let choose_zero = true;
let expected_message = random_message0.as_bytes().to_vec();
let ot = OtMessages1OutOf2::default();

c.bench_function(&label, move |b| {
b.iter(|| {
let (receiver_secret, receiver_commitment) =
ot.receiver_init(choose_zero);
let sender_ciphertexts =
ot.sender_init(&data, &receiver_commitment).unwrap();
let decrypt_message = ot.receiver_decrypt(
choose_zero,
&receiver_secret,
&sender_ciphertexts,
);
assert_eq!(decrypt_message, expected_message);
})
});
}

fn create_base_ot_kv_k_out_of_n_helper(
c: &mut Criterion,
k_choose_count: u64,
n_message_count: u64,
str_len: u64,
) {
let label = format!(
"create_base_ot_kv_k_out_of_n_helper, k_choose_count = {}, \
n_message_count = {}, str_len = {}",
k_choose_count, n_message_count, str_len
);
let mut data = DataDict::default();
let mut expected: Vec<Vec<u8>> = vec![];
for _ in 0..n_message_count {
let random_id: String =
thread_rng().sample_iter(&Alphanumeric).take(18).collect();
let random_message: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(str_len as usize)
.collect();
data.mut_pair().push(BytesToBytesPair {
id: random_id.as_bytes().to_vec(),
message: random_message.as_bytes().to_vec(),
unknown_fields: Default::default(),
cached_size: Default::default(),
})
}
let mut choice_list = IdList::default();
for i in 0..k_choose_count {
let pair = &data.get_pair()[i as usize];
choice_list.mut_id().push(pair.get_id().to_vec());
expected.push(pair.get_message().to_vec())
}
let ot = OtKvKOutOfN::default();

c.bench_function(&label, move |b| {
b.iter(|| {
let (receiver_secret, receiver_commitment) =
ot.receiver_init(&choice_list);
let sender_ciphertexts =
ot.sender_init(&data, &receiver_commitment).unwrap();
let message = ot
.receiver_decrypt(
&receiver_secret,
&sender_ciphertexts,
k_choose_count as usize,
)
.unwrap();
assert_eq!(message, expected);
})
});
}

fn create_base_ot_kv_k_out_of_n_1_300_10(c: &mut Criterion) {
create_base_ot_kv_k_out_of_n_helper(c, 1, 300, 10);
}

fn create_base_ot_kv_k_out_of_n_3_300_10(c: &mut Criterion) {
create_base_ot_kv_k_out_of_n_helper(c, 3, 300, 10);
}

fn create_base_ot_kv_k_out_of_n_10_300_10(c: &mut Criterion) {
create_base_ot_kv_k_out_of_n_helper(c, 10, 300, 10);
}

fn create_base_ot_message_1_out_of_2_10(c: &mut Criterion) {
create_base_ot_message_1_out_of_2_helper(c, 10);
}

criterion_group! {
name = init_base_ot_test;
config = Criterion::default().sample_size(10);
targets =
create_base_ot_message_1_out_of_2_10,
create_base_ot_kv_k_out_of_n_1_300_10,
create_base_ot_kv_k_out_of_n_3_300_10,
create_base_ot_kv_k_out_of_n_10_300_10,
}

criterion_main!(init_base_ot_test);
9 changes: 9 additions & 0 deletions crypto/oblivious_transfer/base_ot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.

//! Oblivious transfer (OT) functions.
#[macro_use]
extern crate lazy_static;

pub mod ot_kv;
pub mod ot_message;
Loading

0 comments on commit d74440a

Please sign in to comment.