Skip to content

Commit 289a374

Browse files
committed
Hash IDs for better serialization
key = H(idA, idB, X*, Y*, KB) -> key = H(H(idA), H(idB), X*, Y*, KB)
1 parent ddc2c42 commit 289a374

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

spake2/spake2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class ReflectionThwarted(SPAKEError):
3737
# Y = scalarmult(g, y)
3838
# Y* = Y + scalarmult(N, int(pw))
3939
# KA = scalarmult(Y* + scalarmult(N, -int(pw)), x)
40-
# key = H(idA, idB, X*, Y*, KA)
40+
# key = H(H(idA), H(idB), X*, Y*, KA)
4141
# KB = scalarmult(X* + scalarmult(M, -int(pw)), y)
42-
# key = H(idA, idB, X*, Y*, KB)
42+
# key = H(H(idA), H(idB), X*, Y*, KB)
4343

4444
# to serialize intermediate state, just remember x and A-vs-B. And U/V.
4545

@@ -152,9 +152,9 @@ def _extract_message(self, inbound_side_and_message):
152152
return inbound_message
153153

154154
def _make_transcript(self, K_bytes):
155-
return b":".join([self.idA, self.idB,
156-
self.X_msg(), self.Y_msg(), K_bytes,
157-
self.pw])
155+
return b"".join([sha256(self.idA).digest(), sha256(self.idB).digest(),
156+
self.X_msg(), self.Y_msg(), K_bytes,
157+
self.pw])
158158

159159
def _serialize_to_dict(self):
160160
g = self.params.group
@@ -231,9 +231,9 @@ def _make_transcript(self, K_bytes):
231231
# since we don't know which side is which, we must sort the messages
232232
first_msg, second_msg = sorted([self.inbound_message,
233233
self.outbound_message])
234-
return b":".join([self.idSymmetric,
235-
first_msg, second_msg, K_bytes,
236-
self.pw])
234+
return b"".join([sha256(self.idSymmetric).digest(),
235+
first_msg, second_msg, K_bytes,
236+
self.pw])
237237

238238
def hash_params(self):
239239
g = self.params.group

0 commit comments

Comments
 (0)