Exemplo n.º 1
0
async def test_open_future_shares():
    n, t = 4, 1
    pp_elements = PreProcessedElements()
    pp_elements.generate_rands(1000, n, t)
    pp_elements.generate_triples(1000, n, t)

    async def _prog(context):
        e1_, e2_ = [context.preproc.get_rand(context) for _ in range(2)]
        e1, e2 = await asyncio.gather(*[e1_.open(), e2_.open()],
                                      return_exceptions=True)

        s_prod_f = e1_ * e2_
        s_prod_f2 = s_prod_f * e1_
        final_prod = s_prod_f2 + e1_ + e2_
        final_prod_2 = final_prod * e1_
        wrapped_final_prod_2 = context.Share(final_prod_2.open())

        assert await s_prod_f2.open() == e1 * e1 * e2
        assert await final_prod.open() == e1 * e1 * e2 + e1 + e2
        assert await final_prod_2.open() == (e1 * e1 * e2 + e1 + e2) * e1
        assert await wrapped_final_prod_2.open() == await final_prod_2.open()

    program_runner = TaskProgramRunner(
        n, t, {MixinConstants.MultiplyShare: BeaverMultiply()})
    program_runner.add(_prog)
    await program_runner.join()
Exemplo n.º 2
0
from pytest import mark

from honeybadgermpc.elliptic_curve import Jubjub, Point
from honeybadgermpc.progs.jubjub import SharedPoint, share_mul
from honeybadgermpc.progs.mixins.share_arithmetic import (
    BeaverMultiply,
    BeaverMultiplyArrays,
    DivideShareArrays,
    DivideShares,
    Equality,
    InvertShare,
    InvertShareArray,
)

MIXINS = [
    BeaverMultiply(),
    BeaverMultiplyArrays(),
    InvertShare(),
    InvertShareArray(),
    DivideShares(),
    DivideShareArrays(),
    Equality(),
]

TEST_PREPROCESSING = ["rands", "triples", "bits"]

TEST_CURVE = Jubjub()
TEST_POINT = Point(
    5,
    6846412461894745224441235558443359243034138132682534265960483512729196124138,
    TEST_CURVE,
Exemplo n.º 3
0
import asyncio
from honeybadgermpc.mpc import TaskProgramRunner
from honeybadgermpc.progs.mixins.dataflow import Share
from honeybadgermpc.preprocessing import (
    PreProcessedElements as FakePreProcessedElements,
)
from honeybadgermpc.utils.typecheck import TypeCheck
from honeybadgermpc.progs.mixins.share_arithmetic import (
    MixinConstants,
    BeaverMultiply,
    BeaverMultiplyArrays,
)

config = {
    MixinConstants.MultiplyShareArray: BeaverMultiplyArrays(),
    MixinConstants.MultiplyShare: BeaverMultiply(),
}


@TypeCheck()
async def beaver_multiply(ctx, x: Share, y: Share):
    """The hello world of MPC: beaver multiplication
     - Linear operations on Share objects are easy
     - Shares of random values are available from preprocessing
     - Opening a Share returns a GFElementFuture
    """
    a, b, ab = ctx.preproc.get_triples(ctx)
    D = await (x - a).open()
    E = await (y - b).open()

    # D*E is multiplying GFElements
Exemplo n.º 4
0
from pytest import mark
from random import randint
from honeybadgermpc.elliptic_curve import Jubjub
from honeybadgermpc.progs.mimc import mimc_mpc_batch
from honeybadgermpc.progs.mixins.share_arithmetic import (
    BeaverMultiply,
    BeaverMultiplyArrays,
    InvertShare,
    InvertShareArray,
    DivideShares,
    DivideShareArrays,
    Equality,
)

CONFIG = {
    BeaverMultiply.name: BeaverMultiply(),
    BeaverMultiplyArrays.name: BeaverMultiplyArrays(),
    InvertShare.name: InvertShare(),
    InvertShareArray.name: InvertShareArray(),
    DivideShares.name: DivideShares(),
    DivideShareArrays.name: DivideShareArrays(),
    Equality.name: Equality(),
}

PREPROCESSING = ["rands", "triples", "zeros", "cubes", "bits"]
n, t = 4, 1
k = 300000

TEST_CURVE = Jubjub()
TEST_FIELD = Jubjub.Field
TEST_KEY = TEST_FIELD(randint(0, TEST_FIELD.modulus))
Exemplo n.º 5
0
from pytest import mark
from random import randint
from honeybadgermpc.field import GF
from honeybadgermpc.mpc import Subgroup
from honeybadgermpc.progs.mimc import mimc_mpc, mimc_plain, mimc_mpc_batch
from honeybadgermpc.progs.mixins.share_arithmetic import BeaverMultiply

MIXINS = [BeaverMultiply()]
PREPROCESSING = ["rands", "triples", "zeros", "cubes"]
n, t = 4, 1
k = 3500


@mark.asyncio
async def test_mimc(test_runner):
    async def _prog(context):
        x = context.preproc.get_zero(context)
        field = GF(Subgroup.BLS12_381)
        key = field(15)

        # Compute F_MiMC_mpc
        mm = await mimc_mpc(context, x, key)
        mm_open = await mm.open()

        # open x, then compute F_MiMC_plain
        x_open = await x.open()
        mp = mimc_plain(x_open, key)

        # Compare the MPC evaluation to the plain one
        assert mm_open == mp
Exemplo n.º 6
0
import asyncio
import logging
import time

from honeybadgermpc.elliptic_curve import Subgroup
from honeybadgermpc.field import GF
from honeybadgermpc.mpc import TaskProgramRunner
from honeybadgermpc.preprocessing import (
    PreProcessedElements as FakePreProcessedElements, )
from honeybadgermpc.progs.mixins.share_arithmetic import BeaverMultiply, MixinConstants

config = {MixinConstants.MultiplyShare: BeaverMultiply()}
"""
Secure Computation With Fixed-Point Numbers
Catrina and Saxena
http://www.ifca.ai/pub/fc10/31_47.pdf
"""

# Fixed Point parameters

F = 32  # The precision (binary bits)
"""
This implementation of the library is not completely hiding. This leaks information about the bits used in computation which is determinied by the security parameter Kappa.
In particular, we leak O(1/(2^Kappa)) information theorotic bits per operation on a floating point secret.
"""
KAPPA = 32  # Statistical security parameter
K = 64  # Total number of padding bits ()
p = modulus = Subgroup.BLS12_381
Field = GF(p)
"""
Library for fixed point operations:
import random

from pytest import mark

from honeybadgermpc.preprocessing import (
    PreProcessedElements as FakePreProcessedElements, )
from honeybadgermpc.progs.fixedpoint import FixedPoint
from honeybadgermpc.progs.mixins.share_arithmetic import BeaverMultiply, MixinConstants

config = {MixinConstants.MultiplyShare: BeaverMultiply()}

STANDARD_ARITHMETIC_MIXINS = [BeaverMultiply()]

STANDARD_PREPROCESSING = ["triples", "bits", "zeros"]

n, t = 4, 1


async def run_test_program(prog,
                           test_runner,
                           n=n,
                           t=t,
                           k=1000,
                           mixins=STANDARD_ARITHMETIC_MIXINS):

    return await test_runner(prog, n, t, STANDARD_PREPROCESSING, k, mixins)


def approx_equal(value, expected, epsilon=0.0001):
    return abs(value - expected) <= epsilon