diff --git a/Compiler/compilerLib.py b/Compiler/compilerLib.py index 8c4f41b8d..66febc85c 100644 --- a/Compiler/compilerLib.py +++ b/Compiler/compilerLib.py @@ -206,6 +206,12 @@ def build_option_parser(self): dest="edabit", help="mixing arithmetic and binary computation using edaBits", ) + parser.add_option( + "--comparison_rabbit", + action="store_true", + dest="comparison_rabbit", + help="using the rabbit comparison protocol for known prime modulus, instead of truncation", + ) parser.add_option( "-Z", "--split", diff --git a/Compiler/library.py b/Compiler/library.py index 5f7e42e83..d695ee8d2 100644 --- a/Compiler/library.py +++ b/Compiler/library.py @@ -131,6 +131,25 @@ def print_ln(s='', *args, **kwargs): """ print_str(str(s) + '\n', *args, **kwargs) + +def print_without_ln(s='', *args, **kwargs): + """ Print line, with optional args for adding variables/registers + with ``%s``. By default only player 0 outputs, but the ``-I`` + command-line option changes that. + + :param s: Python string with same number of ``%s`` as length of :py:obj:`args` + :param args: list of public values (regint/cint/int/cfix/cfloat/localint) + :param print_secrets: whether to output secret shares + + Example: + + .. code:: + + print_ln('a is %s.', a.reveal()) + """ + print_str(str(s), *args, **kwargs) + + def print_both(s, end='\n'): """ Print line during compilation and execution. """ print(s, end=end) diff --git a/Compiler/non_linear.py b/Compiler/non_linear.py index 147af9f20..fc0f420a0 100644 --- a/Compiler/non_linear.py +++ b/Compiler/non_linear.py @@ -44,8 +44,52 @@ def trunc(self, a, k, m, signed): if m == 0: return a return self._trunc(a, k, m, signed) + + def LTBits(self, R, x, BIT_SIZE): + library.print_ln("in LTBits") + R_bits = cint.bit_decompose(R, BIT_SIZE) + y = [x[i].bit_xor(R_bits[i]) for i in range(BIT_SIZE)] + z = floatingpoint.PreOpL(floatingpoint.or_op, y[::-1])[::-1] + [0] + w = [z[i] - z[i + 1] for i in range(BIT_SIZE)] + + return types.sintbit(1) - types.sintbit(sum((R_bits[i] & w[i]) for i in range(BIT_SIZE))) + + def rabbitLTZ(self, x, BIT_SIZE = 64): + """ + s = (x