mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
[test/crypto] Add ECDH
Co-authored-by: Pieter Wuille <pieter.wuille@gmail.com>
This commit is contained in:
parent
4487b80517
commit
595ad4b168
1 changed files with 20 additions and 0 deletions
20
test/functional/test_framework/v2_p2p.py
Normal file
20
test/functional/test_framework/v2_p2p.py
Normal file
|
@ -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…
Add table
Reference in a new issue