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

Commit 623d3bd

Browse files
committed
[UNSTABLE][#61] Addressed some unit test failures.
1 parent 75a7ce3 commit 623d3bd

File tree

3 files changed

+571
-548
lines changed

3 files changed

+571
-548
lines changed

iota/crypto/kerl/pykerl.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ def __init__(self):
2020
self.reset()
2121

2222
def absorb(self, trits, offset=0, length=None):
23+
# Pad input if necessary, so that it can be divided evenly into
24+
# hashes.
25+
pad = ((len(trits) % TRIT_HASH_LENGTH) or TRIT_HASH_LENGTH)
26+
trits += [0] * (TRIT_HASH_LENGTH - pad)
27+
2328
if length is None:
2429
length = len(trits)
2530

26-
if length % 243:
31+
if length < 1:
2732
raise with_context(
28-
exc = ValueError('Illegal length (s/b divisible by 243).'),
33+
exc = ValueError('Invalid length passed to ``absorb``.'),
2934

3035
context = {
36+
'trits': trits,
37+
'offset': offset,
3138
'length': length,
3239
},
3340
)
@@ -49,12 +56,24 @@ def absorb(self, trits, offset=0, length=None):
4956

5057
offset += TRIT_HASH_LENGTH
5158

52-
def squeeze(self, trits, offset=0, length=TRIT_HASH_LENGTH):
53-
if length % 243:
59+
def squeeze(self, trits, offset=0, length=None):
60+
# Pad input if necessary, so that it can be divided evenly into
61+
# hashes.
62+
pad = ((len(trits) % TRIT_HASH_LENGTH) or TRIT_HASH_LENGTH)
63+
trits += [0] * (TRIT_HASH_LENGTH - pad)
64+
65+
if length is None:
66+
# By default, we will try to squeeze one hash.
67+
# Note that this is different than ``absorb``.
68+
length = len(trits) or TRIT_HASH_LENGTH
69+
70+
if length < 1:
5471
raise with_context(
55-
exc = ValueError('Illegal length (s/b divisible by 243).'),
72+
exc = ValueError('Invalid length passed to ``squeeze``.'),
5673

5774
context = {
75+
'trits': trits,
76+
'offset': offset,
5877
'length': length,
5978
},
6079
)

iota/crypto/signing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ def __init__(self, seed, start, step, security_level):
238238
},
239239
)
240240

241+
# In order to work correctly, the seed must be padded so that it is
242+
# a multiple of 81 trytes.
243+
pad = (len(seed) % Hash.LEN) or Hash.LEN
244+
self.seed = seed + b'9' * (Hash.LEN - pad)
245+
241246
self.security_level = security_level
242-
self.seed = seed
243247
self.start = start
244248
self.step = step
245249

0 commit comments

Comments
 (0)