def Paillier_Signed_send(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None): if isclient(): _sendcost(bitlen) _cast_send(src, dst, Signed) else: _sendcost(state.config.asymmetric_security_parameter) _send(src, dst)
def PaillierVec_PlainVec_receive(typ, src, dst, bitlen, dim, signed, force_bitlen, force_signed): tmp = _receive() tmp._bit_length = force_bitlen or bitlen if isclient(): bla = typ(val=tmp) else: bla = tmp _set_dst(src, dst, bla)
def Garbled_Signed_send(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None): _sendcost(bitlen) if isclient(): _send(bits2value(permbits(src._value)), src.signed()) else: new = Signed(val=src) _sender_copy(new, dst) # atteches here _send(new)
def Garbled_Unsigned_send(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None): _sendcost(bitlen) if isclient(): if src.signed(): warnings.warn("Loosing Signedness", UserWarningRepeated) _send((bits2value(permbits(src._value)), src.signed())) else: new = Unsigned(val=src) _sender_copy(new, dst) # atteches here _send(new)
def Plain_Garbled_send(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None): _sendcost(bitlen * (state.config.symmetric_security_parameter + 1)) if isclient(): raise TastySyntaxError("Encrypting to Garbled and Sending to Server does not make sense") if state.precompute: tmp = Garbled(val=src, bitlen=bitlen, signed=signed) state.active_party.push_tmpattr(tmp) else: tmp = state.active_party.pop_tmpattr() tmp = Garbled(val=src, bitlen=bitlen, signed=signed) _sender_copy(tmp, dst) # attaches implicitly here _send(tmp)
def Paillier_Garbled_receive(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None): if force_bitlen is not None: bitlen = force_bitlen if force_signed is not None: signed = force_signed p = partyAttribute if not isclient(): raise TastySyntaxError("Conversion from Homomorphic to Garbled from Client to Server does not make sense") masklen = bitlen + state.config.symmetric_security_parameter if state.precompute: # receive garbled Mask mgm = _receive(src, dst) mgm._bit_length = bitlen state.active_party.push_tmpattr(mgm) # prepare for creation of garbled masked plain value mgv = Garbled(bitlen = bitlen, val=p, signed=False) state.active_party.push_tmpattr(mgv) # prepare addition circuit to remove the mask ret = mgv.dropmsb_sub(mgm) # save shadow copy of resulting Garbled _set_dst(src, dst, ret) ret.set_bit_length(bitlen) # avoid warnings here, in online phase this is correct ret._signed = False else: mgm = state.active_party.pop_tmpattr() state.active_party._tmp_ = state.active_party.pop_tmpattr() # get the masked Homomorphic hval = _receive() hval._bit_length = masklen # decrypt the masked Homomorphic mpv = Unsigned(val=hval) mpv._value &= ((1<<bitlen)-1) if mpv.signed(): raise NotImplementedError() mpv.set_bit_length(bitlen) # convert plain masked value into Garbled state.active_party._tmp_ = Garbled(val=mpv, bitlen=bitlen, signed=signed) # deblind the garbled value ret = state.active_party._tmp_.dropmsb_sub(mgm) # tasty calculates theoretical worst case bitlengths. Since we know better, # we can safely overwrite that _set_dst(src, dst, ret) ret.set_bit_length(bitlen) ret._signed = hval.signed()
def next_ots(self, args): args = tuple(args) num = len(args) try: if isclient(self.party): x = (args, self.__precomputed_b.popleft(num), self.__precomputed_m.popleft(num)) else: x = (args, self.__precomputed_m.popleft(num)) except IndexError: try: x except NameError: x = [None, []] raise OverflowError( "More oblivoius transfers requested then generated (%d requested and only %d left)" % (num, len(x[1]))) ot = BeaverOT(self.party) ot(x) return tuple(ot.get_results())
def PaillierVec_GarbledVec_receive(src, dst, source_bitlen, source_dim, signed, force_bitlen=None, force_signed=None): p = partyAttribute if force_bitlen and (force_signed or (signed and not force_signed == False)): raise NotImplementedError("forcing bitlen on signeds is not supported now") if force_bitlen: source_bitlen = force_bitlen overallbitlen = reduce(operator.mul, source_dim, 1) * source_bitlen cpc = state.config.asymmetric_security_parameter - state.config.symmetric_security_parameter - 1 chunksize = (cpc - 1) / source_bitlen chunkpayloadbits = chunksize * source_bitlen chunks = (overallbitlen - 1) / chunkpayloadbits + 1 lastchunksize = overallbitlen % (chunksize * source_bitlen) if lastchunksize: chunksizes = (chunks - 1) * (chunkpayloadbits, ) + (lastchunksize, ) masks = nogen(get_randomm(0, 2**(chunkpayloadbits + state.config.symmetric_security_parameter) - 1, chunks - 1)) + (mpz(rand.randint(0, 2**(lastchunksize + state.config.symmetric_security_parameter) - 1)),) else: chunksizes = chunks * (chunkpayloadbits, ) masks = nogen(get_randomm(0, 2**(chunkpayloadbits + state.config.symmetric_security_parameter)- 1, chunks)) if state.precompute: if force_signed is not None: signed = force_signed # receive garbled Mask mgms = _receive(src, dst) for mgm, size in zip(mgms, chunksizes): mgm._bit_length = size # prepare for creation of garbled masked plain value state.active_party.push_tmpval(mgms) # precompute first chunkpayloadbits for the garbled masked value mgvs = [] for i in chunksizes: mgv = Garbled(bitlen=i, val=p, signed=False) state.passive_party.push_tmpattr(mgv) mgvs.append(mgv) # precompute the unmasking and unpacking rets = [] for mgv, mgm, chunksize in zip (mgvs, mgms, chunksizes): ret = mgv.unpack(mgm, source_bitlen, chunksize, signed) state.active_party.push_tmpattr(ret) rets.extend(ret) rets.reverse() vec = GarbledVec(bitlen=source_bitlen, dim=source_dim, val=rets, signed=signed) # save shadow copy of resulting GarbledVec _set_dst(src, dst, vec) else: # online phase if force_signed is not None: signed = force_signed if not isclient(): raise TastySyntaxError("Conversion from Homomorphic to Garbled from Client to Server does not make sense") # receive masked homomorphic values mhvs = _receive() for i, chunksize in zip(mhvs, chunksizes): i._bit_length = chunksize # decrypt masked garbled values mvs = nogen(Unsigned(val=i) for i in mhvs) # get the masked garbled values from tmpval-stack mgms = state.active_party.pop_tmpval() # compute first chunksize bits of garbled masked values mgvs = [] for mv, chunksize in zip(mvs, chunksizes): state.passive_party._tmp_ = mgv = state.passive_party.pop_tmpattr() mv._value &= (1<<chunksize) - 1 mv.set_bit_length(chunksize) state.passive_party._tmp_ = Garbled(val=mv, bitlen=chunksize, signed=signed) mgvs.append(state.passive_party._tmp_) # unpacking and unblinding rets = [] for mgm, mgv, chunksize in zip(mgms, mgvs, chunksizes): state.active_party._tmp_ = state.active_party.pop_tmpattr() state.active_party._tmp_ = mgv.unpack(mgm, source_bitlen, chunksize, signed) rets.extend(state.active_party._tmp_) rets.reverse() vec = GarbledVec(bitlen=source_bitlen, dim=source_dim, val=rets, signed = rets[0].signed()) _set_dst(src, dst, vec)
def PaillierVec_PlainVec_send(typ, src, dst, bitlen, dim, signed, force_bitlen, force_signed): if isclient(): src = typ(val=src) _send(src)