hashutilities.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:crypto 作者: erose1337 项目源码 文件源码
def split_secret(secret, piece_count, function):
    """ Splits secret into piece_count separate challenges, based on cracking a
        given output function from function.

        The secret can be recovered by a threshold quantity of pieces, which is
        determined by the size of the secret and the number/weight of pieces. 

        Challenge weight is calculated as:

            piece_size, last_challenge_size = divmod(len(secret), piece_count - 1)

        Note that if the length of secret is not evenly divisible by piece_count,
        then the last challenge will be of weight len(secret) % (piece_count - 1). """
    piece_size, remainder = divmod(len(secret), piece_count - 1)    
    pieces = []
    for index in range(piece_count - 1):
        piece = secret[index * piece_size:(index + 1) * piece_size]
        challenge_iv = random._urandom(16)
        hash_output = function(challenge_iv, piece)
        pieces.append((index, hash_output, challenge_iv))
    last_iv = random._urandom(16)
    #print "Creating last block: ", -remainder
    pieces.append((index + 1, function(last_iv, secret[-remainder:]), last_iv))
    return pieces, function('', secret), piece_size
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号