diff --git a/README.rst b/README.rst index a7b8dc0..614dcb5 100644 --- a/README.rst +++ b/README.rst @@ -37,12 +37,12 @@ To install the latest version:: Optional C Extension ==================== -PyOTA has an optional C extension that improves the performance of its +PyOTA has optional C extensions that improve the performance of its cryptography features significantly (speedups of **60x** are common!). -To install this extension, use the following command:: +To install these extensions, use the following command:: - pip install pyota[ccurl] + pip install pyota[speedups] Installing from Source diff --git a/iota/crypto/kerl/__init__.py b/iota/crypto/kerl/__init__.py index 094b795..9ff9c2c 100644 --- a/iota/crypto/kerl/__init__.py +++ b/iota/crypto/kerl/__init__.py @@ -2,4 +2,11 @@ from __future__ import absolute_import, division, print_function, \ unicode_literals -from .pykerl import * + +try: + from ckerl import Kerl, trits_to_bytes, bytes_to_trits, trits_to_trytes, \ + trytes_to_trits +except ImportError: + from .pykerl import Kerl + from .conv import trits_to_bytes, bytes_to_trits, trits_to_trytes, \ + trytes_to_trits diff --git a/iota/crypto/kerl/conv.py b/iota/crypto/kerl/conv.py index 5541fa1..18feb2d 100644 --- a/iota/crypto/kerl/conv.py +++ b/iota/crypto/kerl/conv.py @@ -57,13 +57,13 @@ def trits_to_trytes(trits): return ''.join(trytes) -def convertToTrits(bytes_k): +def bytes_to_trits(bytes_k): bigInt = convertBytesToBigInt(bytes_k) trits = convertBigintToBase(bigInt, 3, TRIT_HASH_LENGTH) return trits -def convertToBytes(trits): +def trits_to_bytes(trits): bigInt = convertBaseToBigint(trits, 3) bytes_k = convertBigintToBytes(bigInt) return bytes_k diff --git a/iota/crypto/kerl/pykerl.py b/iota/crypto/kerl/pykerl.py index 86edcb5..1a4c437 100644 --- a/iota/crypto/kerl/pykerl.py +++ b/iota/crypto/kerl/pykerl.py @@ -66,7 +66,7 @@ def absorb(self, trits, offset=0, length=None): if stop - offset == TRIT_HASH_LENGTH: trits[stop - 1] = 0 - signed_nums = conv.convertToBytes(trits[offset:stop]) + signed_nums = conv.trits_to_bytes(trits[offset:stop]) # Convert signed bytes into their equivalent unsigned # representation, in order to use Python's built-in bytes @@ -127,7 +127,7 @@ def squeeze(self, trits, offset=0, length=None): signed_hash = [conv.convert_sign(b) for b in unsigned_hash] - trits_from_hash = conv.convertToTrits(signed_hash) + trits_from_hash = conv.bytes_to_trits(signed_hash) trits_from_hash[TRIT_HASH_LENGTH - 1] = 0 stop = min(TRIT_HASH_LENGTH, length - offset) diff --git a/setup.py b/setup.py index 444dfc9..398f72b 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,8 @@ extras_require = { 'ccurl': ['pyota-ccurl'], + 'ckerl': ['ckerl'], + 'speedups': ['pyota-ccurl', 'ckerl'], 'docs-builder': ['sphinx', 'sphinx_rtd_theme'], 'test-runner': ['detox'] + tests_require, }, diff --git a/test/crypto/kerl/pykerl_test.py b/test/crypto/kerl/pykerl_test.py index 3e48169..72db0bb 100644 --- a/test/crypto/kerl/pykerl_test.py +++ b/test/crypto/kerl/pykerl_test.py @@ -10,7 +10,7 @@ from sha3 import keccak_384 from iota.crypto.kerl import Kerl -from iota.crypto.kerl.conv import convertToBytes, convertToTrits, \ +from iota.crypto.kerl import trits_to_bytes, bytes_to_trits, \ trits_to_trytes, trytes_to_trits @@ -105,16 +105,16 @@ def test_input_greater_243(self): def test_all_bytes(self): for i in range(-128, 128): in_bytes = [i] * 48 - trits = convertToTrits(in_bytes) - out_bytes = convertToBytes(trits) + trits = bytes_to_trits(in_bytes) + out_bytes = trits_to_bytes(trits) self.assertEqual(in_bytes, out_bytes) def test_random_trits(self): in_trits = [randrange(-1,2) for _ in range(243)] in_trits[242] = 0 - in_bytes = convertToBytes(in_trits) - out_trits = convertToTrits(in_bytes) + in_bytes = trits_to_bytes(in_trits) + out_trits = bytes_to_trits(in_bytes) self.assertEqual(in_trits, out_trits)