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

Compare #141

Closed
wants to merge 102 commits into from
Closed

Compare #141

wants to merge 102 commits into from

Conversation

Arthur-hu-0806
Copy link
Collaborator

No description provided.

Comment on lines +1 to +2
pub mod compare;
pub mod parameters;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more comments of this implementation according to the paper.

Suggested change
pub mod compare;
pub mod parameters;
//! This is the implemenation of the alogirhtm in paper .. in page ...
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![deny(missing_docs)]
pub mod compare;
pub mod parameters;

use lattice::{LWE, NTTRGSW, RLWE};
use rand::prelude::*;

///the structrue of Compare's input key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///the structrue of Compare's input key
/// The structrue of Compare's input key

Comment on lines 10 to 12
pub struct Compare<F: Field<Value = u64> + NTTField> {
key: RLWEBlindRotationKey<F>,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use F: NTTField ?

Comment on lines 14 to 15
///the implementation of Compare, including comparison of greater, equality and less
impl<F: Field<Value = u64> + NTTField> Compare<F> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///the implementation of Compare, including comparison of greater, equality and less
impl<F: Field<Value = u64> + NTTField> Compare<F> {
/// The implementation of Compare, including comparison of greater, equality and less
impl<F: Field<Value = u64> + NTTField> Compare<F> {

Comment on lines 43 to 52
/// Performs the homomorphic and operation.
///
/// # Arguments
///
/// * Input: blind rotation key `self`.
/// * Input: LWE ciphertext `ca`, with message `a`.
/// * Input: LWE ciphertext `cb`, with message `b`.
/// * Input: the size of test vector `poly_length`.
/// * Input: encryption of 1 `delta`.
/// * Output: LWE ciphertext with message `a & b`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the following format for comments.

Suggested change
/// Performs the homomorphic and operation.
///
/// # Arguments
///
/// * Input: blind rotation key `self`.
/// * Input: LWE ciphertext `ca`, with message `a`.
/// * Input: LWE ciphertext `cb`, with message `b`.
/// * Input: the size of test vector `poly_length`.
/// * Input: encryption of 1 `delta`.
/// * Output: LWE ciphertext with message `a & b`.
/// Performs the homomorphic AND operation.
///
/// # Arguments
///
/// * `ca` - The LWE ciphertext, with message `a`.
/// * `cb` - The LWE ciphertext, with message `b`.
/// * `poly_length` - The size of test vector.
/// * `delta` - The encryption of 1.
/// * Output - LWE ciphertext with message `a & b`.

Comment on lines +260 to +268
pub fn encrypt<F, R>(
mut num1: usize,
mut num2: usize,
ntt_ring_secret_key: &NTTPolynomial<F>,
basis: Basis<F>,
delta: F,
error_sampler: FieldDiscreteGaussianSampler,
mut rng: R,
) -> (Vec<RLWE<F>>, Vec<NTTRGSW<F>>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of use two encryption algorithms to generate RLWE and RGSW ciphertexts seperately.
This is because the ciphertext is generated from different parties.

pub fn encrypt<F, R>(
mut num1: usize,
mut num2: usize,
ntt_ring_secret_key: &NTTPolynomial<F>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should hide this key into the struct.

Comment on lines 306 to 313
/// decryption for the ciphertext
pub fn decrypt<F: Field<Value = u64> + NTTField>(sk: &[F], ciphertext: LWE<F>) -> u64 {
let a_mul_s = sk
.iter()
.zip(ciphertext.a())
.fold(F::zero(), |acc, (&s, &a)| acc + s * a);
decode(ciphertext.b() - a_mul_s)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sk should be put into the struct.

Comment on lines 316 to 318
pub fn decode<F: Field<Value = u64> + NTTField>(c: F) -> u64 {
(c.value() as f64 * 16_f64 / 132120577_f64).round() as u64 % 16
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hardcode the values as constants, it should stored in the parameters, which should be stored in the struct.

Comment on lines +260 to +262
pub fn encrypt<F, R>(
mut num1: usize,
mut num2: usize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you only consider the case that the inputs are u64, we should also consider the case with inputs in u8, u16, u32, u64 and u128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants