Ejemplo n.º 1
0
    def server_1(self, args):
        gc.disable()
        s = list(utils.get_random(0, 1, self.k))
        m = len(self.args)

        if m <= state.config.symmetric_security_parameter:
            # IKNP03 does not make sense if m <= symmetric_security_parameter
            # Use the subot directly then.
            self.subot.forward()
            self.subot(self.args)
            return None

        self.subot(s)
        tmp = [utils.value2bits(res, m) for res in self.subot.get_results()]
        Q = zip(*tmp)  # transpose tmp
        del tmp
        si = utils.bits2value(s)
        q = [utils.bits2value(j) for j in Q]
        cost_results.CostSystem.costs["theoretical"]["setup"]["accumulated"](
            Send=2 *
            utils.bit2byte(state.config.symmetric_security_parameter) * m)
        gc.enable()
        return (((xj0 ^ self.H(j, qj)).binary(),
                 (xj1 ^ self.H(j, qj ^ si)).binary())
                for (j, qj), (xj0, xj1) in zip(enumerate(q), self.args))
Ejemplo n.º 2
0
def Garbled_Unsigned_receive(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None):
    if isserver():
        val, signed = _receive(src, dst)
        val = value2bits(val, bitlen)
        zv = permbits(Garbled.get_zero_value(src.gid))
        if signed:
            warnings.warn("Loosing Signedness", UserWarningRepeated)
            val = abs(bits2value(perm2plain(val, zv)))
        else:
            val = bits2value(perm2plain(val, zv))
        new = Unsigned(val=val, bitlen=bitlen)
        _set_dst(src, dst, new)
    else:
        _just_receive(src, dst, bitlen, dim, signed)
Ejemplo n.º 3
0
 def client_2(self, args):
     args = tuple(args)
     self.results = (mpz(args[j][i], 256)
                     ^ self.H(j, utils.bits2value(self.T[j]))
                     for j, i in enumerate(self.args))
     gc.enable()
     return None
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def Garbled_Signed_receive(src, dst, bitlen, dim, signed, force_bitlen=None, force_signed=None):
    if isserver():
        val, signed = _receive(src, dst)
        val = value2bits(val, bitlen)
        zv = Garbled.get_zero_value(src.gid)
        val = bits2value(perm2plain(val, zv))
        new = Unsigned(val=val, bitlen=bitlen)
        _set_dst(src, dst, new)
    else:
        _just_receive(src, dst, bitlen, dim, signed)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
    def eval(self, inputs):
        """Evaluate circuit on plain inputs"""

        assert len(inputs) == len(self.inputs()), \
            "#inputs must match #inputs of circuit"

        u = self.num_input_bits()
        k = self.num_gates()

        wire_values = [None for i in xrange(u + k)]  #  values of wires

        # assign inputs
        input_desc = self.inputs()
        k = 0
        for ix, i in enumerate(inputs):  # for each input i
            v = i
            l, desc = input_desc[ix]
            state.log.debug("%s:", desc)

            wire_values[k:k + l] = value2bits(mpz(v), l)
            k += l

        # evaluate gates
        state.log.debug("Evaluating gates:")

        for gx, g in enumerate(self.next_gate()):  # for each gate
            g_ins, g_tab = g

            # determine index into gate table
            tab_idx = 0
            for i in g_ins:
                tab_idx <<= 1
                tab_idx |= wire_values[i]

            # evaluate gate
            lookup_idx = (1 << len(g_ins)) - tab_idx - 1
            val = (g_tab & (1 << lookup_idx)) >> lookup_idx
            wire_values[u + gx] = val

            state.log.debug("%d: %s %s @ %d => %d", u + gx, g_ins, bin(g_tab),
                            tab_idx, val)

        # read outputs
        output_values = []
        for out, desc, type_ in self.outputs():
            trans_out = map(lambda x: wire_values[x], out)
            o_val = bits2value(trans_out)
            output_values.append(o_val)
        return output_values
Ejemplo n.º 8
0
 def otlist(r, T):
     r = utils.bits2value(r)
     for i in xrange(self.k):
         ti = utils.bits2value(ithrow(T, i))
         yield (ti, ti ^ r)