Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/key.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2019 Pieter Wuille | # Copyright (c) 2019 Pieter Wuille | ||||
# Copyright (c) 2019-2020 The Bitcoin developers | # Copyright (c) 2019-2020 The Bitcoin developers | ||||
"""Test-only secp256k1 elliptic curve implementation | """Test-only secp256k1 elliptic curve implementation | ||||
WARNING: This code is slow, uses bad randomness, does not properly protect | WARNING: This code is slow, uses bad randomness, does not properly protect | ||||
keys, and is trivially vulnerable to side channel attacks. Do not use for | keys, and is trivially vulnerable to side channel attacks. Do not use for | ||||
anything but tests. | anything but tests. | ||||
""" | """ | ||||
import hashlib | import hashlib | ||||
import random | import random | ||||
from .address import byte_to_base58 | from .address import byte_to_base58 | ||||
def modinv(a, n): | def modinv(a, n): | ||||
Lint: flake8 E302: expected 2 blank lines, found 1 | |||||
"""Compute the modular inverse of a modulo n | """Compute the modular inverse of a modulo n | ||||
See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers | See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers | ||||
""" | """ | ||||
t1, t2 = 0, 1 | t1, t2 = 0, 1 | ||||
r1, r2 = n, a | r1, r2 = n, a | ||||
while r2 != 0: | while r2 != 0: | ||||
q = r1 // r2 | q = r1 // r2 | ||||
▲ Show 20 Lines • Show All 398 Lines • ▼ Show 20 Lines | def sign_schnorr(self, msg32): | ||||
return sig | return sig | ||||
def bytes_to_wif(b, compressed=True): | def bytes_to_wif(b, compressed=True): | ||||
if compressed: | if compressed: | ||||
b += b'\x01' | b += b'\x01' | ||||
return byte_to_base58(b, 239) | return byte_to_base58(b, 239) | ||||
def generate_wif_key(): | def generate_wif_key(): | ||||
Lint: flake8 E302 expected 2 blank lines, found 1 Lint: flake8 E302: expected 2 blank lines, found 1 | |||||
# Makes a WIF privkey for imports | # Makes a WIF privkey for imports | ||||
k = ECKey() | k = ECKey() | ||||
k.generate() | k.generate() | ||||
return bytes_to_wif(k.get_bytes(), k.is_compressed) | return bytes_to_wif(k.get_bytes(), k.is_compressed) |
expected 2 blank lines, found 1