INNER CODE UNIT · Go
chacha20polyEncrypt
lightningnetwork/lightning-onion · crypto.go:210
func chacha20polyEncrypt(key, plainTxt []byte) ([]byte, error) {
aead, err := chacha20poly1305.New(key)
if err != nil {
return nil, err
}
return aead.Seal(plainTxt[:0], chaChaPolyZeroNonce[:], plainTxt, nil),
nil
}
// 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.
func chacha20polyDecrypt(key, cipherTxt []byte) ([]byte, error) {
aead, err := chacha20poly1305.New(key)
if err != nil {
return nil, err
}