Skip to content

Commit 595ad4b

Browse files
stratosphersipa
andcommitted
[test/crypto] Add ECDH
Co-authored-by: Pieter Wuille <[email protected]>
1 parent 4487b80 commit 595ad4b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Class for v2 P2P protocol (see BIP 324)"""
6+
7+
from .crypto.ellswift import ellswift_ecdh_xonly
8+
from .key import TaggedHash
9+
10+
class EncryptedP2PState:
11+
@staticmethod
12+
def v2_ecdh(priv, ellswift_theirs, ellswift_ours, initiating):
13+
"""Compute BIP324 shared secret."""
14+
ecdh_point_x32 = ellswift_ecdh_xonly(ellswift_theirs, priv)
15+
if initiating:
16+
# Initiating, place our public key encoding first.
17+
return TaggedHash("bip324_ellswift_xonly_ecdh", ellswift_ours + ellswift_theirs + ecdh_point_x32)
18+
else:
19+
# Responding, place their public key encoding first.
20+
return TaggedHash("bip324_ellswift_xonly_ecdh", ellswift_theirs + ellswift_ours + ecdh_point_x32)

0 commit comments

Comments
 (0)