microsoft / SEAL

Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.
https://www.microsoft.com/en-us/research/group/cryptography-research/
MIT License
3.62k stars 709 forks source link

Error in constructor of Microsoft seal PlainText when string is to long. #577

Closed adolfommoyano closed 2 years ago

adolfommoyano commented 2 years ago

Hi,

I need to sum a cyphertext with a 256 bit number (256Big in my code). As the Plaintext only accepts an hexadecimal string parameter I am trying the following:

string stringSUM= 256Big.ToString("X64"); -> conversion is correct
Plaintext keyLevelPlain = new Plaintext(keyString);

Output:

Unhandled exception. System.ArgumentException: Value does not fall within the expected 
range.
   at Microsoft.Research.SEAL.NativeMethods.Plaintext_Create4(String hexPoly, IntPtr memoryPoolHandle, IntPtr& plainText)
   at Microsoft.Research.SEAL.Plaintext..ctor(String hexPoly, MemoryPoolHandle pool) 

Any solutions?

Thanks in advice

kimlaine commented 2 years ago

What does your encoding (stringSUM) look like exactly? Can you show a small example? Are the coefficients bounded in [0, plainModulus)?

adolfommoyano commented 2 years ago

@kimlaine The hexadecimal string looks like 696C1758E157438EF9C7DD4867CBE5F01453E5C0FE53CCF287CDB5D9842B45DA. PlainModulus is: parms.PlainModulus = new Modulus(1024). How should I set it? What is the maximum value?

kimlaine commented 2 years ago

Note that the Modulus(1024) sets the modulus to be literally 1024 -- not 1024 bits. The plainModulus can be at most 60 bits, but even such a large one is pretty impractical to use. There used to be a hacky way in SEAL to do arithmetic on such large integers, but this was removed due to serious usability problems. There are some other better ways, but these are not implemented by any library since there aren't (m)any applications.

adolfommoyano commented 2 years ago

Note that the Modulus(1024) sets the modulus to be literally 1024 -- not 1024 bits. The plainModulus can be at most 60 bits, but even such a large one is pretty impractical to use. There used to be a hacky way in SEAL to do arithmetic on such large integers, but this was removed due to serious usability problems. There are some other better ways, but these are not implemented by any library since there aren't (m)any applications.

Okey, thanks!