using ec class
@@ -11,7 +11,7 @@ Created on Thu Nov 9 11:00:55 2017
# https://github.com/AntonKueltz/fastecdsa/blob/master/fastecdsa/util.py
from hashlib import sha256
-from ECsecp256k1 import order as ec_order
+from ECsecp256k1 import ec
from struct import pack
from binascii import hexlify
from hmac import new as hmac_new
@@ -19,7 +19,7 @@ from hmac import new as hmac_new
default_hasher = sha256
default_hash_digest_size = 32
-qlen = len(bin(ec_order)) - 2 # -2 for the leading '0b'
+qlen = len(bin(ec.order)) - 2 # -2 for the leading '0b'
rlen = ((qlen + 7) // 8) * 8
def bits2int(b):
@@ -39,7 +39,7 @@ def int2octets(x):
def bits2octets(b):
z1 = bits2int(b) # -2 for the leading '0b'
- z2 = z1 % ec_order
+ z2 = z1 % ec.order
return int2octets(z2)
def check_hash_digest(m, hash_digest_size=default_hash_digest_size):
@@ -48,7 +48,7 @@ def check_hash_digest(m, hash_digest_size=default_hash_digest_size):
assert type(m) == bytes and len(m) == hash_digest_size, "m must be bytes with correct bytes length"
def rfc6979(prv, m, hasher=default_hasher):
- assert type(prv) == int and 0 < prv and prv < ec_order, "invalid prv"
+ assert type(prv) == int and 0 < prv and prv < ec.order, "invalid prv"
check_hash_digest(m)
return rfc6979_raw(prv, m, hasher)
@@ -67,7 +67,7 @@ def rfc6979_raw(prv, m, hasher=default_hasher):
v = hmac_new(k, v, hasher).digest()
t = t + v
nonce = bits2int(t)
- if nonce >= 1 and nonce < ec_order:
+ if nonce >= 1 and nonce < ec.order:
# here it should be checked that nonce do not yields a invalid signature
# but then I should put the signature generation here
return nonce
@@ -76,7 +76,7 @@ def rfc6979_raw(prv, m, hasher=default_hasher):
"""
def deterministic_k(prv, msg, hasher = sha256):
- assert type(prv) == int and 0 < prv and prv < ec_order, "invalid prv"
+ assert type(prv) == int and 0 < prv and prv < ec.order, "invalid prv"
if type(msg) == str: msg = msg.encode()
assert type(msg) == bytes
hashmsg = hasher(msg)
@@ -98,7 +98,7 @@ def deterministic_k_raw(prv, m, hasher=default_hasher):
v = hmac_new(k, v, hasher).digest()
t = t + v
nonce = bits2int(t)
- if nonce >= 1 and nonce < ec_order:
+ if nonce >= 1 and nonce < ec.order:
# here it should be checked that nonce do not yields a invalid signature
# but then I should put the signature generation here
return nonce
