Skip to content

Commit 322a038

Browse files
committed
support use sm-algorithm to generate signature for acv when using sm feature
1 parent 963e46c commit 322a038

File tree

8 files changed

+72
-34
lines changed

8 files changed

+72
-34
lines changed

.github/workflows/workflow.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ jobs:
6464
with:
6565
name: libffi_c_hdk.dylib.tar.gz
6666
path: target/release/libffi_c_hdk.dylib
67+
- name: build sm-acv
68+
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
69+
- name: rename libffi_java_acv
70+
run: mv target/release/libffi_java_acv.dylib target/release/libffi_java_sm_acv.dylib
71+
- uses: actions/upload-artifact@v2
72+
with:
73+
name: libffi_java_sm_acv.dylib.tar.gz
74+
path: target/release/libffi_java_sm_acv.dylib
6775

6876
build_with_centos:
6977
name: build_with_centos
@@ -116,6 +124,14 @@ jobs:
116124
with:
117125
name: libffi_c_hdk.so.tar.gz
118126
path: target/release/libffi_c_hdk.so
127+
- name: build sm-acv
128+
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
129+
- name: rename libffi_java_acv
130+
run: mv target/release/libffi_java_acv.so target/release/libffi_java_sm_acv.so
131+
- uses: actions/upload-artifact@v2
132+
with:
133+
name: libffi_java_sm_acv.so.tar.gz
134+
path: target/release/libffi_java_sm_acv.so
119135
build_with_windows:
120136
name: build_with_windows
121137
runs-on: ${{ matrix.os }}
@@ -161,3 +177,11 @@ jobs:
161177
with:
162178
name: ffi_c_hdk.dll.zip
163179
path: D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_c_hdk.dll
180+
- name: build sm-acv
181+
run: cd ffi/ffi_java/ffi_java_acv && cargo clean && cargo build --release --no-default-features --features sm
182+
- name: rename libffi_java_acv
183+
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
184+
- uses: actions/upload-artifact@v2
185+
with:
186+
name: ffi_java_sm_acv.dll.zip
187+
path: D:\a\WeDPR-Lab-Core\WeDPR-Lab-Core\target\release\ffi_java_sm_acv.dll

ffi/ffi_java/ffi_java_acv/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ edition = "2018"
99
name = "ffi_java_acv"
1010
crate-type = [ "cdylib", "staticlib" ]
1111

12+
[features]
13+
default = ["wedpr_s_protos/wedpr_f_secp256k1_signature"]
14+
sm = ["wedpr_s_protos/wedpr_f_sm_signature"]
15+
1216
[dependencies]
1317
jni = "0.13.0"
1418
protobuf = "2.22.1"
1519
wedpr_ffi_common = "1.1.0"
1620
wedpr_ffi_macros = "1.1.0"
1721

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

2226
# This is required to generate C/C++ header files.
2327
[build-dependencies]

protos/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ edition = "2018"
66
license = "Apache-2.0"
77
description = "Library of WeDPR protobuf definitions and their generated code."
88

9+
[features]
10+
default = ["wedpr_f_secp256k1_signature"]
11+
sm = ["wedpr_f_sm_signature"]
12+
wedpr_f_sm_signature = ["wedpr_l_crypto_hash_sm3", "wedpr_l_crypto_signature_sm2"]
13+
wedpr_f_secp256k1_signature = ["wedpr_l_crypto_hash_keccak256", "wedpr_l_crypto_signature_secp256k1"]
14+
915
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1016

1117
[dependencies]
@@ -14,5 +20,7 @@ protobuf = "2.22.1"
1420
protoc-rust = "2.22.1"
1521
wedpr_l_utils = "1.1.0"
1622
wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
17-
wedpr_l_crypto_hash_keccak256 = "1.1.0"
18-
wedpr_l_crypto_signature_secp256k1 = "1.1.0"
23+
wedpr_l_crypto_hash_sm3 = {version = "1.1.0", optional = true}
24+
wedpr_l_crypto_signature_sm2 = {version = "1.1.0", optional = true}
25+
wedpr_l_crypto_hash_keccak256 = {version = "1.1.0", optional = true}
26+
wedpr_l_crypto_signature_secp256k1 = {version = "1.1.0", optional = true}

protos/src/config.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
22

33
//! Config of anonymous ciphertext voting (ACV) solution.
4+
#[cfg(feature = "wedpr_f_sm_signature")]
5+
use wedpr_l_crypto_hash_sm3::WedprSm3;
6+
#[cfg(feature = "wedpr_f_sm_signature")]
7+
use wedpr_l_crypto_signature_sm2::WedprSm2p256v1;
8+
#[cfg(feature = "wedpr_f_sm_signature")]
9+
lazy_static! {
10+
/// Shared signature algorithm reference for quick implementation replacement.
11+
pub static ref SIGNATURE: WedprSm2p256v1 =
12+
WedprSm2p256v1::default();
13+
/// Shared hash algorithm reference for quick implementation replacement.
14+
pub static ref HASH: WedprSm3 = WedprSm3::default();
15+
}
16+
17+
#[cfg(feature = "wedpr_f_secp256k1_signature")]
418
use wedpr_l_crypto_hash_keccak256::WedprKeccak256;
19+
#[cfg(feature = "wedpr_f_secp256k1_signature")]
520
use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover;
6-
7-
// TODO: support sm-crypto
21+
#[cfg(feature = "wedpr_f_secp256k1_signature")]
822
lazy_static! {
923
/// Shared signature algorithm reference for quick implementation replacement.
1024
pub static ref SIGNATURE: WedprSecp256k1Recover =
11-
WedprSecp256k1Recover::default();
25+
WedprSecp256k1Recover::default();
1226
/// Shared hash algorithm reference for quick implementation replacement.
1327
pub static ref HASH: WedprKeccak256 = WedprKeccak256::default();
1428
}

solution/anonymous_ciphertext_voting/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ license = "Apache-2.0"
77
description = "Library of anonymous ciphertext voting (ACV) solution."
88

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

1114
[dependencies]
1215
curve25519-dalek = { version = "1", features = [ "serde" ] }
1316
lazy_static = "1.4.0"
14-
wedpr_l_crypto_hash_keccak256 = "1.1.0"
15-
wedpr_l_crypto_signature_secp256k1 = "1.1.0"
1617
wedpr_l_crypto_zkp_discrete_logarithm_proof = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
1718
wedpr_l_crypto_zkp_range_proof = "1.2.0"
1819
wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
1920
wedpr_l_macros = "1.0.0"
2021
wedpr_l_utils = "1.1.0"
21-
wedpr_s_protos = { path = "../../protos" }
22+
wedpr_s_protos = { path = "../../protos", default-features = false}
2223
colored = "1.8"
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2-
3-
//! Config of anonymous ciphertext voting (ACV) solution.
4-
5-
use wedpr_l_crypto_hash_keccak256::WedprKeccak256;
6-
use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover;
7-
8-
lazy_static! {
9-
/// Shared signature algorithm reference for quick implementation replacement.
10-
pub static ref SIGNATURE: WedprSecp256k1Recover =
11-
WedprSecp256k1Recover::default();
12-
/// Shared hash algorithm reference for quick implementation replacement.
13-
pub static ref HASH: WedprKeccak256 = WedprKeccak256::default();
14-
}
15-
162
/// Poll result key for total ballots.
173
pub const POLL_RESULT_KEY_TOTAL_BALLOTS: &str = "Wedpr_voting_total_ballots";

solution/anonymous_ciphertext_voting/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ pub mod voter;
1818
#[cfg(test)]
1919
mod tests {
2020
use super::*;
21-
use crate::{
22-
config::{POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE},
23-
coordinator,
24-
};
21+
use crate::{config::POLL_RESULT_KEY_TOTAL_BALLOTS, coordinator};
2522
use wedpr_l_crypto_zkp_utils::{
2623
bytes_to_point, get_random_scalar, scalar_to_bytes,
2724
};
2825
use wedpr_l_utils::traits::Signature;
29-
use wedpr_s_protos::generated::acv::{
30-
CandidateList, CounterParametersStorage, CounterSecret,
31-
DecryptedResultPartStorage, UnlistedVoteChoice, VoteChoice,
32-
VoteChoices, VoteStorage, VoterSecret,
26+
use wedpr_s_protos::{
27+
config::SIGNATURE,
28+
generated::acv::{
29+
CandidateList, CounterParametersStorage, CounterSecret,
30+
DecryptedResultPartStorage, UnlistedVoteChoice, VoteChoice,
31+
VoteChoices, VoteStorage, VoterSecret,
32+
},
3333
};
3434

3535
#[test]

solution/anonymous_ciphertext_voting/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use wedpr_l_crypto_zkp_utils::bytes_to_point;
66
use wedpr_l_utils::traits::Signature;
7+
use wedpr_s_protos::config::SIGNATURE;
78

89
use wedpr_s_protos::generated::acv::{
910
CandidateList, CounterParametersStorage, CounterSecret,
@@ -13,8 +14,8 @@ use wedpr_s_protos::generated::acv::{
1314
extern crate wedpr_s_anonymous_ciphertext_voting;
1415
use colored::Colorize;
1516
use wedpr_s_anonymous_ciphertext_voting::{
16-
config::{POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE},
17-
coordinator, counter, verifier, voter,
17+
config::POLL_RESULT_KEY_TOTAL_BALLOTS, coordinator, counter, verifier,
18+
voter,
1819
};
1920

2021
fn main() {

0 commit comments

Comments
 (0)