Skip to content

Commit

Permalink
Test x-only ECDH
Browse files Browse the repository at this point in the history
  • Loading branch information
stratospher committed Dec 12, 2022
1 parent a9c2165 commit fe10103
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/functional/test_framework/ellswift.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Do not use for anything but tests."""

import random
import unittest

from .key import FE, GE, SECP256K1_G

Expand Down Expand Up @@ -76,3 +77,12 @@ def ellswift_ecdh_xonly(pubkey_theirs, privkey):
t = FE(int.from_bytes(pubkey_theirs[32:], 'big'))
d = int.from_bytes(privkey, 'big')
return (d * GE.lift_x(xswiftec(u, t))).x.to_bytes()

class TestFrameworkEllSwift(unittest.TestCase):
def test_ellswift_ecdh_xonly(self):
for _ in range(32):
privkey1, encoding1 = ellswift_create()
privkey2, encoding2 = ellswift_create()
shared_secret1 = ellswift_ecdh_xonly(encoding1, privkey2)
shared_secret2 = ellswift_ecdh_xonly(encoding2, privkey1)
assert shared_secret1 == shared_secret2
3 changes: 2 additions & 1 deletion test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
TEST_FRAMEWORK_MODULES = [
"address",
"blocktools",
"muhash",
"ellswift",
"key",
"muhash",
"script",
"segwit_addr",
"util",
Expand Down

0 comments on commit fe10103

Please sign in to comment.