From 7bd8e8a1fd98bb4ac6cb77ca78b79ca4b4bc07d2 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Mon, 19 Dec 2022 18:10:12 +0100 Subject: [PATCH 1/4] Prefer https:// url scheme for deps --- Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ba6438..7ec11c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,7 +233,7 @@ dependencies = [ [[package]] name = "generic-ec" version = "0.0.0" -source = "git+ssh://git@github.com/dfns-labs/generic-ec?branch=d#0eaee76851b51464818586abcd241242ac562742" +source = "git+https://github.com/dfns-labs/generic-ec?branch=d#8e1c966d2995884a9c15b5decd7b5c02f4b4a1a4" dependencies = [ "generic-array", "generic-ec-core", @@ -249,7 +249,7 @@ dependencies = [ [[package]] name = "generic-ec-core" version = "0.1.0" -source = "git+ssh://git@github.com/dfns-labs/generic-ec?branch=d#0eaee76851b51464818586abcd241242ac562742" +source = "git+https://github.com/dfns-labs/generic-ec?branch=d#8e1c966d2995884a9c15b5decd7b5c02f4b4a1a4" dependencies = [ "generic-array", "rand_core", @@ -261,7 +261,7 @@ dependencies = [ [[package]] name = "generic-ec-curves" version = "0.1.0" -source = "git+ssh://git@github.com/dfns-labs/generic-ec?branch=d#0eaee76851b51464818586abcd241242ac562742" +source = "git+https://github.com/dfns-labs/generic-ec?branch=d#8e1c966d2995884a9c15b5decd7b5c02f4b4a1a4" dependencies = [ "elliptic-curve", "generic-ec-core", diff --git a/Cargo.toml b/Cargo.toml index 6dd75b5..91ded99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -generic-ec = { git = "ssh://git@github.com/dfns-labs/generic-ec", branch = "d" } -generic-ec-core = { git = "ssh://git@github.com/dfns-labs/generic-ec", branch = "d" } +generic-ec = { git = "https://github.com/dfns-labs/generic-ec", branch = "d" } +generic-ec-core = { git = "https://github.com/dfns-labs/generic-ec", branch = "d" } rand_core = { version = "0.6", default-features = false } rand_chacha = { version = "0.3", default-features = false } libpaillier = { version = "0.5", features = ["rust"], default-features = false } @@ -18,4 +18,4 @@ zeroize = { version = "1.5", default-features = false } [dev-dependencies] rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } -generic-ec-curves = { git = "ssh://git@github.com/dfns-labs/generic-ec", branch = "d", features = ["secp256r1"] } +generic-ec-curves = { git = "https://github.com/dfns-labs/generic-ec", branch = "d", features = ["secp256r1"] } From f56bc90fde3a9f200a34eaa57cf67a9e330a87bb Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Mon, 19 Dec 2022 18:14:28 +0100 Subject: [PATCH 2/4] Implement missing traits --- src/group_element_vs_paillier_encryption_in_range.rs | 6 ++++++ src/paillier_affine_operation_in_range.rs | 6 ++++++ src/paillier_blum_modulus.rs | 7 ++++++- src/paillier_decryption_modulo_q.rs | 6 ++++++ src/paillier_encryption_in_range.rs | 6 ++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/group_element_vs_paillier_encryption_in_range.rs b/src/group_element_vs_paillier_encryption_in_range.rs index af6b71e..ec8e21b 100644 --- a/src/group_element_vs_paillier_encryption_in_range.rs +++ b/src/group_element_vs_paillier_encryption_in_range.rs @@ -86,6 +86,7 @@ use crate::unknown_order::BigNumber; use generic_ec::{Curve, Point}; use libpaillier::{Ciphertext, EncryptionKey, Nonce}; +#[derive(Debug, Clone)] pub struct SecurityParams { /// l in paper, bit size of plaintext pub l: usize, @@ -93,6 +94,7 @@ pub struct SecurityParams { pub epsilon: usize, } +#[derive(Debug, Clone)] pub struct Data { pub key0: EncryptionKey, pub c: Ciphertext, @@ -101,11 +103,13 @@ pub struct Data { pub g: Point, } +#[derive(Clone)] pub struct PrivateData { pub x: BigNumber, pub nonce: Nonce, } +#[derive(Debug, Clone)] pub struct Commitment { pub s: BigNumber, pub a: Ciphertext, @@ -113,6 +117,7 @@ pub struct Commitment { pub d: BigNumber, } +#[derive(Clone)] pub struct PrivateCommitment { pub alpha: BigNumber, pub mu: BigNumber, @@ -122,6 +127,7 @@ pub struct PrivateCommitment { pub type Challenge = BigNumber; +#[derive(Debug, Clone)] pub struct Proof { pub z1: BigNumber, pub z2: BigNumber, diff --git a/src/paillier_affine_operation_in_range.rs b/src/paillier_affine_operation_in_range.rs index abb5658..bc03019 100644 --- a/src/paillier_affine_operation_in_range.rs +++ b/src/paillier_affine_operation_in_range.rs @@ -139,6 +139,7 @@ use libpaillier::{Ciphertext, EncryptionKey, Nonce}; pub use crate::common::InvalidProof; +#[derive(Debug, Clone)] pub struct SecurityParams { /// l in paper, bit size of x pub l_x: usize, @@ -149,6 +150,7 @@ pub struct SecurityParams { } /// Public data that both parties know +#[derive(Debug, Clone)] pub struct Data { /// N0 in paper, public key that C was encrypted on pub key0: EncryptionKey, @@ -165,6 +167,7 @@ pub struct Data { } /// Private data of prover +#[derive(Clone)] pub struct PrivateData { /// x or epsilon in paper, preimage of X pub x: BigNumber, @@ -178,6 +181,7 @@ pub struct PrivateData { // As described in cggmp21 at page 35 /// Prover's first message, obtained by `commit` +#[derive(Debug, Clone)] pub struct Commitment { pub a: BigNumber, pub b_x: Point, @@ -190,6 +194,7 @@ pub struct Commitment { /// Prover's data accompanying the commitment. Kept as state between rounds in /// the interactive protocol. +#[derive(Clone)] pub struct PrivateCommitment { pub alpha: BigNumber, pub beta: BigNumber, @@ -206,6 +211,7 @@ pub struct PrivateCommitment { pub type Challenge = BigNumber; /// The ZK proof. Computed by `prove` +#[derive(Debug, Clone)] pub struct Proof { pub z1: BigNumber, pub z2: BigNumber, diff --git a/src/paillier_blum_modulus.rs b/src/paillier_blum_modulus.rs index 9c4016f..9305b56 100644 --- a/src/paillier_blum_modulus.rs +++ b/src/paillier_blum_modulus.rs @@ -73,17 +73,20 @@ pub enum InvalidProof { } /// Public data that both parties know: the Paillier-Blum modulus +#[derive(Debug, Clone)] pub struct Data { pub n: BigNumber, } /// Private data of prover +#[derive(Clone)] pub struct PrivateData { pub p: BigNumber, pub q: BigNumber, } /// Prover's first message, obtained by `commit` +#[derive(Debug, Clone)] pub struct Commitment { pub w: BigNumber, } @@ -92,11 +95,12 @@ pub struct Commitment { /// `challenge` /// /// Consists of `M` singular challenges -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct Challenge { pub ys: [BigNumber; M], } +#[derive(Debug, Clone)] pub struct ProofPoint { pub x: BigNumber, pub a: bool, @@ -105,6 +109,7 @@ pub struct ProofPoint { } /// The ZK proof. Computed by `prove`. Consists of M proofs for each challenge +#[derive(Debug, Clone)] pub struct Proof { pub points: [ProofPoint; M], } diff --git a/src/paillier_decryption_modulo_q.rs b/src/paillier_decryption_modulo_q.rs index 520bb6d..9151140 100644 --- a/src/paillier_decryption_modulo_q.rs +++ b/src/paillier_decryption_modulo_q.rs @@ -75,6 +75,7 @@ use libpaillier::{Ciphertext, EncryptionKey, Nonce}; pub use crate::common::InvalidProof; +#[derive(Debug, Clone)] pub struct SecurityParams { /// l in paper, bit size of plaintext pub l: usize, @@ -83,6 +84,7 @@ pub struct SecurityParams { } /// Public data that both parties know +#[derive(Debug, Clone)] pub struct Data { /// q in paper, modulo value such that `x = y mod q` pub q: BigNumber, @@ -95,6 +97,7 @@ pub struct Data { } /// Private data of prover +#[derive(Clone)] pub struct PrivateData { /// y in paper, plaintext value of C pub y: BigNumber, @@ -102,6 +105,7 @@ pub struct PrivateData { pub nonce: Nonce, } +#[derive(Debug, Clone)] /// Prover's first message, obtained by `commit` pub struct Commitment { pub s: BigNumber, @@ -112,6 +116,7 @@ pub struct Commitment { /// Prover's data accompanying the commitment. Kept as state between rounds in /// the interactive protocol. +#[derive(Clone)] pub struct PrivateCommitment { pub alpha: BigNumber, pub mu: BigNumber, @@ -124,6 +129,7 @@ pub struct PrivateCommitment { pub type Challenge = BigNumber; /// The ZK proof. Computed by `prove` +#[derive(Debug, Clone)] pub struct Proof { pub z1: BigNumber, pub z2: BigNumber, diff --git a/src/paillier_encryption_in_range.rs b/src/paillier_encryption_in_range.rs index e0992e6..e84931e 100644 --- a/src/paillier_encryption_in_range.rs +++ b/src/paillier_encryption_in_range.rs @@ -76,6 +76,7 @@ use libpaillier::{Ciphertext, EncryptionKey, Nonce}; pub use crate::common::InvalidProof; +#[derive(Debug, Clone)] pub struct SecurityParams { /// l in paper, bit size of plaintext pub l: usize, @@ -86,6 +87,7 @@ pub struct SecurityParams { } /// Public data that both parties know +#[derive(Debug, Clone)] pub struct Data { /// N0 in paper, public key that k -> K was encrypted on pub key: EncryptionKey, @@ -94,6 +96,7 @@ pub struct Data { } /// Private data of prover +#[derive(Clone)] pub struct PrivateData { /// k in paper, plaintext of K pub plaintext: BigNumber, @@ -103,6 +106,7 @@ pub struct PrivateData { // As described in cggmp21 at page 33 /// Prover's first message, obtained by `commit` +#[derive(Debug, Clone)] pub struct Commitment { pub s: BigNumber, pub a: BigNumber, @@ -111,6 +115,7 @@ pub struct Commitment { /// Prover's data accompanying the commitment. Kept as state between rounds in /// the interactive protocol. +#[derive(Clone)] pub struct PrivateCommitment { pub alpha: BigNumber, pub mu: BigNumber, @@ -124,6 +129,7 @@ pub type Challenge = BigNumber; // As described in cggmp21 at page 33 /// The ZK proof. Computed by `prove` +#[derive(Debug, Clone)] pub struct Proof { pub z1: BigNumber, pub z2: BigNumber, From 535392dbc876ef9bb019defee4bb7d3c3f346e50 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Mon, 19 Dec 2022 18:31:24 +0100 Subject: [PATCH 3/4] Expose accidently hidden error types --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 31bad24..5925b17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,4 +15,4 @@ pub use libpaillier; /// the correct version of the library pub use libpaillier::unknown_order; -pub use common::convert_scalar; +pub use common::{convert_scalar, InvalidProof, ProtocolError}; From 9bd65701f7eaf325c584c339821fc9724c2facda Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Mon, 19 Dec 2022 18:48:39 +0100 Subject: [PATCH 4/4] Choose bignumber backend by default, but allow to override --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 91ded99..98105ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ generic-ec = { git = "https://github.com/dfns-labs/generic-ec", branch = "d" } generic-ec-core = { git = "https://github.com/dfns-labs/generic-ec", branch = "d" } rand_core = { version = "0.6", default-features = false } rand_chacha = { version = "0.3", default-features = false } -libpaillier = { version = "0.5", features = ["rust"], default-features = false } +libpaillier = { version = "0.5", default-features = false } sha2 = { version = "0.10", default-features = false } subtle = { version = "2.4", default-features = false } @@ -19,3 +19,6 @@ zeroize = { version = "1.5", default-features = false } [dev-dependencies] rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } generic-ec-curves = { git = "https://github.com/dfns-labs/generic-ec", branch = "d", features = ["secp256r1"] } + +[features] +default = ["libpaillier/rust"]