Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
sergey3bv marked this conversation as resolved.
func chacha20polyEncrypt(key, plainTxt []byte) ([]byte, error) {
aead, err := chacha20poly1305.New(key)
if err != nil {
Expand All @@ -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
Comment thread
sergey3bv marked this conversation as resolved.
func chacha20polyDecrypt(key, cipherTxt []byte) ([]byte, error) {
aead, err := chacha20poly1305.New(key)
if err != nil {
Expand Down