mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-10 15:18:33 -05:00
chore(tfhe): remove useless comments
This commit is contained in:
@@ -253,7 +253,6 @@ cks1 has {choice1:?}, cks2 has: {choice2:?}
|
||||
),
|
||||
};
|
||||
|
||||
// encryption
|
||||
let ct = allocate_and_encrypt_new_lwe_ciphertext(
|
||||
&lwe_sk,
|
||||
plain,
|
||||
@@ -284,7 +283,6 @@ cks1 has {choice1:?}, cks2 has: {choice2:?}
|
||||
),
|
||||
};
|
||||
|
||||
// encryption
|
||||
let ct = allocate_and_encrypt_new_seeded_lwe_ciphertext(
|
||||
&lwe_sk,
|
||||
plain,
|
||||
@@ -310,7 +308,6 @@ cks1 has {choice1:?}, cks2 has: {choice2:?}
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
// encryption
|
||||
encrypt_lwe_ciphertext_with_public_key(
|
||||
&pks.lwe_public_key,
|
||||
&mut output,
|
||||
@@ -356,7 +353,6 @@ cks1 has {choice1:?}, cks2 has: {choice2:?}
|
||||
EncryptionKeyChoice::Small => cks.lwe_secret_key.as_view(),
|
||||
};
|
||||
|
||||
// decryption
|
||||
let decrypted = decrypt_lwe_ciphertext(&lwe_sk, ciphertext);
|
||||
|
||||
// cast as a u32
|
||||
|
||||
@@ -262,35 +262,25 @@ fn test_encrypt_decrypt_lwe_secret_key(parameters: BooleanParameters) {
|
||||
let (cks, sks) = (keys.client_key(), keys.server_key());
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
// encryption of false
|
||||
let ct_false = cks.encrypt(false);
|
||||
|
||||
// encryption of true
|
||||
let ct_true = cks.encrypt(true);
|
||||
|
||||
// decryption of false
|
||||
let dec_false = cks.decrypt(&ct_false);
|
||||
|
||||
// decryption of true
|
||||
let dec_true = cks.decrypt(&ct_true);
|
||||
|
||||
// assert
|
||||
assert!(!dec_false);
|
||||
assert!(dec_true);
|
||||
|
||||
// encryption of false
|
||||
let ct_false = sks.trivial_encrypt(false);
|
||||
|
||||
// encryption of true
|
||||
let ct_true = sks.trivial_encrypt(true);
|
||||
|
||||
// decryption of false
|
||||
let dec_false = cks.decrypt(&ct_false);
|
||||
|
||||
// decryption of true
|
||||
let dec_true = cks.decrypt(&ct_true);
|
||||
|
||||
// assert
|
||||
assert!(!dec_false);
|
||||
assert!(dec_true);
|
||||
}
|
||||
@@ -316,67 +306,53 @@ fn test_and_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = b1 && b2;
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// AND gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let ct_res = sks.and(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// AND gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.and(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// AND gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.and(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// AND gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.and_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// AND gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.and_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// AND gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.and_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_and = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_and, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
@@ -392,22 +368,17 @@ fn test_mux_gate(parameters: BooleanParameters) {
|
||||
let b3 = random_boolean();
|
||||
let expected_result = if b1 { b2 } else { b3 };
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// encryption of b3
|
||||
let ct3 = random_enum_encryption(cks, sks, b3);
|
||||
|
||||
// MUX gate
|
||||
let ct_res = sks.mux(&ct1, &ct2, &ct3);
|
||||
|
||||
// decryption
|
||||
let dec_mux = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
expected_result, dec_mux,
|
||||
"cond: {ct1:?}, then: {ct2:?}, else: {ct3:?}"
|
||||
@@ -425,67 +396,53 @@ fn test_nand_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = !(b1 && b2);
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// NAND gate -> left: Ciphertext, right: Ciphertext
|
||||
let ct_res = sks.nand(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// NAND gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.nand(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// NAND gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.nand(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// NAND gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.nand_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// NAND gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.nand_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// NAND gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.nand_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_nand = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nand, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
@@ -500,67 +457,53 @@ fn test_nor_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = !(b1 || b2);
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// NOR gate -> left: Ciphertext, right: Ciphertext
|
||||
let ct_res = sks.nor(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// NOR gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.nor(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// NOR gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.nor(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// NOR gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.nor_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// NOR gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.nor_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// NOR gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.nor_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_nor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_nor, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
@@ -574,26 +517,21 @@ fn test_not_gate(parameters: BooleanParameters) {
|
||||
let b1 = random_boolean();
|
||||
let expected_result = !b1;
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// NOT gate
|
||||
let ct_res = sks.not(&ct1);
|
||||
|
||||
// decryption
|
||||
let dec_not = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_not);
|
||||
|
||||
// NOT gate
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.not_assign(&mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_not = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_not);
|
||||
}
|
||||
}
|
||||
@@ -608,67 +546,53 @@ fn test_or_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = b1 || b2;
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// OR gate -> left: Ciphertext, right: Ciphertext
|
||||
let ct_res = sks.or(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// OR gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.or(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// OR gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.or(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// OR gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.or_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// OR gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.or_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// OR gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.or_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_or = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_or, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
@@ -683,67 +607,53 @@ fn test_xnor_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = b1 == b2;
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// XNOR gate -> left: Ciphertext, right: Ciphertext
|
||||
let ct_res = sks.xnor(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// XNOR gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.xnor(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// XNOR gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.xnor(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// XNOR gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.xnor_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// XNOR gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.xnor_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// XNOR gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.xnor_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_xnor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xnor, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
@@ -758,67 +668,53 @@ fn test_xor_gate(parameters: BooleanParameters) {
|
||||
let b2 = random_boolean();
|
||||
let expected_result = b1 ^ b2;
|
||||
|
||||
// encryption of b1
|
||||
let ct1 = random_enum_encryption(cks, sks, b1);
|
||||
|
||||
// encryption of b2
|
||||
let ct2 = random_enum_encryption(cks, sks, b2);
|
||||
|
||||
// XOR gate -> left: Ciphertext, right: Ciphertext
|
||||
let ct_res = sks.xor(&ct1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// XOR gate -> left: Ciphertext, right: bool
|
||||
let ct_res = sks.xor(&ct1, b2);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// XOR gate -> left: bool, right: Ciphertext
|
||||
let ct_res = sks.xor(b1, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {b1:?}, right: {ct2:?}");
|
||||
|
||||
// XOR gate -> "left: {:?}, right: {:?}",ct1, ct2
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.xor_assign(&mut ct_res, &ct2);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {ct1:?}, right: {ct2:?}");
|
||||
|
||||
// XOR gate -> left: Ciphertext, right: bool
|
||||
let mut ct_res = ct1.clone();
|
||||
sks.xor_assign(&mut ct_res, b2);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {ct1:?}, right: {b2:?}");
|
||||
|
||||
// XOR gate -> left: bool, right: Ciphertext
|
||||
let mut ct_res = ct2.clone();
|
||||
sks.xor_assign(b1, &mut ct_res);
|
||||
|
||||
// decryption
|
||||
let dec_xor = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(expected_result, dec_xor, "left: {b1:?}, right: {ct2:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +328,6 @@ fn test_circuit_bootstrapping_binary() {
|
||||
for _ in 0..NB_TESTS {
|
||||
// value is 0 or 1 as CBS works on messages expected to contain 1 bit of information
|
||||
let value: u64 = test_tools::random_uint_between(0..2u64);
|
||||
// Encryption of an LWE with the value 'message'
|
||||
let message = Plaintext((value) << delta_log.0);
|
||||
let mut lwe_in =
|
||||
LweCiphertextOwned::new(0u64, small_lwe_dimension.to_lwe_size(), ciphertext_modulus);
|
||||
|
||||
@@ -197,7 +197,6 @@ impl ClientKey {
|
||||
/// // 2 * 4 = 8 bits of message
|
||||
/// let ct = cks.encrypt_radix(msg, num_block);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt_radix(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
@@ -224,7 +223,6 @@ impl ClientKey {
|
||||
/// // 2 * 4 = 8 bits of message
|
||||
/// let ct = cks.encrypt_radix_without_padding(msg, num_block);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt_radix_without_padding(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
@@ -297,10 +295,8 @@ impl ClientKey {
|
||||
///
|
||||
/// let msg = 191_u64;
|
||||
///
|
||||
/// // Encryption
|
||||
/// let ct = cks.encrypt_radix(msg, num_block);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt_radix(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
@@ -327,10 +323,8 @@ impl ClientKey {
|
||||
///
|
||||
/// let msg = 191_u64;
|
||||
///
|
||||
/// // Encryption
|
||||
/// let ct = cks.encrypt_radix_without_padding(msg, num_block);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt_radix_without_padding(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
@@ -476,10 +470,8 @@ impl ClientKey {
|
||||
///
|
||||
/// let msg = 2_u64;
|
||||
///
|
||||
/// // Encryption
|
||||
/// let ct = cks.encrypt_one_block(msg);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt_one_block(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
|
||||
@@ -27,7 +27,6 @@ use serde::{Deserialize, Serialize};
|
||||
///
|
||||
/// let ct = cks.encrypt(msg);
|
||||
///
|
||||
/// // Decryption
|
||||
/// let dec = cks.decrypt(&ct);
|
||||
/// assert_eq!(msg, dec);
|
||||
/// ```
|
||||
|
||||
@@ -97,7 +97,6 @@ where
|
||||
|
||||
// Put each decomposition into a new ciphertext
|
||||
for modulus in base_vec.iter().copied() {
|
||||
// encryption
|
||||
let ct = encrypt_block(encrypting_key, message, MessageModulus(modulus as usize));
|
||||
|
||||
ctxt_vect.push(ct);
|
||||
|
||||
@@ -341,7 +341,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -392,7 +391,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -442,7 +440,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -483,7 +480,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -524,7 +520,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -564,7 +559,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -605,7 +599,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -651,7 +644,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -697,7 +689,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -755,7 +746,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -814,7 +804,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -873,7 +862,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -932,7 +920,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -973,7 +960,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1014,7 +1000,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1094,7 +1079,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1172,7 +1156,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1223,7 +1206,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1274,7 +1256,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1325,7 +1306,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1366,7 +1346,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1407,7 +1386,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1447,7 +1425,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1488,7 +1465,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1534,7 +1510,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1580,7 +1555,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1619,7 +1593,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1658,7 +1631,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1697,7 +1669,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1784,7 +1755,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1827,7 +1797,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1868,7 +1837,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1909,7 +1877,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1948,7 +1915,6 @@ where
|
||||
|
||||
let (cks, sks) = gen_keys_gpu(param, &stream);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
|
||||
@@ -62,19 +62,15 @@ fn big_radix_encrypt_decrypt_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let public_key = PublicKey::new(&cks);
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let clear = rng.gen::<u128>();
|
||||
|
||||
//encryption
|
||||
let ct = public_key.encrypt_radix(clear, num_block);
|
||||
|
||||
// decryption
|
||||
let dec: u128 = cks.decrypt_radix(&ct);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec);
|
||||
}
|
||||
|
||||
@@ -82,19 +78,15 @@ fn radix_encrypt_decrypt_compressed_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let public_key = CompressedPublicKey::new(&cks);
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let clear = rng.gen::<u128>();
|
||||
|
||||
//encryption
|
||||
let ct = public_key.encrypt_radix(clear, num_block);
|
||||
|
||||
// decryption
|
||||
let dec: u128 = cks.decrypt_radix(&ct);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,16 +61,13 @@ fn integer_unchecked_crt_add_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_add(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 + clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -92,16 +89,13 @@ fn integer_unchecked_crt_mul_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_mul(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 * clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -122,15 +116,12 @@ fn integer_unchecked_crt_neg_32_bits() {
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_neg(&ct_zero);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!((modulus - clear_0) as u64, dec_res % modulus as u64);
|
||||
}
|
||||
}
|
||||
@@ -149,16 +140,13 @@ fn integer_unchecked_crt_sub_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_sub(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((modulus + clear_0 - clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -180,15 +168,12 @@ fn integer_unchecked_crt_scalar_add_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_add(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 + clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -210,15 +195,12 @@ fn integer_unchecked_crt_scalar_mul_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_mul(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 * clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -240,15 +222,12 @@ fn integer_unchecked_crt_scalar_sub_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_sub(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((modulus + clear_0 - clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -260,7 +239,6 @@ fn integer_unchecked_crt_mul(param: ClassicPBSParameters) {
|
||||
// generate the server-client key set
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// Define CRT basis, and global modulus
|
||||
@@ -271,17 +249,14 @@ fn integer_unchecked_crt_mul(param: ClassicPBSParameters) {
|
||||
let clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
let ct_one = cks.encrypt_crt(clear_1, basis.clone());
|
||||
|
||||
// add the two ciphertexts
|
||||
sks.unchecked_crt_mul_assign(&mut ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear_0 * clear_1) % modulus, dec_res % modulus);
|
||||
}
|
||||
}
|
||||
@@ -293,13 +268,11 @@ fn integer_smart_crt_add(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
let mut ct_one = cks.encrypt_crt(clear_1, basis);
|
||||
|
||||
@@ -307,10 +280,8 @@ fn integer_smart_crt_add(param: ClassicPBSParameters) {
|
||||
// add the two ciphertexts
|
||||
sks.smart_crt_add_assign(&mut ct_zero, &mut ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// assert
|
||||
clear_0 += clear_1;
|
||||
assert_eq!(clear_0 % modulus, dec_res % modulus);
|
||||
}
|
||||
@@ -326,13 +297,11 @@ fn integer_smart_crt_mul(param: ClassicPBSParameters) {
|
||||
|
||||
println!("BASIS = {basis:?}");
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
let mut ct_one = cks.encrypt_crt(clear_1, basis);
|
||||
|
||||
@@ -340,7 +309,6 @@ fn integer_smart_crt_mul(param: ClassicPBSParameters) {
|
||||
// mul the two ciphertexts
|
||||
sks.smart_crt_mul_assign(&mut ct_zero, &mut ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
clear_0 = (clear_0 * clear_1) % modulus;
|
||||
@@ -355,25 +323,21 @@ fn integer_smart_crt_neg(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut clear_0 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
// add the two ciphertexts
|
||||
sks.smart_crt_neg_assign(&mut ct_zero);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
clear_0 = (modulus - clear_0) % modulus;
|
||||
|
||||
// println!("clear = {}", clear_0);
|
||||
// assert
|
||||
assert_eq!(clear_0, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -385,23 +349,19 @@ fn integer_smart_crt_scalar_add(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
|
||||
// add the two ciphertexts
|
||||
sks.smart_crt_scalar_add_assign(&mut ct_zero, clear_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear_0 + clear_1) % modulus, dec_res % modulus);
|
||||
}
|
||||
}
|
||||
@@ -413,23 +373,19 @@ fn integer_smart_crt_scalar_mul(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
|
||||
// add the two ciphertexts
|
||||
sks.smart_crt_scalar_mul_assign(&mut ct_zero, clear_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear_0 * clear_1) % modulus, dec_res % modulus);
|
||||
}
|
||||
}
|
||||
@@ -441,25 +397,21 @@ fn integer_smart_crt_scalar_sub(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
// add the two ciphertexts
|
||||
sks.smart_crt_scalar_sub_assign(&mut ct_zero, clear_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// println!("clear_0 = {}, clear_1 = {}, modulus = {}", clear_0, clear_1, modulus);
|
||||
|
||||
// assert
|
||||
clear_0 = (clear_0 + modulus - clear_1) % modulus;
|
||||
assert_eq!(clear_0, dec_res % modulus);
|
||||
}
|
||||
@@ -472,13 +424,11 @@ fn integer_smart_crt_sub(param: ClassicPBSParameters) {
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct_zero = cks.encrypt_crt(clear_0, basis.clone());
|
||||
let mut ct_one = cks.encrypt_crt(clear_1, basis);
|
||||
|
||||
@@ -486,12 +436,10 @@ fn integer_smart_crt_sub(param: ClassicPBSParameters) {
|
||||
// sub the two ciphertexts
|
||||
sks.smart_crt_sub_assign(&mut ct_zero, &mut ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_zero);
|
||||
|
||||
// println!("clear_0 = {}, clear_1 = {}, modulus = {}", clear_0, clear_1, modulus);
|
||||
|
||||
// assert
|
||||
clear_0 = (clear_0 + modulus - clear_1) % modulus;
|
||||
assert_eq!(clear_0, dec_res);
|
||||
}
|
||||
|
||||
@@ -32,16 +32,13 @@ fn integer_unchecked_crt_add_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_add_parallelized(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 + clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -63,17 +60,14 @@ fn integer_unchecked_crt_mul_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
// multiply the two ciphertexts
|
||||
let ct_res = sks.unchecked_crt_mul_parallelized(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 * clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -94,15 +88,12 @@ fn integer_unchecked_crt_neg_parallelized_32_bits() {
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_neg_parallelized(&ct_zero);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!((modulus - clear_0) as u64, dec_res % modulus as u64);
|
||||
}
|
||||
}
|
||||
@@ -121,16 +112,13 @@ fn integer_unchecked_crt_sub_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
let ct_one = cks.encrypt_crt(clear_1 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_sub_parallelized(&ct_zero, &ct_one);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((modulus + clear_0 - clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -152,15 +140,12 @@ fn integer_unchecked_crt_scalar_add_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_add_parallelized(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 + clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -182,15 +167,12 @@ fn integer_unchecked_crt_scalar_mul_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_mul_parallelized(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((clear_0 * clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
@@ -212,15 +194,12 @@ fn integer_unchecked_crt_scalar_sub_parallelized_32_bits() {
|
||||
let clear_0 = rng.gen::<u128>() % modulus;
|
||||
let clear_1 = rng.gen::<u128>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_crt(clear_0 as u64, basis.to_vec());
|
||||
|
||||
let ct_res = sks.unchecked_crt_scalar_sub_parallelized(&ct_zero, clear_1 as u64);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_crt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
((modulus + clear_0 - clear_1) % modulus) as u64,
|
||||
dec_res % modulus as u64
|
||||
|
||||
@@ -167,10 +167,8 @@ fn integer_encrypt_decrypt_128_bits_specific_values(param: ClassicPBSParameters)
|
||||
let mut ct2 = cks.encrypt_radix(clear_1, num_block);
|
||||
let ct = sks.smart_add(&mut ct, &mut ct2);
|
||||
|
||||
// decryption
|
||||
let dec: u128 = cks.decrypt_radix(&ct);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_0.wrapping_add(clear_1), dec);
|
||||
}
|
||||
|
||||
@@ -182,10 +180,8 @@ fn integer_encrypt_decrypt_128_bits_specific_values(param: ClassicPBSParameters)
|
||||
let mut ct2 = cks.encrypt_radix(clear_1, num_block);
|
||||
let ct = sks.smart_add(&mut ct, &mut ct2);
|
||||
|
||||
// decryption
|
||||
let dec: u128 = cks.decrypt_radix(&ct);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_0.wrapping_add(clear_1), dec);
|
||||
}
|
||||
}
|
||||
@@ -217,7 +213,6 @@ fn integer_encrypt_decrypt_256_bits_specific_values(param: ClassicPBSParameters)
|
||||
fn integer_encrypt_decrypt_256_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = (256f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
@@ -227,13 +222,10 @@ fn integer_encrypt_decrypt_256_bits(param: ClassicPBSParameters) {
|
||||
|
||||
let clear = crate::integer::U256::from((clear0, clear1));
|
||||
|
||||
//encryption
|
||||
let ct = cks.encrypt_radix(clear, num_block);
|
||||
|
||||
// decryption
|
||||
let dec: U256 = cks.decrypt_radix(&ct);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec);
|
||||
}
|
||||
}
|
||||
@@ -251,10 +243,8 @@ fn integer_smart_add_128_bits(param: ClassicPBSParameters) {
|
||||
|
||||
println!("{clear_0} {clear_1}");
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, num_block);
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_1 = cks.encrypt_radix(clear_1, num_block);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -268,7 +258,6 @@ fn integer_smart_add_128_bits(param: ClassicPBSParameters) {
|
||||
ct_res = sks.smart_add(&mut ct_res, &mut ctxt_0);
|
||||
clear_result += clear_0;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u128 = cks.decrypt_radix(&ct_res);
|
||||
// println!("clear = {}, dec_res = {}", clear, dec_res);
|
||||
assert_eq!(clear_result, dec_res);
|
||||
@@ -289,7 +278,6 @@ fn integer_smart_add(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_bitand(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -300,19 +288,15 @@ fn integer_unchecked_bitand(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.unchecked_bitand(&ctxt_0, &ctxt_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_0 & clear_1, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -320,7 +304,6 @@ fn integer_unchecked_bitand(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_bitor(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -331,19 +314,15 @@ fn integer_unchecked_bitor(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.unchecked_bitor(&ctxt_0, &ctxt_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_0 | clear_1, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -351,7 +330,6 @@ fn integer_unchecked_bitor(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_bitxor(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -362,19 +340,15 @@ fn integer_unchecked_bitxor(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.unchecked_bitxor(&ctxt_0, &ctxt_1);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_0 ^ clear_1, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -382,7 +356,6 @@ fn integer_unchecked_bitxor(param: ClassicPBSParameters) {
|
||||
fn integer_smart_bitand(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -395,10 +368,8 @@ fn integer_smart_bitand(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -409,16 +380,13 @@ fn integer_smart_bitand(param: ClassicPBSParameters) {
|
||||
for _ in 0..NB_TESTS_SMALLER {
|
||||
let clear_2 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_2 = cks.encrypt_radix(clear_2, NB_CTXT);
|
||||
|
||||
ct_res = sks.smart_bitand(&mut ct_res, &mut ctxt_2);
|
||||
clear &= clear_2;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -427,7 +395,6 @@ fn integer_smart_bitand(param: ClassicPBSParameters) {
|
||||
fn integer_smart_bitor(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -440,10 +407,8 @@ fn integer_smart_bitor(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -454,16 +419,13 @@ fn integer_smart_bitor(param: ClassicPBSParameters) {
|
||||
for _ in 0..1 {
|
||||
let clear_2 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_2 = cks.encrypt_radix(clear_2, NB_CTXT);
|
||||
|
||||
ct_res = sks.smart_bitor(&mut ct_res, &mut ctxt_2);
|
||||
clear = (clear | clear_2) % modulus;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -472,7 +434,6 @@ fn integer_smart_bitor(param: ClassicPBSParameters) {
|
||||
fn integer_smart_bitxor(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -485,10 +446,8 @@ fn integer_smart_bitxor(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_1 = cks.encrypt_radix(clear_1, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -499,16 +458,13 @@ fn integer_smart_bitxor(param: ClassicPBSParameters) {
|
||||
for _ in 0..NB_TESTS_SMALLER {
|
||||
let clear_2 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_2 = cks.encrypt_radix(clear_2, NB_CTXT);
|
||||
|
||||
ct_res = sks.smart_bitxor(&mut ct_res, &mut ctxt_2);
|
||||
clear = (clear ^ clear_2) % modulus;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -517,7 +473,6 @@ fn integer_smart_bitxor(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -530,16 +485,13 @@ fn integer_unchecked_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
|
||||
let scalar = rng.gen::<u64>() % scalar_modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct = cks.encrypt_radix(clear, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.unchecked_small_scalar_mul(&ct, scalar);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear * scalar) % modulus, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -547,7 +499,6 @@ fn integer_unchecked_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
fn integer_smart_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -561,7 +512,6 @@ fn integer_smart_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
|
||||
let scalar = rng.gen::<u64>() % scalar_modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct = cks.encrypt_radix(clear, NB_CTXT);
|
||||
|
||||
let mut ct_res = sks.smart_small_scalar_mul(&mut ct, scalar);
|
||||
@@ -573,10 +523,8 @@ fn integer_smart_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
clear_res *= scalar;
|
||||
}
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear_res % modulus, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -584,7 +532,6 @@ fn integer_smart_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
fn integer_blockshift(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -595,16 +542,13 @@ fn integer_blockshift(param: ClassicPBSParameters) {
|
||||
|
||||
let power = rng.gen::<u64>() % NB_CTXT as u64;
|
||||
|
||||
// encryption of an integer
|
||||
let ct = cks.encrypt_radix(clear, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.blockshift(&ct, power as usize);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
(clear * param.message_modulus.0.pow(power as u32) as u64) % modulus,
|
||||
dec_res
|
||||
@@ -615,7 +559,6 @@ fn integer_blockshift(param: ClassicPBSParameters) {
|
||||
fn integer_blockshift_right(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -626,16 +569,13 @@ fn integer_blockshift_right(param: ClassicPBSParameters) {
|
||||
|
||||
let power = rng.gen::<u64>() % NB_CTXT as u64;
|
||||
|
||||
// encryption of an integer
|
||||
let ct = cks.encrypt_radix(clear, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.blockshift_right(&ct, power as usize);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(
|
||||
(clear / param.message_modulus.0.pow(power as u32) as u64) % modulus,
|
||||
dec_res
|
||||
@@ -646,7 +586,6 @@ fn integer_blockshift_right(param: ClassicPBSParameters) {
|
||||
fn integer_smart_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -657,16 +596,13 @@ fn integer_smart_scalar_mul(param: ClassicPBSParameters) {
|
||||
|
||||
let scalar = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ct = cks.encrypt_radix(clear, NB_CTXT);
|
||||
|
||||
// scalar mul
|
||||
let ct_res = sks.smart_scalar_mul(&mut ct, scalar);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear * scalar) % modulus, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -708,7 +644,6 @@ fn integer_unchecked_scalar_left_shift(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_scalar_right_shift(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -769,7 +704,6 @@ fn integer_smart_sub(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_block_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -782,19 +716,15 @@ fn integer_unchecked_block_mul(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % block_modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ct_zero = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// encryption of an integer
|
||||
let ct_one = cks.encrypt_one_block(clear_1);
|
||||
|
||||
// add the two ciphertexts
|
||||
let ct_res = sks.unchecked_block_mul(&ct_zero, &ct_one, 0);
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!((clear_0 * clear_1) % modulus, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -802,7 +732,6 @@ fn integer_unchecked_block_mul(param: ClassicPBSParameters) {
|
||||
fn integer_smart_block_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -839,7 +768,6 @@ fn integer_smart_block_mul(param: ClassicPBSParameters) {
|
||||
fn integer_unchecked_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -868,7 +796,6 @@ fn integer_unchecked_mul(param: ClassicPBSParameters) {
|
||||
fn integer_smart_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -919,7 +846,6 @@ fn integer_smart_scalar_add(param: ClassicPBSParameters) {
|
||||
|
||||
let mut clear;
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..NB_TESTS_SMALLER {
|
||||
@@ -927,7 +853,6 @@ fn integer_smart_scalar_add(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -941,11 +866,9 @@ fn integer_smart_scalar_add(param: ClassicPBSParameters) {
|
||||
ct_res = sks.smart_scalar_add(&mut ct_res, clear_1);
|
||||
clear = (clear + clear_1) % modulus;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// println!("clear = {}, dec_res = {}", clear, dec_res);
|
||||
// assert
|
||||
assert_eq!(clear, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -968,7 +891,6 @@ fn integer_smart_scalar_sub(param: ClassicPBSParameters) {
|
||||
|
||||
let mut clear;
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..NB_TESTS_SMALLER {
|
||||
@@ -976,7 +898,6 @@ fn integer_smart_scalar_sub(param: ClassicPBSParameters) {
|
||||
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let mut ctxt_0 = cks.encrypt_radix(clear_0, NB_CTXT);
|
||||
|
||||
// add the two ciphertexts
|
||||
@@ -990,11 +911,9 @@ fn integer_smart_scalar_sub(param: ClassicPBSParameters) {
|
||||
ct_res = sks.smart_scalar_sub(&mut ct_res, clear_1);
|
||||
clear = (clear - clear_1) % modulus;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
// println!("clear = {}, dec_res = {}", clear, dec_res);
|
||||
// assert
|
||||
assert_eq!(clear, dec_res);
|
||||
}
|
||||
}
|
||||
@@ -1019,7 +938,6 @@ fn integer_unchecked_scalar_decomposition_overflow(param: ClassicPBSParameters)
|
||||
let ct_0 = cks.encrypt_radix(clear_0, num_block);
|
||||
|
||||
let ct_res = sks.unchecked_scalar_add(&ct_0, scalar);
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt_radix(&ct_res);
|
||||
|
||||
assert_eq!((clear_0 + scalar as u128), dec_res);
|
||||
@@ -1044,7 +962,6 @@ fn integer_smart_scalar_mul_decomposition_overflow() {
|
||||
// Since smart_scalar_mul is a slow operation, we test against only one parameters set.
|
||||
// If overflow occurs the test case will panic.
|
||||
|
||||
// RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let param = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
@@ -1440,7 +1440,6 @@ where
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1452,7 +1451,6 @@ where
|
||||
.map(|_| rng.gen::<u64>() % modulus)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// encryption of integers
|
||||
let ctxts = clears
|
||||
.iter()
|
||||
.copied()
|
||||
@@ -1498,7 +1496,6 @@ where
|
||||
.map(|_| rng.gen::<u64>() % modulus)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// encryption of integers
|
||||
let ctxts = clears
|
||||
.iter()
|
||||
.copied()
|
||||
@@ -1735,7 +1732,6 @@ where
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1768,7 +1764,6 @@ where
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1813,7 +1808,6 @@ where
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -1857,7 +1851,6 @@ where
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -2378,7 +2371,6 @@ where
|
||||
let clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_0 = cks.encrypt(clear_0);
|
||||
|
||||
let mut ct_res = executor.execute((&ctxt_0, clear_1));
|
||||
@@ -2822,7 +2814,6 @@ where
|
||||
sks.set_deterministic_pbs_execution(true);
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -2913,7 +2904,6 @@ where
|
||||
let clear_0 = rng.gen::<u64>() % modulus;
|
||||
let clear_1 = rng.gen::<u64>() % modulus;
|
||||
|
||||
// encryption of an integer
|
||||
let ctxt_0 = cks.encrypt(clear_0);
|
||||
|
||||
// Do with a small clear to check the way we avoid
|
||||
@@ -3651,7 +3641,6 @@ where
|
||||
));
|
||||
let sks = Arc::new(sks);
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
@@ -3670,7 +3659,6 @@ where
|
||||
.map(|_| rng.gen::<u64>() % modulus)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// encryption of integers
|
||||
let ctxts = clears
|
||||
.iter()
|
||||
.copied()
|
||||
|
||||
@@ -887,7 +887,6 @@ where
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let cks = RadixClientKey::from((cks, NB_CTXT));
|
||||
|
||||
//RNG
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
|
||||
@@ -213,7 +213,6 @@ impl ShortintEngine {
|
||||
public_key.lwe_public_key.ciphertext_modulus(),
|
||||
);
|
||||
|
||||
// encryption
|
||||
encrypt_lwe_ciphertext_with_seeded_public_key(
|
||||
&public_key.lwe_public_key,
|
||||
&mut encrypted_ct,
|
||||
@@ -253,7 +252,6 @@ impl ShortintEngine {
|
||||
public_key.lwe_public_key.ciphertext_modulus(),
|
||||
);
|
||||
|
||||
// encryption
|
||||
encrypt_lwe_ciphertext_with_public_key(
|
||||
&public_key.lwe_public_key,
|
||||
&mut encrypted_ct,
|
||||
@@ -293,7 +291,6 @@ impl ShortintEngine {
|
||||
public_key.lwe_public_key.ciphertext_modulus(),
|
||||
);
|
||||
|
||||
// encryption
|
||||
encrypt_lwe_ciphertext_with_seeded_public_key(
|
||||
&public_key.lwe_public_key,
|
||||
&mut encrypted_ct,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -152,10 +152,8 @@ fn shortint_compact_public_key_base_smart_add(params: ClassicPBSParameters) {
|
||||
sks.smart_add_assign(&mut ct_res, &mut ctxt_0);
|
||||
clear += clear_0;
|
||||
|
||||
// decryption of ct_res
|
||||
let dec_res = cks.decrypt(&ct_res);
|
||||
|
||||
// assert
|
||||
assert_eq!(clear % modulus, dec_res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user