Example #1
0
    def test_mul_AB_private_private(self):
        tf.reset_default_graph()

        prot = ABY3()
        tfe.set_protocol(prot)

        x = tfe.define_private_variable(
            np.array([[1, 2, 3], [4, 5, 6]]), share_type=ARITHMETIC,
        )
        y = tfe.define_private_variable(
            tf.constant([[1, 0, 0], [0, 1, 0]]),
            apply_scaling=False,
            share_type=BOOLEAN,
            factory=prot.bool_factory,
        )

        z = tfe.mul_AB(x, y)

        with tfe.Session() as sess:
            # initialize variables
            sess.run(tfe.global_variables_initializer())
            # reveal result
            result = sess.run(z.reveal())
            np.testing.assert_allclose(
                result, np.array([[1, 0, 0], [0, 5, 0]]), rtol=0.0, atol=0.01
            )
Example #2
0
def test_mul_AB_public_private():
    tf.reset_default_graph()

    prot = ABY3()
    tfe.set_protocol(prot)

    x = tfe.define_constant(np.array([[1, 2, 3], [4, 5, 6]]),
                            share_type=ARITHMETIC)
    y = tfe.define_private_variable(tf.constant([[1, 0, 0], [0, 1, 0]]),
                                    apply_scaling=False,
                                    share_type=BOOLEAN,
                                    factory=prot.bool_factory)

    z = tfe.mul_AB(x, y)

    with tfe.Session() as sess:
        # initialize variables
        sess.run(tfe.global_variables_initializer())
        # reveal result
        result = sess.run(z.reveal())
        close(result, np.array([[1, 0, 0], [0, 5, 0]]))
        print("test_mul_AB_public_private succeeds")