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

use kerl package if installed #164

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion iota/crypto/kerl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions iota/crypto/kerl/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions iota/crypto/kerl/pykerl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 5 additions & 5 deletions test/crypto/kerl/pykerl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

Expand Down