From e9033f0d2d15996ab0349a93b2310af0ae505f10 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:29:07 +0100 Subject: [PATCH 1/3] add step2 domain separated test --- cashu/core/crypto/b_dhke.py | 2 +- tests/test_crypto.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cashu/core/crypto/b_dhke.py b/cashu/core/crypto/b_dhke.py index ad7ba1aa..78b3510f 100644 --- a/cashu/core/crypto/b_dhke.py +++ b/cashu/core/crypto/b_dhke.py @@ -136,7 +136,7 @@ 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: - return verify_domain_separated(a, C, secret_msg) + valid = verify_domain_separated(a, C, secret_msg) # END: BACKWARDS COMPATIBILITY < 0.15.1 return valid diff --git a/tests/test_crypto.py b/tests/test_crypto.py index a74e8b56..0613aff6 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -352,6 +352,29 @@ def test_step1_domain_separated(): ) +def test_step2_domain_separated(): + B_, _ = step1_alice_domain_separated( + "test_message", + blinding_factor=PrivateKey( + privkey=bytes.fromhex( + "0000000000000000000000000000000000000000000000000000000000000001" + ), + raw=True, + ), + ) + a = PrivateKey( + privkey=bytes.fromhex( + "0000000000000000000000000000000000000000000000000000000000000001" + ), + raw=True, + ) + C_, e, s = step2_bob(B_, a) + assert ( + C_.serialize().hex() + == "025cc16fe33b953e2ace39653efb3e7a7049711ae1d8a2f7a9108753f1cdea742b" + ) + + def test_dleq_carol_verify_from_bob_domain_separated(): a = PrivateKey( privkey=bytes.fromhex( From 5a86f1180f6a9908802d14aaf917ec08b53c3dff Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:32:04 +0100 Subject: [PATCH 2/3] add test3 derived from domain separated outputs --- tests/test_crypto.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 0613aff6..f169e988 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -94,6 +94,7 @@ def test_step2(): def test_step3(): # C = C_ - A.mult(r) + # B_ from test_step1 C_ = PublicKey( bytes.fromhex( "02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2" @@ -375,6 +376,36 @@ def test_step2_domain_separated(): ) +def test_step3_domain_separated(): + # C = C_ - A.mult(r) + # B_ from test_step1 + C_ = PublicKey( + bytes.fromhex( + "025cc16fe33b953e2ace39653efb3e7a7049711ae1d8a2f7a9108753f1cdea742b" + ), + raw=True, + ) + r = PrivateKey( + privkey=bytes.fromhex( + "0000000000000000000000000000000000000000000000000000000000000001" + ) + ) + + A = PublicKey( + pubkey=b"\x02" + + bytes.fromhex( + "0000000000000000000000000000000000000000000000000000000000000001", + ), + raw=True, + ) + C = step3_alice(C_, r, A) + + assert ( + C.serialize().hex() + == "0271bf0d702dbad86cbe0af3ab2bfba70a0338f22728e412d88a830ed0580b9de4" + ) + + def test_dleq_carol_verify_from_bob_domain_separated(): a = PrivateKey( privkey=bytes.fromhex( From 3629e748afcc10ef8e4984071c507a8dbb689698 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:35:00 +0100 Subject: [PATCH 3/3] Fix comment --- tests/test_crypto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_crypto.py b/tests/test_crypto.py index f169e988..279145a6 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -94,7 +94,7 @@ def test_step2(): def test_step3(): # C = C_ - A.mult(r) - # B_ from test_step1 + # C_ from test_step2 C_ = PublicKey( bytes.fromhex( "02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2" @@ -378,7 +378,7 @@ def test_step2_domain_separated(): def test_step3_domain_separated(): # C = C_ - A.mult(r) - # B_ from test_step1 + # C_ from test_step2 C_ = PublicKey( bytes.fromhex( "025cc16fe33b953e2ace39653efb3e7a7049711ae1d8a2f7a9108753f1cdea742b"