def test_generate_triples_generates_correct_triples(self, runtime):
        p = 17

        Zp = GF(p)

        random = Random(574566 + runtime.id)
        triple_generator = TripleGenerator(runtime, self.security_parameter, p,
                                           random)

        triples = triple_generator._generate_triples(10)

        def check((a, b, c)):
            self.assertEquals(c, a * b)

        def open(triple):
            d1 = runtime.open(triple.a)
            d2 = runtime.open(triple.b)
            d3 = runtime.open(triple.c)
            d = gatherResults([d1, d2, d3])
            runtime.schedule_callback(d, check)
            return d

        for triple in triples:
            runtime.schedule_callback(triple, open)
        return gatherResults(triples)
    def test_mul_mul(self, runtime):
        """Test multiplication of two numbers."""

        x1 = 6
        y1 = 6

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

        gen = TripleGenerator(runtime, self.security_parameter,
                              self.Zp.modulus, Random(3423993))
        alpha = gen.alpha
        triples = gen._generate_triples(1)

        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

        r = gatherResults(triples)
        runtime.schedule_callback(r, do_mult, alpha)
        return r
    def test_basic_multiply_constant_left(self, runtime):
        """Test multiplication of two numbers."""

        x1 = 6
        y1 = 6

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

        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

        gen = TripleGenerator(runtime, self.security_parameter,
                              self.Zp.modulus, Random(3423993))
        alpha = gen.alpha
        [triple] = gen._generate_triples(1)
        runtime.schedule_callback(triple, do_stuff, alpha)
        return triple
Example #4
0
    def test_basic_multiply_constant_left(self, runtime):
        """Test multiplication of two numbers."""

        x1 = 6
        y1 = 6

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

        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

        gen = TripleGenerator(runtime, self.security_parameter, self.Zp.modulus, Random(3423993))
        alpha = gen.alpha
        [triple] = gen._generate_triples(1)
        runtime.schedule_callback(triple, do_stuff, alpha)
        return triple
Example #5
0
    def test_mul_mul(self, runtime):
        """Test multiplication of two numbers."""

        x1 = 6
        y1 = 6

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

        gen = TripleGenerator(runtime, self.security_parameter, self.Zp.modulus, Random(3423993))
        alpha = gen.alpha
        triples = gen._generate_triples(1)

        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

        r = gatherResults(triples)
        runtime.schedule_callback(r, do_mult, alpha)
        return r
    def test_get_triple(self, runtime):
        """Test generation of a triple."""
        def check((a, b, c)):
            self.assertEquals(c, a * b)

        def open(triple):
            d1 = runtime.open(triple.a)
            d2 = runtime.open(triple.b)
            d3 = runtime.open(triple.c)
            d = gather_shares([d1, d2, d3])
            d.addCallback(check)
            return d

        random = Random(3423993)
        gen = TripleGenerator(runtime, self.security_parameter,
                              self.Zp.modulus, random)
        [triple] = gen._generate_triples(1)
        triple.addCallback(open)
        return triple
Example #7
0
    def test_get_triple(self, runtime):
        """Test generation of a triple."""

        def check((a, b, c)):
            self.assertEquals(c, a * b)

        def open(triple):
            d1 = runtime.open(triple.a)
            d2 = runtime.open(triple.b)
            d3 = runtime.open(triple.c)
            d = gather_shares([d1, d2, d3])
            d.addCallback(check)
            return d

        random = Random(3423993)
        gen = TripleGenerator(runtime, self.security_parameter, self.Zp.modulus, random)
        [triple] = gen._generate_triples(1)
        triple.addCallback(open)
        return triple
Example #8
0
    def test_generate_triples_generates_correct_single_triple(self, runtime):
        p = 17
        Zp = GF(p)
        random = Random(574566 + runtime.id)        
        triple_generator = TripleGenerator(runtime, self.security_parameter, p, random)
        triples = triple_generator._generate_triples(1)

        def check((a, b, c)):
            self.assertEquals(c, a * b)

        def open(triple):
            d1 = runtime.open(triple.a)
            d2 = runtime.open(triple.b)
            d3 = runtime.open(triple.c)
            d = gatherResults([d1, d2, d3])
            runtime.schedule_callback(d, check)
            return d

        for triple in triples:
            runtime.schedule_callback(triple, open)
        return gatherResults(triples)