def share_and_recover(num_players, reconstruction_threshold, secret, end): max_secret_length = len(secret) players = test_authenticated_rss.get_ids(num_players) robust_shares = rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret) shares = {player: share for (player, share) in robust_shares.items()[:end]} return rss.reconstruct_unauthenticated_secret(num_players, max_secret_length, shares)
def corrupt_and_recover(robust_shares, num_players, end, num_corrupt): max_secret_length = len(secret) shares_subset = {player: share for (player, share) in robust_shares.items()[:end]} corrupters = {player: rss._deserialize_robust_share(share) for player, share in shares_subset.items()[:num_corrupt]} # corrupt share data for player, share_dict in corrupters.items(): share_dict["share"] /= 4 shares = test_authenticated_rss.combine_testing_dictionaries(shares_subset, test_authenticated_rss.jsonify_dict(corrupters)) return rss.reconstruct_unauthenticated_secret(num_players, max_secret_length, shares)
def verify(shares_map, test_secret, total_shares): """ Check to see if the unauthenticated Shamir recovery of shares_map results in test_secret Args: shares_map: a map of player_id to the share assigned to that player in call to share test_secret: a potential secret to check of the same size as the originally shared secret total_shares: the original number of shares created Returns True if the shares_map successfully recovers test_secret """ try: return test_secret == rss.reconstruct_unauthenticated_secret(total_shares, len(test_secret), shares_map) except: return False