[test/crypto] Add ECDH

Co-authored-by: Pieter Wuille <pieter.wuille@gmail.com>
pull/24748/head
stratospher 2 years ago
parent 4487b80517
commit 595ad4b168

@ -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)
Loading…
Cancel
Save