def test_cycle(): params = (['a', 'b'], [0], 'ABC', 'A', ) for i in params: my_cycler = tools.cycle(i) of_cycler = itertools.cycle(i) for _ in range(10): assert next(my_cycler) == next(of_cycler)
class muls(base.VarArgsInstruction, base.DataInstruction): """ Secret multiplication $s_i = s_j \cdot s_k$. """ __slots__ = [] code = base.opcodes['MULS'] arg_format = tools.cycle(['sw', 's', 's']) data_type = 'triple' def get_repeat(self): return len(self.args) / 3
class inputfloat(base.TextInputInstruction): __slots__ = [] code = base.opcodes['INPUTFLOAT'] arg_format = tools.cycle(['sw', 'sw', 'sw', 'sw', 'int', 'p']) field_type = 'modp' def add_usage(self, req_node): for player in self.args[5::6]: req_node.increment((self.field_type, 'input', player), \ 4 * self.get_size())
class asm_input(base.TextInputInstruction): r""" Receive input from player $p$ and put in register $s_i$. """ __slots__ = [] code = base.opcodes['INPUT'] arg_format = tools.cycle(['sw', 'p']) field_type = 'modp' def add_usage(self, req_node): for player in self.args[1::2]: req_node.increment((self.field_type, 'input', player), \ self.get_size()) def execute(self): self.args[0].value = _python_input( "Enter player %d's input:" % self.args[1]) % program.P
class muls(base.VarArgsInstruction, base.DataInstruction): """ Secret multiplication $s_i = s_j \cdot s_k$. """ __slots__ = [] code = base.opcodes['MULS'] arg_format = tools.cycle(['sw', 's', 's']) data_type = 'triple' def get_repeat(self): return len(self.args) / 3 def merge_id(self): # can merge different sizes # but not if large if self.get_size() > 100: return type(self), self.get_size() return type(self)
class mulrs(base.VarArgsInstruction, base.DataInstruction): """ Secret multiplication $s_i = s_j \cdot s_k$. """ __slots__ = [] code = base.opcodes['MULRS'] arg_format = tools.cycle(['int', 'sw', 's', 's']) data_type = 'triple' is_vec = lambda self: True def __init__(self, res, x, y): assert y.size == 1 assert res.size == x.size base.Instruction.__init__(self, res.size, res, x, y) def get_repeat(self): return sum(self.args[::4]) def get_def(self): return sum((arg.get_all() for arg in self.args[1::4]), []) def get_used(self): return sum( (arg.get_all() for arg in self.args[2::4] + self.args[3::4]), [])
class asm_open(base.VarArgsInstruction): """ Open the value in $s_j$ and assign it to $c_i$. """ __slots__ = [] code = base.opcodes['OPEN'] arg_format = tools.cycle(['cw', 's'])
class e_mult(base.VarArgsInstruction): """ Start mult secret register $s_i$. """ __slots__ = [] code = base.opcodes['E_MULT'] arg_format = tools.cycle(['sw', 's', 's'])
def test_cycle_exception(): my_cycler = cycle([]) with pytest.raises(StopIteration): next(my_cycler)
class trunc_pr(base.VarArgsInstruction): """ Probalistic truncation for semi-honest computation """ """ with honest majority """ __slots__ = [] code = base.opcodes['TRUNC_PR'] arg_format = tools.cycle(['sw', 's', 'int', 'int'])