2

Can you please let me know how to compare two ciphertexts using the SEAL library?

I have two ciphertexts, C1 and C2 that were encoded using fractional encoder and then encrypted.

Is there a way to compare C1 and C2 for equality ? (C1 == C2 that returns boolean).

I have checked the ciphertext.h file and I was unable to find comparison sub-routines.

Something tells me that I can compare two ciphertexts by encoding them using BinaryEncoder and comparing bit by bit.

How could I go about implementing that?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Sep 06 '18 at 11:18

1 Answers1

2

There are a couple of options. First, you can indeed encrypt your message bit by bit and write a comparison circuit; this can be very inefficient from both running time and message expansion point of view. This is higher level functionality so it is not implemented as a part of SEAL.

Another possible approach is to encrypt your numbers as usual and compute their difference homomorphically. The result will then be either 0 (match) or non-zero (no match). This might not be useful for your needs though. In this case you can also use batching so in an amortized setting you can get good message expansion and performance.

You seem also a bit confused by BinaryEncoder; it doesn’t do anything like bit-wise encoding if that’s what you are after. You should take a look at the SEAL manual on http://sealcrypto.org and read the section about encoders.

Kim Laine
  • 856
  • 5
  • 10
  • Not meaning to sound combative, but it's important to note that subtracting two ciphertexts will result in a encrypted 0 or encrypted non-zero. So the system itself wouldn't be able to see if the two cipher texts are equal or not. Rather further logic would have to be implemented based on whether or not the result is 0 or non zero. And I don't think this is what the OP had in mind. – kebab-case Jun 08 '19 at 20:34