From 5a7e0f33fe390a504d3e1ea0c722dccd4b16c02d Mon Sep 17 00:00:00 2001 From: "Sergey B." Date: Mon, 30 Mar 2026 16:49:34 +0300 Subject: [PATCH] doc: note about function modifying its input --- crypto.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crypto.go b/crypto.go index 6b1b49e..a845fb0 100644 --- a/crypto.go +++ b/crypto.go @@ -206,7 +206,10 @@ func blindBaseElement(blindingFactor btcec.ModNScalar) *btcec.PublicKey { // chacha20polyEncrypt initialises the ChaCha20Poly1305 algorithm with the given // key and uses it to encrypt the passed message. This uses an all-zero nonce as -// required by the route-blinding spec. +// required by the route-blinding spec. The function avoids heap allocation by +// reusing the existing backing array. +// +// Warning: the function modifies plainTxt func chacha20polyEncrypt(key, plainTxt []byte) ([]byte, error) { aead, err := chacha20poly1305.New(key) if err != nil { @@ -219,7 +222,10 @@ func chacha20polyEncrypt(key, plainTxt []byte) ([]byte, error) { // chacha20polyDecrypt initialises the ChaCha20Poly1305 algorithm with the given // key and uses it to decrypt the passed cipher text. This uses an all-zero -// nonce as required by the route-blinding spec. +// nonce as required by the route-blinding spec. The function avoids heap +// allocation by reusing the existing backing array. +// +// Warning: the function modifies cipherTxt func chacha20polyDecrypt(key, cipherTxt []byte) ([]byte, error) { aead, err := chacha20poly1305.New(key) if err != nil {