Would this Python code generate a valid ECDSA private key?
import random
def r(a, b):
sys_ran = random.SystemRandom()
return sys_ran.randint(a, b)
def create_private_key():
hex_chars = '0123456789ABCDEF'
ran_hex = '';
for i in range(64):
ran_hex += hex_chars[r(0, 15)]
max_hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'
if int(ran_hex, 16) <= int(max_hex, 16):
return ran_hex
else:
return create_private_key()
private_key = create_private_key()
print('Private key: ' + private_key)
As far as I can tell from the Bitcoin wiki, an ECDSA private key is any 64 character hexadecimal (or the corresponding decimal) number between 0x1 and 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141. It doesn't mention anything about any special algorithms required for the private key to be valid.