Add tests for domain separated h2c (#451)

* add tests for domain separated h2c

* refactor b_dhke and add domain separated test
This commit is contained in:
callebtc
2024-02-21 11:10:50 +01:00
committed by GitHub
parent c630fc8c40
commit e2c8f7f694
2 changed files with 101 additions and 6 deletions

View File

@@ -136,12 +136,17 @@ def verify(a: PrivateKey, C: PublicKey, secret_msg: str) -> bool:
valid = C == Y.mult(a) # type: ignore
# BEGIN: BACKWARDS COMPATIBILITY < 0.15.1
if not valid:
Y1: PublicKey = hash_to_curve_domain_separated(secret_msg.encode("utf-8"))
return C == Y1.mult(a) # type: ignore
return verify_domain_separated(a, C, secret_msg)
# END: BACKWARDS COMPATIBILITY < 0.15.1
return valid
def verify_domain_separated(a: PrivateKey, C: PublicKey, secret_msg: str) -> bool:
Y: PublicKey = hash_to_curve_domain_separated(secret_msg.encode("utf-8"))
valid = C == Y.mult(a) # type: ignore
return valid
def hash_e(*publickeys: PublicKey) -> bytes:
e_ = ""
for p in publickeys:
@@ -197,13 +202,26 @@ def carol_verify_dleq(
valid = alice_verify_dleq(B_, C_, e, s, A)
# BEGIN: BACKWARDS COMPATIBILITY < 0.15.1
if not valid:
Y1: PublicKey = hash_to_curve_domain_separated(secret_msg.encode("utf-8"))
B_1: PublicKey = Y1 + r.pubkey # type: ignore
return alice_verify_dleq(B_1, C_, e, s, A)
return carol_verify_dleq_domain_separated(secret_msg, r, C, e, s, A)
# END: BACKWARDS COMPATIBILITY < 0.15.1
return valid
def carol_verify_dleq_domain_separated(
secret_msg: str,
r: PrivateKey,
C: PublicKey,
e: PrivateKey,
s: PrivateKey,
A: PublicKey,
) -> bool:
Y: PublicKey = hash_to_curve_domain_separated(secret_msg.encode("utf-8"))
C_: PublicKey = C + A.mult(r) # type: ignore
B_: PublicKey = Y + r.pubkey # type: ignore
valid = alice_verify_dleq(B_, C_, e, s, A)
return valid
# Below is a test of a simple positive and negative case
# # Alice's keys