Skip to content
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

+-x into 2x #6

Merged
merged 14 commits into from
Jan 27, 2023
85 changes: 0 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ generic-ec-curves = { git = "https://github.com/dfns-labs/generic-ec", branch =
[features]
default = ["rust"]
gmp = ["libpaillier/gmp"]
openssl = ["libpaillier/openssl"]
# openssl random generation doesn't respect the rng supplied from rust, and so shouldn't be used
#openssl = ["libpaillier/openssl"]
rust = ["libpaillier/rust"]

serde = ["dep:serde", "generic-ec/serde"]

[profile.dev.package.num-bigint]
opt-level = 3
[profile.dev.package.glass_pumpkin]
opt-level = 3
17 changes: 15 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub fn convert_scalar<C: generic_ec::Curve>(x: &BigNumber) -> generic_ec::Scalar
generic_ec::Scalar::<C>::from_be_bytes_mod_order(x.to_bytes())
}

/// Reason for failure. Mainly interesting for debugging purposes
/// Reason for failure. If the proof failes, you should only be interested in a
/// reason for debugging purposes
#[derive(Debug, PartialEq, Eq)]
pub enum InvalidProof {
/// One equality doesn't hold. Parameterized by equality index
Expand All @@ -49,6 +50,8 @@ pub enum InvalidProof {
EncryptionFailed,
}

/// Unexpeted error that can happen in a protocol. You should probably panic if
/// you see this.
#[derive(Debug, PartialEq, Eq)]
pub enum ProtocolError {
/// Encryption of supplied data failed when computing proof
Expand All @@ -58,7 +61,7 @@ pub enum ProtocolError {
}

#[cfg(test)]
mod test {
pub mod test {
use libpaillier::unknown_order::BigNumber;

#[test]
Expand All @@ -72,4 +75,14 @@ mod test {
let scalar2 = super::convert_scalar(&bignumber);
assert_eq!(scalar1, scalar2);
}

pub fn random_key<R: rand_core::RngCore>(rng: &mut R) -> Option<libpaillier::DecryptionKey> {
let p = BigNumber::prime_from_rng(1024, rng);
let q = BigNumber::prime_from_rng(1024, rng);
libpaillier::DecryptionKey::with_primes_unchecked(&p, &q)
}

pub fn nonce<R: rand_core::RngCore>(rng: &mut R, n: &BigNumber) -> Option<BigNumber> {
Some(BigNumber::from_rng(n, rng))
}
}
2 changes: 1 addition & 1 deletion src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl generic_ec_core::One for Scalar {

impl generic_ec_core::Samplable for Scalar {
fn random<R: rand_core::RngCore>(rng: &mut R) -> Self {
Scalar(rng.next_u64())
rng.next_u64().into()
}
}

Expand Down
Loading