Skip to content

Commit f1cd792

Browse files
committed
Adapt to changes to CKDh in ZIP 32.
Signed-off-by: Daira-Emma Hopwood <[email protected]>
1 parent 99238f9 commit f1cd792

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

zcash_test_vectors/zip_0032.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def MKGh(Context, IKM):
2626
I_R = I[32:]
2727
return (I_L, I_R)
2828

29-
def CKDh(Context, sk_par, c_par, i, tag, full_width_leaf):
29+
def CKDh(Context, sk_par, c_par, i, lead, tag):
3030
assert type(Context) == HardenedOnlyContext
3131
assert 0x80000000 <= i and i <= 0xFFFFFFFF
32+
assert type(lead) == int
3233
assert type(tag) == bytes
33-
assert type(full_width_leaf) == bool
3434

35-
leaf = b"" if tag == b"" and not full_width_leaf else int(full_width_leaf).to_bytes()
36-
I = prf_expand(c_par, Context.CKDDomain + sk_par + i2leosp(32, i) + leaf + tag)
35+
lead_enc = bytes([] if lead == 0 and tag == b"" else [lead])
36+
I = prf_expand(c_par, Context.CKDDomain + sk_par + i2leosp(32, i) + lead_enc + tag)
3737
I_L = I[:32]
3838
I_R = I[32:]
3939
return (I_L, I_R)
@@ -62,12 +62,12 @@ def master(cls, ContextString, S):
6262
return cls(IKM, [], sk, chaincode)
6363

6464
def child(self, i):
65-
(sk_child, c_child) = CKDh(self.Context, self.sk, self.chaincode, i, b"", False)
65+
(sk_child, c_child) = CKDh(self.Context, self.sk, self.chaincode, i, 0, b"")
6666
return self.__class__(None, self.path + [i], sk_child, c_child)
6767

6868
def child_with_tag(self, i, tag):
69-
(sk_child, c_child) = CKDh(self.Context, self.sk, self.chaincode, i, tag, False)
70-
(left, right) = CKDh(self.Context, self.sk, self.chaincode, i, tag, True)
69+
(sk_child, c_child) = CKDh(self.Context, self.sk, self.chaincode, i, 0, tag)
70+
(left, right) = CKDh(self.Context, self.sk, self.chaincode, i, 1, tag)
7171
return self.__class__(None, self.path + [(i, tag)], sk_child, c_child, left + right)
7272

7373

0 commit comments

Comments
 (0)