Inverting a Coefficient Packed Ciphertext

Hello,

I would like to know the most efficient way of inverting a coefficient-packed ciphertext using OpenFHE and BFVrns.

Thanks in advance :slight_smile:

Can you clarify what you mean by “inverting” in this context? An example would be useful.
Do you mean that if:
c = Enc(m_0, m_1, \ldots, m_{n-1}), then, Invert(c) = Enc(m_{n-1}, m_{n-2}, \ldots, m_{0})
?

Oh yeah, sorry for the lack of examples. It is precisely what you describe.

You can use the GetCoefPackedValue function on a plaintext. See the UnitTest_Add_Packed test for an example.

The problem is I need it to be done on the ciphertext, so I can’t decrypt, invert and then encrypt again,

Can you tell us more about your use case? Why not use the Packed Encoding instead of the Coef Packed Encoding?

I’m implementing the Inner Product between two vectors. With Coef Packed Encoding, I need to do one multiplication if the second vector is inverted, while with Packed Encoding, I need to do a lot of rotations and summations.

That’s why I’m asking If there is a way to invert ciphertexts because right now, If I want to calculate the inner product of a vector X with himself, I have to encrypt it twice.

I hope this was helpful :slight_smile: If not please ask more questions

@Bernardo_Ramalho Just to confirm, you are trying to use a technique like the one described in Secret computation of purchase history data using somewhat homomorphic encryption | Pacific Journal of Mathematics for Industry | Full Text You want to be able to apply the second packing in Definition 2 homomorphically rather than encrypt the ciphertext (twice) using two different packing techniques. Correct?

Exactly.

What I’m doing right now is:

I start with two vectors containing the same n values. I invert one of them and then encrypt them using Coefficient Packing into two ciphertexts, c and c’. I then multiply c with c’ and, due to how polynomial multiplication works, at index n, I get the value of the inner product of c with itself.

I want to do the inversion part homomorphically so that I don’t have to encrypt twice.

Hi @Bernardo_Ramalho

Doing this homomorphically for the Coeff Packed encoding is quite challenging.

First, I will describe a simpler option using regular (CRT) Packed Encoding. The inversion of slots there can be done by multiplying the encrypted vector by a permutation matrix of the form {{0,0,1},{0,1,0},{1,0,0}} (for the case of a vector with 3 elements). However, one cannot use it for a multiplication in a CoeffPacked representation unless homomorphic decoding is called after this (it is a relatively expensive subroutine used in CKKS bootstrapping).

Second option is to convert an RLWE ciphertext with n coefficients into n LWE ciphertexts, rearrange the LWE ciphertexts in the clear, and then build a new RLWE ciphertext from the LWE ciphertexts. This is also not cheap.

There are other options, but I cannot think of anything more efficient at the moment.

Both options are not available through the API exposed in OpenFHE, although all the subroutines for the first approach are already implemented in OpenFHE. The subroutines for the second approach will be added in v1.1 (as part of the scheme switching capability).

In summary, encrypting twice is a much cheaper option :slight_smile: