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

What does (1i64 << 10) mean in dec_gsw? #31

Open
qxzhou1010 opened this issue Dec 26, 2023 · 3 comments
Open

What does (1i64 << 10) mean in dec_gsw? #31

qxzhou1010 opened this issue Dec 26, 2023 · 3 comments

Comments

@qxzhou1010
Copy link

In src/server.rs, there is a method called dec_gsw :

    fn dec_gsw<'a>(params: &'a Params, ct: &PolyMatrixNTT<'a>, client: &mut Client<'a>) -> u64 {
   
        let dec = client.decrypt_matrix_reg(ct).raw();
        
        // why need calculate this idx?
        let idx: usize = 2 * (params.t_gsw - 1) * params.poly_len + params.poly_len; // this offset should encode a large value
        let mut val = dec.data[idx] as i64;
        if val >= (params.modulus / 2) as i64 {
            println!("{} - {} = {}", val as i64, params.modulus as i64,  val - params.modulus as i64);
            val -= params.modulus as i64;
        }
        println!("params.modulus: {}", params.modulus as i64);
        println!("dec.data[{}]: {}, val: {}", idx, dec.data[idx], val);

        // why compared with 1i64 << 10? where is the 1i64 << 10 comes from?
        if i64::abs(val) < (1i64 << 10) {
            0
        } else {
            1
        }
    }

I have two questions:

  1. why need to calculate a idx? let idx: usize = 2 * (params.t_gsw - 1) * params.poly_len + params.poly_len;
  2. why compared with 1i64 << 10? where is the 1i64 << 10 comes from?
@praveenperera
Copy link

@qxzhou1010 1 << 10 is 1024, << is bitshift left operator, basically the same as 2^10.

@qxzhou1010
Copy link
Author

Thanks for your reply. Ok, I know this point. My question is that why use 2^10 here? why not use 2^8 or 2^5, or any other number ? What's the reference for using 2^10 here?

@qxzhou1010
Copy link
Author

One possible guess here is plaintext space. However, I found in the parameters of the code that the plaintext modulus (pt_modulus) is all 256.

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

No branches or pull requests

2 participants