def calculate_cost(self):
"""Calculate the cost of fulfilling self condition.
The cost of the RSA condition is the size of the modulus
squared, divided By 64.
Returns:
int: Expected maximum cost to fulfill self condition.
"""
if self.modulus is None:
raise MissingDataError('Requires a public modulus')
public_numbers = RSAPublicNumbers(
PUBLIC_EXPONENT,
int.from_bytes(self.modulus, byteorder='big'),
)
public_key = public_numbers.public_key(default_backend())
modulus_bit_length = public_key.key_size
# TODO watch out >> in Python is not the sane as JS >>>, may need to be
# corrected. For instance see:
# http://grokbase.com/t/python/python-list/0454t3tgaw/zero-fill-shift
return int(math.pow(modulus_bit_length, 2)) >> RsaSha256.COST_RIGHT_SHIFT
评论列表
文章目录