SEAL icon indicating copy to clipboard operation
SEAL copied to clipboard

BGV/BFV inverse of p mod Q

Open wahyudierwin opened this issue 2 months ago • 2 comments

Hi,

I have a (perhaps dumb) question. In BGV or BFV, the plaintext modulus is p or p^r and Q represents the ciphertext modulus. Is there any function to compute p^{-1} mod Q? I was looking at try_invert_uint_mod (https://github.com/microsoft/SEAL/blob/main/native/src/seal/util/uintarithmod.cpp#L15) but it only supports uint64 values, while Q can go more than 64-bit.

Thanks!

wahyudierwin avatar Nov 08 '25 18:11 wahyudierwin

The function in uintarithmod.cpp supports integers modulo a multi-word modulus. There are some overloads that are for single-word moduli, and in fact they are used (almost) always. Actually, I'm not sure if the multi-word function you mentioned is used at all, because everything is done in CRT representation.

So, I'm not really sure what your question is. The function you pointed out takes uint64_count (the word count) as a parameter.

kimlaine avatar Nov 17 '25 19:11 kimlaine

Thanks for your response, @kimlaine . I just realized my question is ambiguous and confusing, my bad.

What I'm looking for is the ctxt.divideByP() function similar to HElib (https://github.com/homenc/HElib/blob/master/src/Ctxt.cpp#L2415). Is there any such function in SEAL?

wahyudierwin avatar Nov 17 '25 20:11 wahyudierwin