Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def PRZS(*size):
"""
Generate a Pseudo-random Sharing of Zero (using arithmetic shares)
This function does so by generating `n` numbers across `n` parties with
each number being held by exactly 2 parties. Therefore, each party holds
two numbes. A zero sharing is found by having each party xor their two
numbers together.
"""
tensor = BinarySharedTensor(src=SENTINEL)
current_share = generate_kbit_random_tensor(*size, generator=comm.get().g0)
next_share = generate_kbit_random_tensor(*size, generator=comm.get().g1)
tensor.share = current_share ^ next_share
return tensor
def _get_binary_PRSS(self, size, bitlength=None, remove_rank=None):
"""
Generates a plaintext value from a set of random binary secret shares
generated by each party
"""
gens = self.generators[1:] if remove_rank else self.generators
result = [
generate_kbit_random_tensor(size, bitlength=bitlength, generator=g)
for g in gens
]
return reduce(lambda a, b: a ^ b, result)
def PRZS(*size):
"""
Generate a Pseudo-random Sharing of Zero (using arithmetic shares)
This function does so by generating `n` numbers across `n` parties with
each number being held by exactly 2 parties. Therefore, each party holds
two numbes. A zero sharing is found by having each party xor their two
numbers together.
"""
tensor = BinarySharedTensor(src=SENTINEL)
current_share = generate_kbit_random_tensor(*size, generator=comm.get().g0)
next_share = generate_kbit_random_tensor(*size, generator=comm.get().g1)
tensor.share = current_share ^ next_share
return tensor
def xor_share(secret, bitlength=constants.BITS, num_parties=2):
"""Create a boolean (xor) sharing from a secret"""
# For single process, do not encrypt (for debugging purposes)
if num_parties < 2:
return secret
shares0 = generate_kbit_random_tensor(secret.size(), bitlength=bitlength)
shares1 = secret ^ shares0
if num_parties == 2:
return shares0, shares1
return (
shares0,
*xor_share(shares1, bitlength=constants.BITS, num_parties=(num_parties - 1)),
)
def PRZS(*size):
"""
Generate a Pseudo-random Sharing of Zero (using arithmetic shares)
This function does so by generating `n` numbers across `n` parties with
each number being held by exactly 2 parties. Therefore, each party holds
two numbes. A zero sharing is found by having each party xor their two
numbers together.
"""
tensor = BinarySharedTensor(src=SENTINEL)
current_share = generate_kbit_random_tensor(*size, generator=comm.get().g0)
next_share = generate_kbit_random_tensor(*size, generator=comm.get().g1)
tensor.share = current_share ^ next_share
return tensor
def generate_binary_triple(size):
"""Generate binary triples of given size"""
generator = TTPClient.get().generator
a = generate_kbit_random_tensor(size, generator=generator)
b = generate_kbit_random_tensor(size, generator=generator)
if comm.get().get_rank() == 0:
# Request c from TTP
c = TTPClient.get().ttp_request("binary", size)
else:
c = generate_kbit_random_tensor(size, generator=generator)
# Stack to vectorize scatter function
a = BinarySharedTensor.from_shares(a)
b = BinarySharedTensor.from_shares(b)
c = BinarySharedTensor.from_shares(c)
return a, b, c
def PRZS(*size):
"""
Generate a Pseudo-random Sharing of Zero (using arithmetic shares)
This function does so by generating `n` numbers across `n` parties with
each number being held by exactly 2 parties. Therefore, each party holds
two numbes. A zero sharing is found by having each party xor their two
numbers together.
"""
tensor = BinarySharedTensor(src=SENTINEL)
current_share = generate_kbit_random_tensor(*size, generator=comm.get().g0)
next_share = generate_kbit_random_tensor(*size, generator=comm.get().g1)
tensor.share = current_share ^ next_share
return tensor