Skip to content

Commit 00cc08b

Browse files
committed
rename acv
1 parent a5d622e commit 00cc08b

File tree

18 files changed

+610
-310
lines changed

18 files changed

+610
-310
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
members = [
44
"bounty",
5+
# "ffi/ffi_c/ffi_c_acv",
56
"ffi/ffi_c/ffi_c_ktb",
67
"ffi/ffi_c/ffi_c_scd",
78
"ffi/ffi_c/ffi_c_vcl",
@@ -12,5 +13,5 @@ members = [
1213
"solution/key_tool_box/hierarchical_deterministic_key",
1314
"solution/selective_certificate_disclosure",
1415
"solution/verifiable_confidential_ledger",
15-
"solution/anonymous_bounded_voting",
16+
"solution/anonymous_ciphertext_voting",
1617
]

ffi/ffi_c/ffi_c_acv/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "ffi_c_abv"
3+
version = "1.5.0"
4+
authors = [ "WeDPR <wedpr@webank.com>" ]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[lib]
10+
name = "ffi_c_abv"
11+
crate-type = [ "cdylib", "staticlib" ]
12+
13+
[dependencies]
14+
libc = "0.2.60"
15+
protobuf = "2.22.1"
16+
wedpr_s_anonymous_bounded_voting = { path = "../../../solution/anonymous_ciphertext_voting" }
17+
wedpr_ffi_common = "1.0.0"
18+
wedpr_ffi_macros = "1.0.0"
19+
wedpr_s_protos = { path = "../../../protos"}
20+
wedpr_l_macros = "1.0.0"
21+
wedpr_l_crypto_zkp_utils = "1.1.0"
22+
23+
24+
# This is required to generate C/C++ header files.
25+
[build-dependencies]
26+
cbindgen = "0.9.0"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2+
3+
//! Library of macros and functions for FFI of a voting coordinator in ABC
4+
//! solution, targeting C/C++ compatible architectures (including iOS).
5+
6+
// C/C++ FFI: C-style interfaces will be generated.
7+
8+
use wedpr_s_protos::generated::abv::{CandidateList, CounterSystemParametersStorage, RegistrationRequest, DecryptedResultPartStorage
9+
};
10+
11+
use libc::c_char;
12+
use protobuf::{self, Message};
13+
use std::{ffi::CString, panic, ptr};
14+
use wedpr_ffi_common::utils::{
15+
bytes_to_string, c_char_pointer_to_string, string_to_bytes,
16+
};
17+
use std::os::raw::{c_int, c_long, c_uint};
18+
19+
20+
/// C interface for 'wedpr_abv_make_system_parameters'.
21+
#[no_mangle]
22+
pub extern "C" fn wedpr_abv_make_system_parameters(
23+
candidates_cstring: *mut c_char,
24+
counter_storage_cstring: *mut c_char,
25+
) -> *mut c_char {
26+
let result = panic::catch_unwind(|| {
27+
let candidates =
28+
c_safe_c_char_pointer_to_proto!(candidates_cstring, CandidateList);
29+
30+
let counter_storage =
31+
c_safe_c_char_pointer_to_proto!(counter_storage_cstring, CounterSystemParametersStorage);
32+
33+
let system_parameters_storage =
34+
match wedpr_s_anonymous_bounded_voting::coordinator::make_system_parameters(
35+
&candidates,
36+
&counter_storage,
37+
) {
38+
Ok(v) => v,
39+
Err(_) => return ptr::null_mut(),
40+
};
41+
c_safe_proto_to_c_char_pointer!(system_parameters_storage)
42+
});
43+
c_safe_return!(result)
44+
}
45+
46+
/// C interface for 'wedpr_abv_certify_bounded_voter'.
47+
#[no_mangle]
48+
pub extern "C" fn wedpr_abv_certify_bounded_voter(
49+
secret_key_cstring: *mut c_char,
50+
blank_vote_value: c_uint,
51+
registration_request_cstring: *mut c_char,
52+
) -> *mut c_char {
53+
let result = panic::catch_unwind(|| {
54+
let registration_request =
55+
c_safe_c_char_pointer_to_proto!(registration_request_cstring, RegistrationRequest);
56+
let secret_key =
57+
c_safe_c_char_pointer_to_bytes!(secret_key_cstring);
58+
let value = blank_vote_value as u32;
59+
60+
let response =
61+
match wedpr_s_anonymous_bounded_voting::coordinator::certify_bounded_voter(
62+
&secret_key,
63+
value,
64+
&registration_request,
65+
) {
66+
Ok(v) => v,
67+
Err(_) => return ptr::null_mut(),
68+
};
69+
c_safe_proto_to_c_char_pointer!(response)
70+
});
71+
c_safe_return!(result)
72+
}
73+
74+
/// C interface for 'wedpr_abv_aggregate_decrypted_part_sum'.
75+
#[no_mangle]
76+
pub extern "C" fn wedpr_abv_aggregate_decrypted_part_sum(
77+
param_cstring: *mut c_char,
78+
decrypted_result_part_storage_cstring: *mut c_char,
79+
counting_result_sum_cstring: *mut c_char,
80+
) -> *mut c_char {
81+
let result = panic::catch_unwind(|| {
82+
let param =
83+
c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage);
84+
85+
let decrypted_result_part_storage =
86+
c_safe_c_char_pointer_to_proto!(decrypted_result_part_storage_cstring, DecryptedResultPartStorage);
87+
88+
let mut counting_result_sum =
89+
c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage);
90+
91+
92+
let b_result =
93+
match wedpr_s_anonymous_bounded_voting::coordinator::aggregate_decrypted_part_sum(
94+
&param,
95+
&decrypted_result_part_storage,
96+
&mut counting_result_sum,
97+
) {
98+
Ok(v) => v,
99+
Err(_) => return ptr::null_mut(),
100+
};
101+
if !b_result {
102+
return ptr::null_mut();
103+
}
104+
c_safe_proto_to_c_char_pointer!(counting_result_sum)
105+
});
106+
c_safe_return!(result)
107+
}

ffi/ffi_c/ffi_c_acv/src/counter.rs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2+
3+
//! Library of macros and functions for FFI of a counter in ABC
4+
//! solution, targeting C/C++ compatible architectures (including iOS).
5+
6+
// C/C++ FFI: C-style interfaces will be generated.
7+
8+
use wedpr_s_protos::generated::abv::{CounterSecret, VoteStorage
9+
};
10+
11+
use libc::c_char;
12+
use protobuf::{self, Message};
13+
use std::{ffi::CString, panic, ptr};
14+
use wedpr_ffi_common::utils::{
15+
bytes_to_string, c_char_pointer_to_string, string_to_bytes,
16+
};
17+
use std::os::raw::c_long;
18+
19+
/// C interface for 'wedpr_abv_make_counter_secret'.
20+
#[no_mangle]
21+
pub extern "C" fn wedpr_abv_make_counter_secret(
22+
) -> *mut c_char {
23+
let result = panic::catch_unwind(|| {
24+
25+
let secret =
26+
wedpr_s_anonymous_bounded_voting::counter::make_counter_secret();
27+
c_safe_proto_to_c_char_pointer!(secret)
28+
});
29+
c_safe_return!(result)
30+
}
31+
32+
33+
/// C interface for 'wedpr_abv_make_system_parameters_share'.
34+
#[no_mangle]
35+
pub extern "C" fn wedpr_abv_make_system_parameters_share(
36+
counter_id_cstring: *mut c_char,
37+
counter_secret_cstring: *mut c_char,
38+
) -> *mut c_char {
39+
let result = panic::catch_unwind(|| {
40+
let counter_id =
41+
c_safe_c_char_pointer_to_string!(counter_id_cstring);
42+
43+
let counter_secret =
44+
c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret);
45+
46+
let request =
47+
match wedpr_s_anonymous_bounded_voting::counter::make_system_parameters_share(
48+
&counter_id,
49+
&counter_secret,
50+
) {
51+
Ok(v) => v,
52+
Err(_) => return ptr::null_mut(),
53+
};
54+
c_safe_proto_to_c_char_pointer!(request)
55+
});
56+
c_safe_return!(result)
57+
}
58+
59+
/// C interface for 'wedpr_abv_count'.
60+
#[no_mangle]
61+
pub extern "C" fn wedpr_abv_count(
62+
counter_id_cstring: *mut c_char,
63+
counter_secret_cstring: *mut c_char,
64+
storage_cstring: *mut c_char,
65+
) -> *mut c_char {
66+
let result = panic::catch_unwind(|| {
67+
let counter_id =
68+
c_safe_c_char_pointer_to_string!(counter_id_cstring);
69+
70+
let counter_secret =
71+
c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret);
72+
73+
let storage =
74+
c_safe_c_char_pointer_to_proto!(storage_cstring, VoteStorage);
75+
76+
let request =
77+
match wedpr_s_anonymous_bounded_voting::counter::count(
78+
&counter_id,
79+
&counter_secret,
80+
&storage
81+
) {
82+
Ok(v) => v,
83+
Err(_) => return ptr::null_mut(),
84+
};
85+
c_safe_proto_to_c_char_pointer!(request)
86+
});
87+
c_safe_return!(result)
88+
}
89+
90+
/// C interface for 'wedpr_abv_finalize_vote_result'.
91+
#[no_mangle]
92+
pub extern "C" fn wedpr_abv_finalize_vote_result(
93+
param_cstring: *mut c_char,
94+
vote_sum_cstring: *mut c_char,
95+
counting_result_sum_cstring: *mut c_char,
96+
max_number: c_long,
97+
) -> *mut c_char {
98+
let result = panic::catch_unwind(|| {
99+
100+
let param =
101+
c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage);
102+
103+
let vote_sum =
104+
c_safe_c_char_pointer_to_proto!(vote_sum_cstring, VoteStorage);
105+
106+
let counting_result_sum =
107+
c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage);
108+
109+
let request =
110+
match wedpr_s_anonymous_bounded_voting::counter::finalize_vote_result(
111+
&param,
112+
&vote_sum,
113+
&counting_result_sum,
114+
max_number
115+
) {
116+
Ok(v) => v,
117+
Err(_) => return ptr::null_mut(),
118+
};
119+
c_safe_proto_to_c_char_pointer!(request)
120+
});
121+
c_safe_return!(result)
122+
}

ffi/ffi_c/ffi_c_acv/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2+
3+
//! Library of macros and functions for FFI of anonymous bounded voting (ABV) solutions,
4+
//! targeting C/C++ compatible architectures (including iOS).
5+
6+
#[allow(unused_imports)]
7+
#[macro_use]
8+
extern crate wedpr_ffi_macros;
9+
10+
#[macro_use]
11+
extern crate wedpr_l_macros;
12+
13+
pub mod coordinator;
14+
pub mod counter;
15+
pub mod verifier;
16+
pub mod voter;

0 commit comments

Comments
 (0)