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

Commit d6b1437

Browse files
committed
[UNSTABLE] Key/Addy gen now uses kerl.
Unit tests have NOT been updated yet. Here we go....
1 parent 24b4913 commit d6b1437

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

iota/crypto/addresses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Generator, Iterable, List, MutableSequence
66

77
from iota import Address, TRITS_PER_TRYTE, TrytesCompatible
8-
from iota.crypto import Curl
8+
from iota.crypto.kerl import Kerl
99
from iota.crypto.signing import KeyGenerator, KeyIterator
1010
from iota.crypto.types import Digest, PrivateKey, Seed
1111
from iota.exceptions import with_context
@@ -157,7 +157,7 @@ def address_from_digest(digest):
157157
"""
158158
address_trits = [0] * (Address.LEN * TRITS_PER_TRYTE) # type: MutableSequence[int]
159159

160-
sponge = Curl()
160+
sponge = Kerl()
161161
sponge.absorb(digest.as_trits())
162162
sponge.squeeze(address_trits)
163163

iota/crypto/signing.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
from six import PY2
88

9-
from iota import TRITS_PER_TRYTE, TryteString, TrytesCompatible, Hash
10-
from iota.crypto import Curl, FRAGMENT_LENGTH, HASH_LENGTH
9+
from iota import Hash, TRITS_PER_TRYTE, TryteString, TrytesCompatible
10+
from iota.crypto import FRAGMENT_LENGTH, HASH_LENGTH
11+
from iota.crypto.kerl import Kerl
1112
from iota.crypto.types import PrivateKey, Seed
1213
from iota.exceptions import with_context
1314

@@ -293,7 +294,7 @@ def advance(self):
293294
self.current += self.step
294295

295296
def _create_sponge(self, index):
296-
# type: (int) -> Curl
297+
# type: (int) -> Kerl
297298
"""
298299
Prepares the Curl sponge for the generator.
299300
"""
@@ -311,7 +312,7 @@ def _create_sponge(self, index):
311312
else:
312313
break
313314

314-
sponge = Curl()
315+
sponge = Kerl()
315316
sponge.absorb(seed)
316317

317318
# Squeeze all of the trits out of the sponge and re-absorb them.
@@ -338,7 +339,7 @@ def __init__(self, private_key, hash_):
338339
self._key_chunks = private_key.iter_chunks(FRAGMENT_LENGTH)
339340
self._iteration = -1
340341
self._normalized_hash = normalize(hash_)
341-
self._sponge = Curl()
342+
self._sponge = Kerl()
342343

343344
def __iter__(self):
344345
# type: () -> SignatureFragmentGenerator
@@ -409,7 +410,7 @@ def validate_signature_fragments(fragments, hash_, public_key):
409410
normalized_hash = normalize(hash_)
410411

411412
for (i, fragment) in enumerate(fragments): # type: Tuple[int, TryteString]
412-
outer_sponge = Curl()
413+
outer_sponge = Kerl()
413414

414415
# If there are more than 3 iterations, loop back around to the
415416
# start.
@@ -418,7 +419,7 @@ def validate_signature_fragments(fragments, hash_, public_key):
418419
buffer = []
419420
for (j, hash_trytes) in enumerate(fragment.iter_chunks(Hash.LEN)): # type: Tuple[int, TryteString]
420421
buffer = hash_trytes.as_trits() # type: MutableSequence[int]
421-
inner_sponge = Curl()
422+
inner_sponge = Kerl()
422423

423424
# Note the sign flip compared to ``SignatureFragmentGenerator``.
424425
for _ in range(13 + normalized_chunk[j]):
@@ -432,7 +433,7 @@ def validate_signature_fragments(fragments, hash_, public_key):
432433
checksum[i*HASH_LENGTH:(i+1)*HASH_LENGTH] = buffer
433434

434435
actual_public_key = [0] * HASH_LENGTH # type: MutableSequence[int]
435-
addy_sponge = Curl()
436+
addy_sponge = Kerl()
436437
addy_sponge.absorb(checksum)
437438
addy_sponge.squeeze(actual_public_key)
438439

iota/crypto/types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from typing import MutableSequence, Optional, Tuple
66

7-
from iota.crypto import Curl, FRAGMENT_LENGTH, HASH_LENGTH
7+
from iota.crypto import FRAGMENT_LENGTH, HASH_LENGTH
8+
from iota.crypto.kerl import Kerl
89
from iota.exceptions import with_context
910
from iota.transaction.base import Bundle
1011
from iota.types import Hash, TryteString, TrytesCompatible
@@ -157,7 +158,7 @@ def get_digest(self):
157158
hash_trits = fragment_trits[hash_start:hash_end] # type: MutableSequence[int]
158159

159160
for k in range(26):
160-
sponge = Curl()
161+
sponge = Kerl()
161162
sponge.absorb(hash_trits)
162163
sponge.squeeze(hash_trits)
163164

@@ -170,7 +171,7 @@ def get_digest(self):
170171
# Note that we will do this once per fragment in the key, so the
171172
# longer the key is, the longer the digest will be.
172173
#
173-
sponge = Curl()
174+
sponge = Kerl()
174175
sponge.absorb(key_fragment)
175176
sponge.squeeze(hash_trits)
176177

0 commit comments

Comments
 (0)