diff options
author | stratospher <44024636+stratospher@users.noreply.github.com> | 2022-10-06 22:11:46 +0530 |
---|---|---|
committer | stratospher <44024636+stratospher@users.noreply.github.com> | 2024-01-23 22:04:55 +0530 |
commit | 595ad4b16880ae1f23463ca9985381c8eae945d8 (patch) | |
tree | a217ee801b514c9d7f3b9bd72406e625de59a15c /test | |
parent | 4487b8051797173c7ab432e75efa370afb03b529 (diff) |
[test/crypto] Add ECDH
Co-authored-by: Pieter Wuille <pieter.wuille@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/test_framework/v2_p2p.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/functional/test_framework/v2_p2p.py b/test/functional/test_framework/v2_p2p.py new file mode 100644 index 0000000000..6a3e769008 --- /dev/null +++ b/test/functional/test_framework/v2_p2p.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# Copyright (c) 2022 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Class for v2 P2P protocol (see BIP 324)""" + +from .crypto.ellswift import ellswift_ecdh_xonly +from .key import TaggedHash + +class EncryptedP2PState: + @staticmethod + def v2_ecdh(priv, ellswift_theirs, ellswift_ours, initiating): + """Compute BIP324 shared secret.""" + ecdh_point_x32 = ellswift_ecdh_xonly(ellswift_theirs, priv) + if initiating: + # Initiating, place our public key encoding first. + return TaggedHash("bip324_ellswift_xonly_ecdh", ellswift_ours + ellswift_theirs + ecdh_point_x32) + else: + # Responding, place their public key encoding first. + return TaggedHash("bip324_ellswift_xonly_ecdh", ellswift_theirs + ellswift_ours + ecdh_point_x32) |