add lib and license

This commit is contained in:
Janmajaya Mall
2024-01-12 17:34:21 +05:30
parent 743d567ba0
commit 91ccf99acf
5 changed files with 117 additions and 6 deletions

2
Cargo.lock generated
View File

@@ -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"

View File

@@ -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
View 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
View 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(&params, &mut rng);
let s_rlk_a = CollectiveRlkGenerator::init_state(&params, &mut rng);
let share_pk_a =
CollectivePublicKeyGenerator::generate_share(&params, &s_pk_a, CRS_PK, &mut rng);
let share_rlk_a =
CollectiveRlkGenerator::generate_share_1(&params, &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(&params, &mut rng);
let s_rlk_b = CollectiveRlkGenerator::init_state(&params, &mut rng);
let share_pk_b =
CollectivePublicKeyGenerator::generate_share(&params, &s_pk_b, CRS_PK, &mut rng);
let share_rlk_b =
CollectiveRlkGenerator::generate_share_1(&params, &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(
&params,
&collective_pk_shares,
CRS_PK,
);
}
fn state2() {}
fn state3() {}

View File

@@ -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.