Skip to content

support use sm-algorithm to generate signature for acv when using sm feature #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ jobs:
with:
name: libffi_c_hdk.dylib.tar.gz
path: target/release/libffi_c_hdk.dylib
- name: build sm-acv
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
- name: rename libffi_java_acv
run: mv target/release/libffi_java_acv.dylib target/release/libffi_java_sm_acv.dylib
- uses: actions/upload-artifact@v2
with:
name: libffi_java_sm_acv.dylib.tar.gz
path: target/release/libffi_java_sm_acv.dylib

build_with_centos:
name: build_with_centos
Expand Down Expand Up @@ -116,6 +124,14 @@ jobs:
with:
name: libffi_c_hdk.so.tar.gz
path: target/release/libffi_c_hdk.so
- name: build sm-acv
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
- name: rename libffi_java_acv
run: mv target/release/libffi_java_acv.so target/release/libffi_java_sm_acv.so
- uses: actions/upload-artifact@v2
with:
name: libffi_java_sm_acv.so.tar.gz
path: target/release/libffi_java_sm_acv.so
build_with_windows:
name: build_with_windows
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -161,3 +177,11 @@ jobs:
with:
name: ffi_c_hdk.dll.zip
path: D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_c_hdk.dll
- name: build sm-acv
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
- name: rename libffi_java_acv
run: mv D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_java_acv.dll D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_java_sm_acv.dll
- uses: actions/upload-artifact@v2
with:
name: ffi_java_sm_acv.dll.zip
path: D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_java_sm_acv.dll
8 changes: 6 additions & 2 deletions ffi/ffi_java/ffi_java_acv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ edition = "2018"
name = "ffi_java_acv"
crate-type = [ "cdylib", "staticlib" ]

[features]
default = ["wedpr_s_protos/wedpr_f_secp256k1_signature"]
sm = ["wedpr_s_protos/wedpr_f_sm_signature"]

[dependencies]
jni = "0.13.0"
protobuf = "2.22.1"
wedpr_ffi_common = "1.1.0"
wedpr_ffi_macros = "1.1.0"

wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
wedpr_s_protos = { path = "../../../protos" }
wedpr_s_anonymous_ciphertext_voting = { path = "../../../solution/anonymous_ciphertext_voting" }
wedpr_s_protos = { path = "../../../protos", default-features = false}
wedpr_s_anonymous_ciphertext_voting = { path = "../../../solution/anonymous_ciphertext_voting", default-features = false}

# This is required to generate C/C++ header files.
[build-dependencies]
Expand Down
12 changes: 10 additions & 2 deletions protos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ edition = "2018"
license = "Apache-2.0"
description = "Library of WeDPR protobuf definitions and their generated code."

[features]
default = ["wedpr_f_secp256k1_signature"]
sm = ["wedpr_f_sm_signature"]
wedpr_f_sm_signature = ["wedpr_l_crypto_hash_sm3", "wedpr_l_crypto_signature_sm2"]
wedpr_f_secp256k1_signature = ["wedpr_l_crypto_hash_keccak256", "wedpr_l_crypto_signature_secp256k1"]

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

[dependencies]
Expand All @@ -14,5 +20,7 @@ protobuf = "2.22.1"
protoc-rust = "2.22.1"
wedpr_l_utils = "1.1.0"
wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
wedpr_l_crypto_hash_keccak256 = "1.1.0"
wedpr_l_crypto_signature_secp256k1 = "1.1.0"
wedpr_l_crypto_hash_sm3 = {version = "1.1.0", optional = true}
wedpr_l_crypto_signature_sm2 = {version = "1.1.0", optional = true}
wedpr_l_crypto_hash_keccak256 = {version = "1.1.0", optional = true}
wedpr_l_crypto_signature_secp256k1 = {version = "1.1.0", optional = true}
20 changes: 17 additions & 3 deletions protos/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.

//! Config of anonymous ciphertext voting (ACV) solution.
#[cfg(feature = "wedpr_f_sm_signature")]
use wedpr_l_crypto_hash_sm3::WedprSm3;
#[cfg(feature = "wedpr_f_sm_signature")]
use wedpr_l_crypto_signature_sm2::WedprSm2p256v1;
#[cfg(feature = "wedpr_f_sm_signature")]
lazy_static! {
/// Shared signature algorithm reference for quick implementation replacement.
pub static ref SIGNATURE: WedprSm2p256v1 =
WedprSm2p256v1::default();
/// Shared hash algorithm reference for quick implementation replacement.
pub static ref HASH: WedprSm3 = WedprSm3::default();
}

#[cfg(feature = "wedpr_f_secp256k1_signature")]
use wedpr_l_crypto_hash_keccak256::WedprKeccak256;
#[cfg(feature = "wedpr_f_secp256k1_signature")]
use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover;

// TODO: support sm-crypto
#[cfg(feature = "wedpr_f_secp256k1_signature")]
lazy_static! {
/// Shared signature algorithm reference for quick implementation replacement.
pub static ref SIGNATURE: WedprSecp256k1Recover =
WedprSecp256k1Recover::default();
WedprSecp256k1Recover::default();
/// Shared hash algorithm reference for quick implementation replacement.
pub static ref HASH: WedprKeccak256 = WedprKeccak256::default();
}
7 changes: 4 additions & 3 deletions solution/anonymous_ciphertext_voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ license = "Apache-2.0"
description = "Library of anonymous ciphertext voting (ACV) solution."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["wedpr_s_protos/wedpr_f_secp256k1_signature"]
sm = ["wedpr_s_protos/wedpr_f_sm_signature"]

[dependencies]
curve25519-dalek = { version = "1", features = [ "serde" ] }
lazy_static = "1.4.0"
wedpr_l_crypto_hash_keccak256 = "1.1.0"
wedpr_l_crypto_signature_secp256k1 = "1.1.0"
wedpr_l_crypto_zkp_discrete_logarithm_proof = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
wedpr_l_crypto_zkp_range_proof = "1.2.0"
wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
wedpr_l_macros = "1.0.0"
wedpr_l_utils = "1.1.0"
wedpr_s_protos = { path = "../../protos" }
wedpr_s_protos = { path = "../../protos", default-features = false}
colored = "1.8"
14 changes: 0 additions & 14 deletions solution/anonymous_ciphertext_voting/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.

//! Config of anonymous ciphertext voting (ACV) solution.

use wedpr_l_crypto_hash_keccak256::WedprKeccak256;
use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover;

lazy_static! {
/// Shared signature algorithm reference for quick implementation replacement.
pub static ref SIGNATURE: WedprSecp256k1Recover =
WedprSecp256k1Recover::default();
/// Shared hash algorithm reference for quick implementation replacement.
pub static ref HASH: WedprKeccak256 = WedprKeccak256::default();
}

/// Poll result key for total ballots.
pub const POLL_RESULT_KEY_TOTAL_BALLOTS: &str = "Wedpr_voting_total_ballots";
16 changes: 8 additions & 8 deletions solution/anonymous_ciphertext_voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ pub mod voter;
#[cfg(test)]
mod tests {
use super::*;
use crate::{
config::{POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE},
coordinator,
};
use crate::{config::POLL_RESULT_KEY_TOTAL_BALLOTS, coordinator};
use wedpr_l_crypto_zkp_utils::{
bytes_to_point, get_random_scalar, scalar_to_bytes,
};
use wedpr_l_utils::traits::Signature;
use wedpr_s_protos::generated::acv::{
CandidateList, CounterParametersStorage, CounterSecret,
DecryptedResultPartStorage, UnlistedVoteChoice, VoteChoice,
VoteChoices, VoteStorage, VoterSecret,
use wedpr_s_protos::{
config::SIGNATURE,
generated::acv::{
CandidateList, CounterParametersStorage, CounterSecret,
DecryptedResultPartStorage, UnlistedVoteChoice, VoteChoice,
VoteChoices, VoteStorage, VoterSecret,
},
};

#[test]
Expand Down
5 changes: 3 additions & 2 deletions solution/anonymous_ciphertext_voting/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use wedpr_l_crypto_zkp_utils::bytes_to_point;
use wedpr_l_utils::traits::Signature;
use wedpr_s_protos::config::SIGNATURE;

use wedpr_s_protos::generated::acv::{
CandidateList, CounterParametersStorage, CounterSecret,
Expand All @@ -13,8 +14,8 @@ use wedpr_s_protos::generated::acv::{
extern crate wedpr_s_anonymous_ciphertext_voting;
use colored::Colorize;
use wedpr_s_anonymous_ciphertext_voting::{
config::{POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE},
coordinator, counter, verifier, voter,
config::POLL_RESULT_KEY_TOTAL_BALLOTS, coordinator, counter, verifier,
voter,
};

fn main() {
Expand Down