mirror of
https://github.com/cursive-team/2P-PSI.git
synced 2026-01-09 03:57:55 -05:00
add lib and license
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -17,7 +17,6 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
[[package]]
|
||||
name = "bfv"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/Janmajayamall/bfv?branch=pk#34090532ce04ee6c143753edab11f902c057837c"
|
||||
dependencies = [
|
||||
"concrete-ntt",
|
||||
"crypto-bigint",
|
||||
@@ -344,7 +343,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "traits"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/Janmajayamall/bfv?branch=pk#34090532ce04ee6c143753edab11f902c057837c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
|
||||
@@ -6,6 +6,6 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bfv = {git = "https://github.com/Janmajayamall/bfv", branch = "pk"}
|
||||
bfv = {path = "./../bfv/bfv"}
|
||||
rand = "0.8.5"
|
||||
itertools = "0.10.5"
|
||||
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Gaussian
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
83
src/lib.rs
Normal file
83
src/lib.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use bfv::{
|
||||
BfvParameters, Ciphertext, CollectivePublicKeyGenerator, CollectiveRlkGenerator,
|
||||
CollectiveRlkGeneratorState, Poly, SecretKey,
|
||||
};
|
||||
use rand::thread_rng;
|
||||
|
||||
static CRS_PK: [u8; 32] = [0u8; 32];
|
||||
static CRS_RLK: [u8; 32] = [0u8; 32];
|
||||
|
||||
fn params() -> BfvParameters {
|
||||
let mut params = BfvParameters::new(&[30, 30], 65537, 1 << 15);
|
||||
params.enable_hybrid_key_switching(&[30]);
|
||||
params.enable_pke();
|
||||
params
|
||||
}
|
||||
|
||||
struct PrivateOutputAPostState0 {
|
||||
s_pk_a: SecretKey,
|
||||
s_rlk_a: SecretKey,
|
||||
}
|
||||
struct MessageAToBPostState0 {
|
||||
share_pk_a: Poly,
|
||||
share_rlk_a: (Vec<Poly>, Vec<Poly>),
|
||||
}
|
||||
|
||||
struct PrivateOutputBPostState0 {
|
||||
s_pk_b: SecretKey,
|
||||
}
|
||||
struct MessageBToAPostState1 {}
|
||||
|
||||
struct MessageAToBPostState2 {}
|
||||
|
||||
struct MessageBToAPostState3 {}
|
||||
|
||||
fn state0() -> (PrivateOutputAPostState0, MessageAToBPostState0) {
|
||||
let params = params();
|
||||
let mut rng = thread_rng();
|
||||
let s_pk_a = SecretKey::random_with_params(¶ms, &mut rng);
|
||||
let s_rlk_a = CollectiveRlkGenerator::init_state(¶ms, &mut rng);
|
||||
|
||||
let share_pk_a =
|
||||
CollectivePublicKeyGenerator::generate_share(¶ms, &s_pk_a, CRS_PK, &mut rng);
|
||||
|
||||
let share_rlk_a =
|
||||
CollectiveRlkGenerator::generate_share_1(¶ms, &s_pk_a, &s_rlk_a, CRS_RLK, 0, &mut rng);
|
||||
|
||||
let message_a_to_b = MessageAToBPostState0 {
|
||||
share_pk_a,
|
||||
share_rlk_a,
|
||||
};
|
||||
|
||||
let private_state_a = PrivateOutputAPostState0 {
|
||||
s_pk_a,
|
||||
s_rlk_a: s_rlk_a.0.clone(),
|
||||
};
|
||||
|
||||
(private_state_a, message_a_to_b)
|
||||
}
|
||||
|
||||
fn state1(input: MessageAToBPostState0) -> () {
|
||||
let params = params();
|
||||
let mut rng = thread_rng();
|
||||
let s_pk_b = SecretKey::random_with_params(¶ms, &mut rng);
|
||||
let s_rlk_b = CollectiveRlkGenerator::init_state(¶ms, &mut rng);
|
||||
|
||||
let share_pk_b =
|
||||
CollectivePublicKeyGenerator::generate_share(¶ms, &s_pk_b, CRS_PK, &mut rng);
|
||||
|
||||
let share_rlk_b =
|
||||
CollectiveRlkGenerator::generate_share_1(¶ms, &s_pk_b, &s_rlk_b, CRS_RLK, 0, &mut rng);
|
||||
|
||||
// collective public key
|
||||
let collective_pk_shares = vec![share_pk_b.clone(), input.share_pk_a];
|
||||
let collecitve_pk = CollectivePublicKeyGenerator::aggregate_shares_and_finalise(
|
||||
¶ms,
|
||||
&collective_pk_shares,
|
||||
CRS_PK,
|
||||
);
|
||||
}
|
||||
|
||||
fn state2() {}
|
||||
|
||||
fn state3() {}
|
||||
15
src/main.rs
15
src/main.rs
@@ -1,6 +1,6 @@
|
||||
use bfv::{
|
||||
BfvParameters, CollectiveDecryption, CollectivePublicKeyGenerator, CollectiveRlkGenerator,
|
||||
Encoding, EvaluationKey, Evaluator, PartySecret, Plaintext, Poly, PublicKey, SecretKey,
|
||||
Encoding, EvaluationKey, Evaluator, MHEDebugger, Plaintext, Poly, PublicKey, SecretKey,
|
||||
};
|
||||
use itertools::{izip, Itertools};
|
||||
use rand::{distributions::Uniform, thread_rng, Rng};
|
||||
@@ -36,8 +36,8 @@ fn plain_psi(parties: &[Party]) -> Vec<u64> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut params = BfvParameters::new(&[50, 50, 50], 65537, 1 << 15);
|
||||
params.enable_hybrid_key_switching(&[50, 50]);
|
||||
let mut params = BfvParameters::new(&[30, 30], 65537, 1 << 15);
|
||||
params.enable_hybrid_key_switching(&[30]);
|
||||
params.enable_pke();
|
||||
|
||||
let hw = 21000;
|
||||
@@ -130,6 +130,15 @@ fn main() {
|
||||
let ct1ct2 = evaluator.mul(&ct1, &ct2);
|
||||
let psi_ct = evaluator.relinearize(&ct1ct2, &evaluation_key);
|
||||
|
||||
unsafe {
|
||||
let secrets = parties.iter().map(|s| s.secret.clone()).collect_vec();
|
||||
dbg!(MHEDebugger::measure_noise(
|
||||
&secrets,
|
||||
evaluator.params(),
|
||||
&psi_ct
|
||||
));
|
||||
}
|
||||
|
||||
// Collective decryption //
|
||||
// Each party can independently generate their share to decrypt `psi_ct`. Unless the other party has evaluated the FHE circuit maliciously, they should be able to decrypt `psi_ct` after receiving other party's share.
|
||||
// As it is often the case in MPC, the last party to send their share has leverage to not send the share and prevent the other party from learning PSI output.
|
||||
|
||||
Reference in New Issue
Block a user