3
$\begingroup$

I'm trying to use the Microsoft SEAL library in order to do Matrix multiplication. That's why I'm trying to find a way to compute the Dot Product of 2 vectors.

My issue is that the CKKS encoder in SEAL encodes entire vectors. So if I had a 2D vector of floats I get a 1D vector of Plaintext (and then a 1D vector of Ciphertext after encryption).

The operations that I am able to do are: addition, component-wise multiplication, exponential, and rotation. In order to do a dot product of vectors I need to multiply the components of the first vector by the components of the second vector and sum them up. If I want to multiply 2 matrices, I can transpose the second matrix and multiply the rows together but I am unable to compute the sum of the elements inside the Ciphertext. Is it possible to get the sum of those elements in the Ciphertext? Should I change my approach?

$\endgroup$
  • 1
    $\begingroup$ I don't understand.. Can you already do a homomorphic dot product? Because if you can do so, then you can of course multiply matrices. If you cannot, then what about using the rotation n-1 times to add all the components into the first entry? $\endgroup$ – Hilder Vitor Lima Pereira Feb 17 at 7:59
  • $\begingroup$ @HilderVitorLimaPereira No I cannot do a homomorphic dot product in SEAL. However you are correct, there was an issue on Github that was just answered that solved the issue with the method you proposed. $\endgroup$ – Marwan N Feb 17 at 13:32
2
$\begingroup$

As suggested by Hilder Vitor Lima Pereira in the comments and KyoohyungHan on Github in the issue https://github.com/microsoft/SEAL/issues/138, it is possible to sum the elements with rotations:

For example, {1, 2, 3, 4} is encrypted in a ciphertext. You can get encrypted {3, 4, 1, 2} using homomorphic rotation by index 2. With homomorphic addition, you have encrypted {4, 6, 4, 6}. After that, you can get encrypted {6, 4, 6, 4} using homomorphic rotation by index 1. Finally, you have encrypted {10, 10, 10, 10} with homomorphic addition which is the sum of the element in a ciphertext.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.