Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit c1f6d69

Browse files
committed
use ckerl package if installed
1 parent 08230b0 commit c1f6d69

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ To install the latest version::
3737

3838
Optional C Extension
3939
====================
40-
PyOTA has an optional C extension that improves the performance of its
40+
PyOTA has optional C extensions that improve the performance of its
4141
cryptography features significantly (speedups of **60x** are common!).
4242

43-
To install this extension, use the following command::
43+
To install these extensions, use the following command::
4444

45-
pip install pyota[ccurl]
45+
pip install pyota[speedups]
4646

4747

4848
Installing from Source

iota/crypto/kerl/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22
from __future__ import absolute_import, division, print_function, \
33
unicode_literals
44

5-
from .pykerl import *
5+
6+
try:
7+
from ckerl import Kerl, trits_to_bytes, bytes_to_trits, trits_to_trytes, \
8+
trytes_to_trits
9+
except ImportError:
10+
from .pykerl import Kerl
11+
from .conv import trits_to_bytes, bytes_to_trits, trits_to_trytes, \
12+
trytes_to_trits

iota/crypto/kerl/conv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def trits_to_trytes(trits):
5555

5656
return ''.join(trytes)
5757

58-
def convertToTrits(bytes_k):
58+
def bytes_to_trits(bytes_k):
5959
bigInt = convertBytesToBigInt(bytes_k)
6060
trits = convertBigintToBase(bigInt, 3, TRIT_HASH_LENGTH)
6161
return trits
6262

63-
def convertToBytes(trits):
63+
def trits_to_bytes(trits):
6464
bigInt = convertBaseToBigint(trits, 3)
6565
bytes_k = convertBigintToBytes(bigInt)
6666
return bytes_k

iota/crypto/kerl/pykerl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def absorb(self, trits, offset=0, length=None):
6464
if stop - offset == TRIT_HASH_LENGTH:
6565
trits[stop - 1] = 0
6666

67-
signed_nums = conv.convertToBytes(trits[offset:stop])
67+
signed_nums = conv.trits_to_bytes(trits[offset:stop])
6868

6969
# Convert signed bytes into their equivalent unsigned representation
7070
# In order to use Python's built-in bytes type
@@ -122,7 +122,7 @@ def squeeze(self, trits, offset=0, length=None):
122122

123123
signed_hash = [conv.convert_sign(b) for b in unsigned_hash]
124124

125-
trits_from_hash = conv.convertToTrits(signed_hash)
125+
trits_from_hash = conv.bytes_to_trits(signed_hash)
126126
trits_from_hash[TRIT_HASH_LENGTH - 1] = 0
127127

128128
stop = min(TRIT_HASH_LENGTH, length-offset)

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676

7777
extras_require = {
7878
'ccurl': ['pyota-ccurl'],
79+
'ckerl': ['ckerl'],
80+
'speedups': ['pyota-ccurl', 'ckerl'],
7981
'docs-builder': ['sphinx', 'sphinx_rtd_theme'],
8082
'test-runner': ['detox'] + tests_require,
8183
},

test/crypto/kerl/pykerl_test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sha3 import keccak_384
1111

1212
from iota.crypto.kerl import Kerl
13-
from iota.crypto.kerl.conv import convertToBytes, convertToTrits, \
13+
from iota.crypto.kerl import trits_to_bytes, bytes_to_trits, \
1414
trits_to_trytes, trytes_to_trits
1515

1616

@@ -105,16 +105,16 @@ def test_input_greater_243(self):
105105
def test_all_bytes(self):
106106
for i in range(-128, 128):
107107
in_bytes = [i] * 48
108-
trits = convertToTrits(in_bytes)
109-
out_bytes = convertToBytes(trits)
108+
trits = bytes_to_trits(in_bytes)
109+
out_bytes = trits_to_bytes(trits)
110110

111111
self.assertEqual(in_bytes, out_bytes)
112112

113113
def test_random_trits(self):
114114
in_trits = [randrange(-1,2) for _ in range(243)]
115115
in_trits[242] = 0
116-
in_bytes = convertToBytes(in_trits)
117-
out_trits = convertToTrits(in_bytes)
116+
in_bytes = trits_to_bytes(in_trits)
117+
out_trits = bytes_to_trits(in_bytes)
118118

119119
self.assertEqual(in_trits, out_trits)
120120

0 commit comments

Comments
 (0)