Example #1
0
        def do_stuff(triple, alpha):
            random = Random(3423993)
            share_random = Random(random.getrandbits(128))

            paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
            gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, alpha)

            x2 = gen.generate_share(x1)
            y2 = gen.generate_share(y1)
            z2 = runtime._basic_multiplication(self.Zp(x1), y2, triple.a, triple.b, triple.c)
            d = runtime.open(z2)
            d.addCallback(check)
            return d
Example #2
0
        def do_mult(triples, alpha):
            runtime.triples = triples
            random = Random(3423993)
            share_random = Random(random.getrandbits(128))
            paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
            gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, alpha)

            x2 = gen.generate_share(x1)
            y2 = gen.generate_share(y1)

            z2 = x2 * y2
            d = runtime.open(z2)
            d.addCallback(check)
            return d
Example #3
0
    def test_encrypted_real_share_open_correctly(self, runtime):
        random = Random(3423993)
        modulus = 17
        Zp = GF(modulus)
        bits_in_p = 5
        u_bound = 2**(4 * bits_in_p)
        alpha = 15
        
        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))

        share_random = Random(random.getrandbits(128))
        gen = TestShareGenerator(Zp, runtime, share_random, paillier, u_bound, alpha)
        share = gen.generate_share(7)
        def check(v):
            self.assertEquals(7, v)
        r = runtime.open(share)
        runtime.schedule_callback(r, check)
        return r
Example #4
0
    def test_sum_plus(self, runtime):
        """Test addition of two numbers."""

        def check(v):
            self.assertEquals(v, 11)

        random = Random(3423993)
        share_random = Random(random.getrandbits(128))

        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
        gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, self.alpha)

        x2 = gen.generate_share(2)
        y2 = gen.generate_share(9)
        z2 = x2 + y2
        d = runtime.open(z2)
        d.addCallback(check)
        return d
Example #5
0
    def test_open_two_secret_share(self, runtime):
        """Test sharing and open of a number."""

        def check((a, b)):
            self.assertEquals(a, 6)
            self.assertEquals(b, 6)

        random = Random(3423993)
        share_random = Random(random.getrandbits(128))

        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
        gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, self.alpha)

        x = gen.generate_share(6)
        y = gen.generate_share(6)
        d = runtime.open_two_values(x, y)
        d.addCallback(check)
        return d
Example #6
0
    def test_sub_constant_left(self, runtime):
        """Test subtraction of a public number and secret shared number."""

        y = 8

        def check(v):
            self.assertEquals(v, 3)

        random = Random(3423993)
        share_random = Random(random.getrandbits(128))

        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
        gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, self.alpha)

        x2 = gen.generate_share(5)
        z2 = y - x2
        d = runtime.open(x2)
        d.addCallback(check)
        return d
Example #7
0
    def test_sum_constant_right(self, runtime):
        """Test addition of secret shared number and a public number."""

        y1 = 7

        def check(v):
            self.assertEquals(v, 15)

        random = Random(3423993)
        share_random = Random(random.getrandbits(128))

        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
        gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, self.alpha)

        x2 = gen.generate_share(8)
        z2 = x2 + y1
        d = runtime.open(z2)
        d.addCallback(check)
        return d
Example #8
0
    def test_constant_multiplication_constant_right(self, runtime):
        """Test multiplication of two numbers."""

        x1 = 6
        y1 = 7

        def check(v):
            self.assertEquals(v, self.Zp(x1 * y1))

        random = Random(3423993)
        share_random = Random(random.getrandbits(128))

        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
        gen = TestShareGenerator(self.Zp, runtime, share_random, paillier, self.u_bound, self.alpha)

        x2 = gen.generate_share(x1)

        z2 = runtime._cmul(x2, self.Zp(y1), self.Zp)
        d = runtime.open(z2)
        d.addCallback(check)
        return d
Example #9
0
    def test_encrypted_random_real_shares_open_correctly(self, runtime):
        random = Random(3423993)
        modulus = 17
        Zp = GF(modulus)
        bits_in_p = 5
        u_bound = 2**(4 * bits_in_p)
        alpha = 15
        
        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))

        share_random = Random(random.getrandbits(128))
        gen = TestShareGenerator(Zp, runtime, share_random, paillier, u_bound, alpha)
        shares = gen.generate_random_shares(7)
        expected_result = [9,16,7,12,3,5,6]
        results = []
        for inx, share in enumerate(shares):
            def check(v, expected_result):
                self.assertEquals(expected_result, v)
            r = runtime.open(share)
            results.append(r)
            runtime.schedule_callback(r, check, expected_result[inx])
        return gather_shares(results)