def test_shamir_polynomial_compute(): dealer = Dealer(p256, n_participants, s_secrets, access_structures) dealer.access_group_polynomial_coeffs() # override coeffs dealer.d[0][0] = [bytes([0x05]), bytes([0x07])] coeffs = dealer.get_d_polynomial_coeffs(0, 0) secret_value = dealer.s_secrets[0] value = common.shamir_polynomial_compute(bytes([0x01]), coeffs, secret_value, dealer.p) assert_equal(value, 12 + s_secrets[0]) value = common.shamir_polynomial_compute(bytes([0x02]), coeffs, secret_value, dealer.p) assert_equal(value, 38 + s_secrets[0])
def user_polynomial_value_B(self, i_secret, q_group, participant): assert(participant in self.access_structures[i_secret][q_group]) print('user_polynomial_value_B for secret %d, group A %d '.format(i_secret, q_group)) participant_id = self.random_id[participant-1] print('B value for user %d with ID %d'.format(participant, participant_id)) coeffs = self.get_d_polynomial_coeffs(i_secret, q_group) secret_value = self.s_secrets[i_secret] # returns int return common.shamir_polynomial_compute(participant_id, coeffs, secret_value, self.p)
def compute_all_key_shares(self): self.key_shares = copy.deepcopy(self.access_structures) print(self.access_structures) for i, gamma in enumerate(self.access_structures): for q, A in enumerate(self.access_structures[i]): for b, Pb in enumerate(self.access_structures[i][q]): print('secret_value (cipher_key)', self.cipher_keys[i]) secret_value = int.from_bytes(self.cipher_keys[i], byteorder='big') self.key_shares[i][q][b] = \ common.shamir_polynomial_compute(self.random_id[b], self.d[i][q], secret_value, self.p) print( 'Key share = {} for user {} (index {}) and secret {}'. format(self.key_shares[i][q][b], Pb, b, i)) return self.key_shares