-
Notifications
You must be signed in to change notification settings - Fork 5
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
Compare #141
Conversation
pub mod compare; | ||
pub mod parameters; |
There was a problem hiding this comment.
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.
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; |
fhe_cmp/src/compare.rs
Outdated
use lattice::{LWE, NTTRGSW, RLWE}; | ||
use rand::prelude::*; | ||
|
||
///the structrue of Compare's input key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
///the structrue of Compare's input key | |
/// The structrue of Compare's input key |
fhe_cmp/src/compare.rs
Outdated
pub struct Compare<F: Field<Value = u64> + NTTField> { | ||
key: RLWEBlindRotationKey<F>, | ||
} |
There was a problem hiding this comment.
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
?
fhe_cmp/src/compare.rs
Outdated
///the implementation of Compare, including comparison of greater, equality and less | ||
impl<F: Field<Value = u64> + NTTField> Compare<F> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
///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> { |
fhe_cmp/src/compare.rs
Outdated
/// 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`. |
There was a problem hiding this comment.
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.
/// 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`. |
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>>) |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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.
fhe_cmp/src/compare.rs
Outdated
/// 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) | ||
} |
There was a problem hiding this comment.
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.
fhe_cmp/src/compare.rs
Outdated
pub fn decode<F: Field<Value = u64> + NTTField>(c: F) -> u64 { | ||
(c.value() as f64 * 16_f64 / 132120577_f64).round() as u64 % 16 | ||
} |
There was a problem hiding this comment.
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.
pub fn encrypt<F, R>( | ||
mut num1: usize, | ||
mut num2: usize, |
There was a problem hiding this comment.
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
.
No description provided.