Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
crypto performance help
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Apr 25, 2018
1 parent f83651f commit bc0e459
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Expand Up @@ -5,7 +5,7 @@ History
0.3.11-dev (work in progress)
-----------------------------
* ``np-utils`` cli tool (see ``cli.py``, `PR #40 <https://github.com/CityOfZion/neo-python-core/pull/40>`_)

* alter initialization of Crypto signature curve

0.3.10 (2018-03-21)
----------------------------
Expand Down
12 changes: 9 additions & 3 deletions neocore/Cryptography/Crypto.py
Expand Up @@ -8,11 +8,14 @@

class Crypto(object):

_Instance = None

@staticmethod
def SetupSignatureCurve():
"""
Setup the Elliptic curve parameters.
"""
print("CHANGING BITCOIN CURVE!")
bitcoin.change_curve(
int("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16),
int("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16),
Expand All @@ -30,7 +33,9 @@ def Default():
Returns:
CryptoInstance:
"""
return CryptoInstance()
if not Crypto._Instance:
Crypto._Instance = CryptoInstance()
return Crypto._Instance

@staticmethod
def Hash160(message):
Expand Down Expand Up @@ -109,7 +114,6 @@ def Sign(message, private_key):
Returns:
bytearray: the signature of the message.
"""
Crypto.SetupSignatureCurve()

hash = hashlib.sha256(binascii.unhexlify(message)).hexdigest()

Expand All @@ -135,7 +139,6 @@ def VerifySignature(message, signature, public_key):
Returns:
bool: True if verification passes. False otherwise.
"""
Crypto.SetupSignatureCurve()

if type(public_key) is EllipticCurve.ECPoint:
pubkey_x = public_key.x.value.to_bytes(32, 'big')
Expand Down Expand Up @@ -165,6 +168,9 @@ def VerifySignature(message, signature, public_key):

class CryptoInstance():

def __init__(self):
Crypto.SetupSignatureCurve()

def Hash160(self, message):
"""
Get a hash of the provided message using the ripemd160 algorithm.
Expand Down

0 comments on commit bc0e459

Please sign in to comment.