|
|
@ -30,20 +30,19 @@ else: |
|
|
|
|
|
|
|
|
|
|
|
if hasattr(int, "to_bytes"): |
|
|
|
def int_to_bytes(num, length=None): |
|
|
|
return length or num.to_bytes((num.bit_length() + 7) // 8 or 1, 'big') |
|
|
|
def int_to_bytes(num): |
|
|
|
return pad_scalar( |
|
|
|
num.to_bytes((num.bit_length() + 7) // 8 or 1, 'big') |
|
|
|
) |
|
|
|
else: |
|
|
|
def int_to_bytes(num, length=None): |
|
|
|
def int_to_bytes(num): |
|
|
|
hexed = '%x' % num |
|
|
|
|
|
|
|
# Handle odd-length hex strings. |
|
|
|
if len(hexed) & 1: |
|
|
|
hexed = '0' + hexed |
|
|
|
|
|
|
|
if not length: |
|
|
|
return unhexlify(hexed) |
|
|
|
|
|
|
|
return pad_scalar(unhexlify(hexed), length) |
|
|
|
return pad_scalar(unhexlify(hexed)) |
|
|
|
|
|
|
|
|
|
|
|
def sha256(bytestr): |
|
|
@ -75,8 +74,8 @@ def get_valid_secret(): |
|
|
|
return secret |
|
|
|
|
|
|
|
|
|
|
|
def pad_scalar(scalar, length=KEY_SIZE): |
|
|
|
return (ZERO * (length - len(scalar))) + scalar |
|
|
|
def pad_scalar(scalar): |
|
|
|
return (ZERO * (KEY_SIZE - len(scalar))) + scalar |
|
|
|
|
|
|
|
|
|
|
|
def validate_secret(secret): |
|
|
|