def choose_distinct_master_shares_x(self): """ dealer chooses distinct master share x_j for each participant """ master_shares_x = common.list_of_random_in_modulo_p(self.n, self.hash_len, self.p) common.print_list_of_hex(master_shares_x, 'x') return master_shares_x # TODO: use yield to construct a generator
def test_list_of_random_in_modulo_p(): """ test: list_of_random_in_modulo_p """ dealer = Dealer(4099, n_participants, s_secrets, access_structures) n = 5 randomList = common.list_of_random_in_modulo_p(n, dealer.hash_len, dealer.p) common.print_list_of_hex(randomList, 'test randomList') # check the length of the list assert_equal(len(randomList), n) # check the type of object in the list assert_equal(isinstance(randomList[0], bytes), True)
def test_access_group_polynomial_coeffs(): """ test: access_group_polynomial_coeffs """ A1 = (1, 3) # gamma1 is a group of users authorized to reconstruct s1 gamma1 = [A1] gamma2 = [(1, 2), (2, 3)] # A1, A2 implicitly gamma3 = [(1, 2, 3) ] # to secret s3 only all 3 users together can gain access access_structures = [gamma1, gamma2, gamma3] # Create a Dealer dealer = Dealer(p256, n_participants, s_secrets, access_structures) # compute d coeffs dealer.access_group_polynomial_coeffs() # dealer.print_list_of_hex(dealer.d[1][1], 'd-1-1') # test output assert_equal(len(dealer.d), 3) assert_equal(len(dealer.d[0]), 1) assert_equal(len(dealer.d[1][1]), 1) assert_equal(len(dealer.d[2][0]), 2) # Test index out of range with assert_raises(IndexError): print('Test', common.print_list_of_hex(dealer.d[2][1], 'd-2-1'))
def access_group_polynomial_coeffs(self): """ for the qth qualified set of access group, the dealer chooses d0, d1, d2... dm in Zp modulo field to construct the polynomial f_q(x) = si + d1*x + d2*x^2 + ... + dm*x^(m-1) note: d0 corresponds to x^1, d1 corresponds to x^2 """ for gindex, gamma in enumerate(self.access_structures): print('gamma%d for secret s%d:' % (gindex, gindex)) coeffs_for_A = [] self.d.append([]) for index, A in enumerate(gamma): coeffs_for_A = common.list_of_random_in_modulo_p( len(A) - 1, self.hash_len, self.p) print('A%d: %r' % (index, A)) common.print_list_of_hex(coeffs_for_A, 'polynomial coeff d') self.d[gindex].append(coeffs_for_A) return self.d