crypto: move LN-related chacha20/poly1305 code into crypto.py
This commit is contained in:
@@ -27,10 +27,8 @@ import hashlib
|
||||
from typing import Sequence, List, Tuple, NamedTuple, TYPE_CHECKING
|
||||
from enum import IntEnum, IntFlag
|
||||
|
||||
from Cryptodome.Cipher import ChaCha20
|
||||
|
||||
from . import ecc
|
||||
from .crypto import sha256, hmac_oneshot
|
||||
from .crypto import sha256, hmac_oneshot, chacha20_encrypt
|
||||
from .util import bh2u, profiler, xor_bytes, bfh
|
||||
from .lnutil import (get_ecdh, PaymentFailure, NUM_MAX_HOPS_IN_PAYMENT_PATH,
|
||||
NUM_MAX_EDGES_IN_PAYMENT_PATH, ShortChannelID)
|
||||
@@ -227,8 +225,9 @@ def generate_filler(key_type: bytes, num_hops: int, hop_size: int,
|
||||
|
||||
|
||||
def generate_cipher_stream(stream_key: bytes, num_bytes: int) -> bytes:
|
||||
cipher = ChaCha20.new(key=stream_key, nonce=bytes(8))
|
||||
return cipher.encrypt(bytes(num_bytes))
|
||||
return chacha20_encrypt(key=stream_key,
|
||||
nonce=bytes(8),
|
||||
data=bytes(num_bytes))
|
||||
|
||||
|
||||
class ProcessedOnionPacket(NamedTuple):
|
||||
|
||||
Reference in New Issue
Block a user