3

I am working with a fairly simple Paillier partial homomorphic encryption library in Haskell. The API for the library is here - https://hackage.haskell.org/package/Paillier-0.1.0.3/docs/Crypto-Paillier.html

This library unfortunately does not handle negative numbers or floating point numbers. It only operates on positive integers. So, an operation like

decrypt prvKey pubKey (encrypt pubKey (-10))  =/=  -10

My naive approach to handling negative numbers and floating points was to multiply the Integers with my desired precision (say 10^6) and then convert it back. But internally, some modular arithmetic does not work for homomorphic multiplication (exponentiation).

The problem could somewhat be boiled down to finding a good encoding of negative numbers as well as floating point numbers into an Integer type (the arbitrary precision integer type in Haskell). Is there any good strategy to do the encoding?

Another strategy could be modifying the modular exponentiation function in the cryptonite package to handle modular arithmetic for negative numbers (https://hackage.haskell.org/package/cryptonite-0.30/docs/Crypto-Number-ModArithmetic.html#v:expSafe).

Can anyone suggest to me the best strategy or something that I am missing out here?

Abhiroop Sarkar
  • 2,251
  • 1
  • 26
  • 45
  • Perhaps [this question and its answer](https://crypto.stackexchange.com/questions/59444/paillier-subtraction-for-negative-result) on the Cryptography Stack Exchange are relevant . In any event, I think you'll have better luck asking there instead. – K. A. Buhr Feb 11 '23 at 19:10
  • Do you need to do math on these, or just have a reversible conversion between negative integers or floating point values as nonnegative numeric values? The latter is easy, the former is harder. (Zigzag encoding and IEEE-754 respectively.) – Louis Wasserman Feb 23 '23 at 03:16

0 Answers0