diff --git a/nix/user-packages.nix b/nix/user-packages.nix index a0c8d395..91f5bb31 100644 --- a/nix/user-packages.nix +++ b/nix/user-packages.nix @@ -40,7 +40,6 @@ rec { python-packages = with python.pkgs; { # pycryptodome = pycryptodome; # altcoins - # py-ecc = py-ecc; # test suite # pysocks = pysocks; # XMR # monero = monero; # XMR (test suite) # eth-keys = eth-keys; # ETH, ETC (test suite) diff --git a/test-requirements.txt b/test-requirements.txt index ca5e8364..4bd65b91 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,3 @@ pycoin monero eth_keys -py_ecc diff --git a/test/include/ecc.py b/test/include/ecc.py index 529c2255..670a10a6 100755 --- a/test/include/ecc.py +++ b/test/include/ecc.py @@ -12,7 +12,7 @@ test.include.ecc: elliptic curve utilities for the MMGen test suite """ -import ecdsa +import ecdsa, hashlib from mmgen.proto.secp256k1.keygen import pubkey_format def _pubkey_to_pub_point(vk_bytes): @@ -41,3 +41,14 @@ def pubkey_tweak_add_pyecdsa(vk_bytes, pk_addend_bytes): return pubkey_format( ecdsa.VerifyingKey.from_public_point(point_sum, curve=ecdsa.curves.SECP256k1).to_string(), compressed = len(vk_bytes) == 33) + +def sign_msghash_pyecdsa(msghash, privkey): + ec_privkey = ecdsa.SigningKey.from_string(privkey, curve=ecdsa.curves.SECP256k1) + return ec_privkey.sign_digest_deterministic( + msghash, + hashfunc = hashlib.sha256, + sigencode = ecdsa.util.sigencode_string_canonize) + +def verify_sig_pyecdsa(sig, msghash, pubkey): + ec_pubkey = ecdsa.VerifyingKey.from_string(pubkey, curve=ecdsa.curves.SECP256k1) + return ec_pubkey.verify_digest(sig, msghash) diff --git a/test/modtest_d/ecc.py b/test/modtest_d/ecc.py index 46a7cb8e..2f93a289 100755 --- a/test/modtest_d/ecc.py +++ b/test/modtest_d/ecc.py @@ -4,9 +4,6 @@ test.modtest_d.ecc: elliptic curve unit test for the MMGen suite """ -import ecdsa -from py_ecc.secp256k1.secp256k1 import ecdsa_raw_sign - from mmgen.proto.secp256k1.secp256k1 import ( pubkey_gen, pubkey_tweak_add, @@ -16,17 +13,11 @@ from mmgen.proto.secp256k1.secp256k1 import ( verify_sig) from ..include.common import vmsg -from ..include.ecc import pubkey_tweak_add_pyecdsa +from ..include.ecc import pubkey_tweak_add_pyecdsa, sign_msghash_pyecdsa, verify_sig_pyecdsa from mmgen.protocol import CoinProtocol secp256k1_group_order = CoinProtocol.Secp256k1.secp256k1_group_order -def sign_msghash_pyecc(msghash, privkey): - v, r, s = ecdsa_raw_sign(msghash, privkey) - return ( - r.to_bytes(length=32) + s.to_bytes(length=32), - v - 27) - class unit_tests: def sig_ops(self, name, ut): @@ -44,17 +35,16 @@ class unit_tests: vmsg(f' privkey: {privkey.hex()}') pubkey = pubkey_gen(privkey, 1) sig, recid = sign_msghash(msghash, privkey) - sig_chk, _ = sign_msghash_pyecc(msghash, privkey) + sig_chk = sign_msghash_pyecdsa(msghash, privkey) if sig != sig_chk: import time from mmgen.util import ymsg - ymsg('Warning: signature (libsecp256k1) does not match reference value (py_ecc)!') + ymsg(f'Warning: signature ({sig.hex()}) doesn’t match reference value ({sig_chk.hex()})!') time.sleep(1) vmsg(f' recid: {recid}') assert recid in (0, 1) - ec_pubkey = ecdsa.VerifyingKey.from_string(pubkey, curve=ecdsa.curves.SECP256k1) - assert ec_pubkey.verify_digest(sig, msghash), 'signature verification failed (py-ecdsa)' assert verify_sig(sig, msghash, pubkey) == 1, 'signature verification failed (secp256k1)' + assert verify_sig_pyecdsa(sig, msghash, pubkey) == 1, 'signature verification failed (ecdsa)' pubkey_rec = pubkey_recover(msghash, sig, recid, True) assert pubkey == pubkey_rec, f'{pubkey.hex()} != {pubkey_rec.hex()}' return True diff --git a/test/modtest_d/testdep.py b/test/modtest_d/testdep.py index 5fbc20d6..466dcc13 100755 --- a/test/modtest_d/testdep.py +++ b/test/modtest_d/testdep.py @@ -67,8 +67,3 @@ class unit_tests: def ssh_socks_proxy(self, name, ut): from test.cmdtest_d.include.proxy import TestProxy return TestProxy(None, cfg) - - def py_ecc(self, name, ut): - from py_ecc.secp256k1 import privtopub - privtopub(b'f' * 32) - return True