async def _prog(context: Mpc, xs: ShareArray): rs = context.ShareArray( [context.preproc.get_rand(context) for _ in range(len(xs))]) sigs = await (await (xs * rs)).open() sig_invs = context.ShareArray([1 / sig for sig in sigs]) return await (rs * sig_invs)
async def reduce_degree_share_array(context: Mpc, x_2t: ShareArray): assert x_2t.t == context.t * 2 r_t, r_2t = [], [] for _ in range(len(x_2t)): r_t_, r_2t_ = context.preproc.get_double_shares(context) r_t.append(r_t_) r_2t.append(r_2t_) q_t = context.ShareArray(r_t) q_2t = context.ShareArray(r_2t, 2 * context.t) diff = await (x_2t - q_2t).open() return q_t + diff
async def _prog(context: Mpc, x: ShareArray, y: ShareArray): assert len(x) == len(y) xy_2t = context.ShareArray( [j.v * k.v for j, k in zip(x._shares, y._shares)], context.t * 2) xy_t = await DoubleSharingMultiplyArrays.reduce_degree_share_array( context, xy_2t) return xy_t
async def _prog(context: Mpc, j: ShareArray, k: ShareArray): assert len(j) == len(k) a, b, ab = [], [], [] for _ in range(len(j)): p, q, pq = context.preproc.get_triples(context) a.append(p) b.append(q) ab.append(pq) u, v = context.ShareArray(a), context.ShareArray(b) f, g = await gather(*[(j - u).open(), (k - v).open()]) xy = [ d * e + d * q + e * p + pq for (p, q, pq, d, e) in zip(a, b, ab, f, g) ] return context.ShareArray(xy)
async def _prog(context: Mpc, p_share: Share, q_share: Share, security_parameter: int = 32): diff = p_share - q_share x = context.ShareArray(await gather(*[ Equality.gen_test_bit(context, diff) for _ in range(security_parameter) ])) return await x.multiplicative_product()