示例#1
0
    def setup(self):
        w, u, g_w = dict(), dict(), dict()

        for idx in self.parties.keys():
            w_idx, u_idx, g_w_idx = list(), list(), list()
            for l in range(self.parties[idx]):
                rnd = _random(self.p, self.sec_param)
                w_idx.append(rnd)
                g_w_idx.append(gp.powmod(self.g, rnd, self.p))
                u_idx.append(_random(self.p, self.sec_param))
            w[idx] = w_idx
            u[idx] = u_idx
            g_w[idx] = g_w_idx

        self.mpk = {
            'g': self.g,
            'p': self.p,
            'sec_param': int(self.sec_param),
            'g_w': g_w,
            'parties': self.parties
        }
        self.msk = {'w': w, 'u': u}
示例#2
0
    def encrypt(self, pk, vec):
        assert len(vec) == pk['bound']

        p = gp.mpz(pk['p'])
        g = gp.mpz(pk['g'])

        r = _random(p, self.sec_param)
        ct0 = gp.digits(gp.powmod(g, r, p))
        ct_list = []
        for i in range(len(vec)):
            ct_list.append(gp.digits(
                gp.mul(
                    gp.powmod(gp.mpz(pk['pk'][i]), r, p),
                    gp.powmod(g, gp.mpz(int(vec[i])), p)
                )
            ))
        return {'ct0': ct0, 'ct_list': ct_list}
示例#3
0
    def encrypt(self, slot_pk, vec):
        assert len(vec) <= len(slot_pk['u'])
        assert len(vec) <= len(slot_pk['w'])

        p = gp.mpz(slot_pk['p'])
        g = gp.mpz(slot_pk['g'])
        sec_param = slot_pk['sec_param']
        u = slot_pk['u']
        w = slot_pk['w']

        r = _random(p, sec_param)
        t = gp.digits(gp.powmod(g, r, p))

        c = [
            gp.digits(
                gp.powmod(
                    g,
                    gp.mpz(vec[i]) + gp.mpz(u[i]) + gp.mul(gp.mpz(w[i]), r),
                    p)) for i in range(len(vec))
        ]

        return {'t': t, 'c': c}
示例#4
0
 def setup(self):
     self.msk = [_random(self.p, self.sec_param) for i in range(self.eta)]
     pk = [gp.powmod(self.g, self.msk[i], self.p) for i in range(self.eta)]
     self.mpk = {'p': self.p, 'g': self.g, 'pk': pk}