tlnonion: use random starting bytes in Sphinx packet as in updated BOLT4 - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
DIR commit 5e59d1a0ed773fbb64f2660ef47957e2f4740308
DIR parent 510399d3d258fef76a390786ad447bba40a2871b
HTML Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 16 Mar 2020 04:37:52 +0100
lnonion: use random starting bytes in Sphinx packet as in updated BOLT4
see https://github.com/lightningnetwork/lightning-rfc/pull/697
Diffstat:
M electrum/lnonion.py | 8 ++++++--
M electrum/tests/test_lnrouter.py | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
---
DIR diff --git a/electrum/lnonion.py b/electrum/lnonion.py
t@@ -134,7 +134,7 @@ class OnionPacket:
def get_bolt04_onion_key(key_type: bytes, secret: bytes) -> bytes:
- if key_type not in (b'rho', b'mu', b'um', b'ammag'):
+ if key_type not in (b'rho', b'mu', b'um', b'ammag', b'pad'):
raise Exception('invalid key_type {}'.format(key_type))
key = hmac_oneshot(key_type, msg=secret, digest=hashlib.sha256)
return key
t@@ -163,9 +163,13 @@ def new_onion_packet(payment_path_pubkeys: Sequence[bytes], session_key: bytes,
hop_shared_secrets = get_shared_secrets_along_route(payment_path_pubkeys, session_key)
filler = generate_filler(b'rho', num_hops, PER_HOP_FULL_SIZE, hop_shared_secrets)
- mix_header = bytes(HOPS_DATA_SIZE)
next_hmac = bytes(PER_HOP_HMAC_SIZE)
+ # Our starting packet needs to be filled out with random bytes, we
+ # generate some determinstically using the session private key.
+ pad_key = get_bolt04_onion_key(b'pad', session_key)
+ mix_header = generate_cipher_stream(pad_key, HOPS_DATA_SIZE)
+
# compute routing info and MAC for each hop
for i in range(num_hops-1, -1, -1):
rho_key = get_bolt04_onion_key(b'rho', hop_shared_secrets[i])
DIR diff --git a/electrum/tests/test_lnrouter.py b/electrum/tests/test_lnrouter.py
t@@ -141,7 +141,7 @@ class Test_LNRouter(TestCaseForTestnet):
)),
]
packet = new_onion_packet(payment_path_pubkeys, session_key, hops_data, associated_data)
parazyd.org:70 /git/electrum/commit/5e59d1a0ed773fbb64f2660ef47957e2f4740308.gph:53: line too long