Skip to content

Commit

Permalink
Merge pull request #29 from jellevos/todos
Browse files Browse the repository at this point in the history
Fix open TODOs in code
  • Loading branch information
jellevos authored May 6, 2022
2 parents 1cc00bb + 2e87722 commit d3dc0b6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions scicrypt-he/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "scicrypt-he"
description = "A scicrypt crate implementing several well-known partially homomorphic (threshold) cryptosystems"
version = "0.5.0"
version = "0.6.0"
authors = ["Jelle Vos <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,8 +13,8 @@ readme = "README.md"
bench = false # Disable default bench (we use criterion)

[dependencies]
scicrypt-traits = { version = "0.5.0", path = "../scicrypt-traits" }
scicrypt-numbertheory = { version = "0.5.0", path = "../scicrypt-numbertheory" }
scicrypt-traits = { version = "0.6.0", path = "../scicrypt-traits" }
scicrypt-numbertheory = { version = "0.6.0", path = "../scicrypt-numbertheory" }
curve25519-dalek = "4.0.0-pre.2"
rug = "1.13"
rand_core = "0.6"
Expand Down
1 change: 0 additions & 1 deletion scicrypt-he/src/cryptosystems/curve_el_gamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl EncryptionKey for PrecomputedCurveElGamalPK {
}
}

// TODO: These double definitions can be made into one generic if associated ciphertexts have a trait
impl DecryptionKey<CurveElGamalPK> for CurveElGamalSK {
fn decrypt_raw(
&self,
Expand Down
2 changes: 1 addition & 1 deletion scicrypt-he/src/cryptosystems/paillier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct PaillierSK {

/// Ciphertext of the Paillier cryptosystem, which is additively homomorphic.
pub struct PaillierCiphertext {
c: Integer,
pub(crate) c: Integer,
}

impl Associable<PaillierPK> for PaillierCiphertext {}
Expand Down
21 changes: 8 additions & 13 deletions scicrypt-he/src/threshold_cryptosystems/paillier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use scicrypt_traits::threshold_cryptosystems::{
use scicrypt_traits::DecryptionError;
use std::ops::Rem;

use crate::cryptosystems::paillier::PaillierCiphertext;

/// Threshold Paillier cryptosystem: Extension of Paillier that requires t out of n parties to
/// successfully decrypt.
#[derive(Copy, Clone)]
Expand All @@ -32,13 +34,6 @@ pub struct ThresholdPaillierSK {
key: Integer,
}

/// A randomized ciphertext created using the public key.
pub struct ThresholdPaillierCiphertext {
c: Integer,
}

impl Associable<ThresholdPaillierPK> for ThresholdPaillierCiphertext {}

/// A partially decrypted ciphertext, of which t must be combined to decrypt successfully.
pub struct ThresholdPaillierShare {
id: i32,
Expand Down Expand Up @@ -108,16 +103,18 @@ impl TOfNCryptosystem for ThresholdPaillier {
}
}

impl Associable<ThresholdPaillierPK> for PaillierCiphertext {}

impl EncryptionKey for ThresholdPaillierPK {
type Input = Integer;
type Plaintext = Integer;
type Ciphertext = ThresholdPaillierCiphertext;
type Ciphertext = PaillierCiphertext;

fn encrypt_raw<R: SecureRng>(
&self,
plaintext: &Integer,
rng: &mut GeneralRng<R>,
) -> ThresholdPaillierCiphertext
) -> PaillierCiphertext
where
Self: Sized,
{
Expand All @@ -131,7 +128,7 @@ impl EncryptionKey for ThresholdPaillierPK {
);
let second = r.secure_pow_mod(&self.modulus, &n_squared);

ThresholdPaillierCiphertext {
PaillierCiphertext {
c: (first * second).rem(&n_squared),
}
}
Expand All @@ -143,7 +140,7 @@ impl PartialDecryptionKey<ThresholdPaillierPK> for ThresholdPaillierSK {
fn partial_decrypt_raw(
&self,
public_key: &ThresholdPaillierPK,
ciphertext: &ThresholdPaillierCiphertext,
ciphertext: &PaillierCiphertext,
) -> ThresholdPaillierShare {
let n_squared = Integer::from(public_key.modulus.square_ref());
ThresholdPaillierShare {
Expand Down Expand Up @@ -209,8 +206,6 @@ impl DecryptionShare<ThresholdPaillierPK> for ThresholdPaillierShare {
}
}

// TODO: Implement homomorphism / simply use standard PaillierCiphertexts

#[cfg(test)]
mod tests {
use crate::threshold_cryptosystems::paillier::{ThresholdPaillier, ThresholdPaillierShare};
Expand Down
4 changes: 2 additions & 2 deletions scicrypt-numbertheory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "scicrypt-numbertheory"
description = "A scicrypt crate implementing number theoretic algorithms such as random (safe) prime generation"
version = "0.5.0"
version = "0.6.0"
authors = ["Jelle Vos <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,7 +13,7 @@ readme = "README.md"
bench = false # Disable default bench (we use criterion)

[dependencies]
scicrypt-traits = { version = "0.5.0", path = "../scicrypt-traits" }
scicrypt-traits = { version = "0.6.0", path = "../scicrypt-traits" }
rug = "1.13"
rand_core = "0.6"

Expand Down
2 changes: 1 addition & 1 deletion scicrypt-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "scicrypt-traits"
description = "A scicrypt crate defining general traits for cryptographic systems and functionalities"
version = "0.5.0"
version = "0.6.0"
authors = ["Jelle Vos <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
1 change: 0 additions & 1 deletion scicrypt-traits/src/homomorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub trait HomomorphicMultiplication: EncryptionKey {
fn pow(&self, ciphertext: Self::Ciphertext, input: Self::Input) -> Self::Ciphertext;
}

// TODO: This leads to problems because PK::Plaintext can be AssociatedCiphertext<'pk, C, PK>
impl<'pk, C: Associable<PK>, PK: EncryptionKey<Ciphertext = C> + HomomorphicMultiplication> Mul
for AssociatedCiphertext<'pk, C, PK>
{
Expand Down
8 changes: 4 additions & 4 deletions scicrypt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "scicrypt"
description = "Lightweight cryptographic building blocks for proof of concept implementations in multi-party computation"
version = "0.5.0" # In sync with `scicrypt-traits`, `scicrypt-numbertheory`, and `scicrypt-he`
version = "0.6.0" # In sync with `scicrypt-traits`, `scicrypt-numbertheory`, and `scicrypt-he`
authors = ["Jelle Vos <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,9 +13,9 @@ readme = "README.md"
bench = false # Disable default bench (we use criterion)

[dependencies]
scicrypt-traits = { version = "0.5.0", path = "../scicrypt-traits" }
scicrypt-numbertheory = { version = "0.5.0", path = "../scicrypt-numbertheory" }
scicrypt-he = { version = "0.5.0", path = "../scicrypt-he" }
scicrypt-traits = { version = "0.6.0", path = "../scicrypt-traits" }
scicrypt-numbertheory = { version = "0.6.0", path = "../scicrypt-numbertheory" }
scicrypt-he = { version = "0.6.0", path = "../scicrypt-he" }

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "katex-header.html" ]

0 comments on commit d3dc0b6

Please sign in to comment.