I want to share the secret key of the BFV scheme among N users using the additive secret-sharing protocol (n-out-of-n threshold secret-sharing). Can anyone please help me to adapt the two algorithms correctly?
Note that the secret key of BFV is generated as a random ternary polynomial from R 2 ( R 2 is the key distribution used to sample polynomials with integer coefficients in $\{-1,0,1\}$)
secret key generation algorithm (python code)
import numpy as np
def gen_binary_poly(size):
""" Generates a polynomial with coeffecients in [0, 1]
Args:
size: number of coeffcients, size-1 being the degree of the polynomial.
Returns:
array of coefficients with the coeff[i] being the coeff of x ^ i.
"""
return np.random.randint(0, 2, size, dtype=np.int64)
if __name__ == "__main__":
#polynomial modulus degree
size= 2**4
secret_key = gen_binary_poly(size)
additive secret sharing algorithm (python code)
import random
def getAdditiveShares(secret, N, fieldSize):
'''Generate N additive shares from 'secret' in finite field of size 'fieldSize'.'''
# Generate n-1 shares randomly
shares = [random.randrange(fieldSize) for i in range(N-1)]
# Append final share by subtracting all shares from secret
# Modulo is done with fieldSize to ensure share is within finite field
shares.append((secret - sum(shares)) % fieldSize )
return shares
def reconstructSecret(shares, fieldSize):
'''Regenerate secret from additive shares'''
return sum(shares) % fieldSize
if __name__ == "__main__":
N=5 # 5 users
# Generating the shares
shares = getAdditiveShares(secret, N, fieldSize)
print('Shares are:', shares)
# Reconstructing the secret from shares
print('Reconstructed secret:', reconstructSecret(shares, fieldSize)