From 595ad4b16880ae1f23463ca9985381c8eae945d8 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Thu, 6 Oct 2022 22:11:46 +0530 Subject: [PATCH] [test/crypto] Add ECDH Co-authored-by: Pieter Wuille --- test/functional/test_framework/v2_p2p.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/functional/test_framework/v2_p2p.py diff --git a/test/functional/test_framework/v2_p2p.py b/test/functional/test_framework/v2_p2p.py new file mode 100644 index 00000000000..6a3e7690085 --- /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)