-
Notifications
You must be signed in to change notification settings - Fork 10
move x1 to range {q/3 , ... , 2q/3} for create_commitments #2
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
base: serde-type-name
Are you sure you want to change the base?
Changes from 5 commits
692114d
18b3c0e
55a83ad
56b3e75
b112faf
2f41e69
cce62df
f22090f
8e1183e
6e24f31
97fd305
96b3055
e187cb3
621b571
ea39420
b61cb57
fae2a5c
ae29559
9a7ad75
31f0bc0
b627997
a5ed1ce
bfdba3e
7863d43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ use crate::paillier::{Decrypt, EncryptWithChosenRandomness, KeyGeneration}; | |
| use crate::paillier::{DecryptionKey, EncryptionKey, Randomness, RawCiphertext, RawPlaintext}; | ||
| use crate::zk_paillier::zkproofs::{NICorrectKeyProof, RangeProofNi}; | ||
| use std::cmp; | ||
| use std::ops::Shl; | ||
| use std::ops::{Mul, Shl}; | ||
|
|
||
| use super::SECURITY_BITS; | ||
| pub use crate::curv::arithmetic::traits::*; | ||
|
|
@@ -136,14 +136,36 @@ pub struct EphKeyGenSecondMsg {} | |
| //****************** End: Party One structs ******************// | ||
|
|
||
| impl KeyGenFirstMsg { | ||
| pub fn create_commitments() -> (KeyGenFirstMsg, CommWitness, EcKeyPair) { | ||
| let base: GE = ECPoint::generator(); | ||
|
|
||
| let secret_share: FE = ECScalar::new_random(); | ||
| //in Lindell's protocol range proof works only for x1<q/3 | ||
| let secret_share: FE = | ||
| ECScalar::from(&secret_share.to_big_int().div_floor(&BigInt::from(3))); | ||
| //in Lindell's protocol range proof works only for x1 \in {q/3 , ... , 2q/3} | ||
| pub fn is_secret_share_in_range(secret_share: &FE) -> bool { | ||
| let lower_bound: BigInt = FE::q().div_floor(&BigInt::from(3)); | ||
| let upper_bound: BigInt = FE::q().mul(&BigInt::from(2)) | ||
| .div_floor(&BigInt::from(3)); | ||
|
|
||
| return if secret_share.to_big_int().gt(&lower_bound) && | ||
| secret_share.to_big_int().lt(&upper_bound) { | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| pub fn get_secret_share_in_range() -> FE { | ||
| let mut secret_share: FE = ECScalar::new_random(); | ||
| secret_share = ECScalar::from(&secret_share.to_big_int()); | ||
|
||
|
|
||
| while !Self::is_secret_share_in_range(&secret_share) { | ||
| secret_share = ECScalar::new_random(); | ||
| secret_share = ECScalar::from(&secret_share.to_big_int()); | ||
|
||
| } | ||
|
|
||
| return secret_share; | ||
| } | ||
|
|
||
| pub fn create_commitments() -> (KeyGenFirstMsg, CommWitness, EcKeyPair) { | ||
| let base: GE = ECPoint::generator(); | ||
| let secret_share: FE = Self::get_secret_share_in_range(); | ||
| let public_share = base.scalar_mul(&secret_share.get_element()); | ||
|
|
||
| let d_log_proof = DLogProof::prove(&secret_share); | ||
|
|
@@ -183,10 +205,8 @@ impl KeyGenFirstMsg { | |
| pub fn create_commitments_with_fixed_secret_share( | ||
| secret_share: FE, | ||
| ) -> (KeyGenFirstMsg, CommWitness, EcKeyPair) { | ||
| //in Lindell's protocol range proof works only for x1<q/3 | ||
| let sk_bigint = secret_share.to_big_int(); | ||
| let q_third = FE::q(); | ||
| assert!(sk_bigint < q_third.div_floor(&BigInt::from(3))); | ||
|
|
||
| assert!(Self::is_secret_share_in_range(&secret_share)); | ||
| let base: GE = ECPoint::generator(); | ||
| let public_share = base.scalar_mul(&secret_share.get_element()); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you have a look in
sample_rangein curv and adapt your code, seems that is what we want