|
|
@ -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 |
|
|
@ -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]) |
|
|
|