Skip to content

Commit

Permalink
Adapt to changes to CKDh in ZIP 32.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
  • Loading branch information
daira committed Feb 20, 2025
1 parent 99238f9 commit f1cd792
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions zcash_test_vectors/zip_0032.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def MKGh(Context, IKM):
I_R = I[32:]
return (I_L, I_R)

def CKDh(Context, sk_par, c_par, i, tag, full_width_leaf):
def CKDh(Context, sk_par, c_par, i, lead, tag):
assert type(Context) == HardenedOnlyContext
assert 0x80000000 <= i and i <= 0xFFFFFFFF
assert type(lead) == int
assert type(tag) == bytes
assert type(full_width_leaf) == bool

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

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

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


Expand Down

0 comments on commit f1cd792

Please sign in to comment.