mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
40359f9c1b
* Adding wakunode module * Adding wakuv2 fleet files * Add waku fleets to update-fleet-config script * Adding config items for waku v2 * Conditionally start waku v2 node depending on config * Adapting common code to use go-waku * Setting log level to info * update dependencies * update fleet config to use WakuNodes instead of BootNodes * send and receive messages * use hash returned when publishing a message * add waku store protocol * trigger signal after receiving store messages * exclude linting rule SA1019 to check deprecated packages
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package noise
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
// encrypt calls the cipher's encryption. It encrypts the provided plaintext,
|
|
// slice-appending the ciphertext on out.
|
|
//
|
|
// Usually you want to pass a 0-len slice to this method, with enough capacity
|
|
// to accommodate the ciphertext in order to spare allocs.
|
|
//
|
|
// encrypt returns a new slice header, whose len is the length of the resulting
|
|
// ciphertext, including the authentication tag.
|
|
//
|
|
// This method will not allocate if the supplied slice is large enough to
|
|
// accommodate the encrypted data + authentication tag. If so, the returned
|
|
// slice header should be a view of the original slice.
|
|
//
|
|
// With the poly1305 MAC function that noise-libp2p uses, the authentication tag
|
|
// adds an overhead of 16 bytes.
|
|
func (s *secureSession) encrypt(out, plaintext []byte) ([]byte, error) {
|
|
if s.enc == nil {
|
|
return nil, errors.New("cannot encrypt, handshake incomplete")
|
|
}
|
|
return s.enc.Encrypt(out, nil, plaintext), nil
|
|
}
|
|
|
|
// decrypt calls the cipher's decryption. It decrypts the provided ciphertext,
|
|
// slice-appending the plaintext on out.
|
|
//
|
|
// Usually you want to pass a 0-len slice to this method, with enough capacity
|
|
// to accommodate the plaintext in order to spare allocs.
|
|
//
|
|
// decrypt returns a new slice header, whose len is the length of the resulting
|
|
// plaintext, without the authentication tag.
|
|
//
|
|
// This method will not allocate if the supplied slice is large enough to
|
|
// accommodate the plaintext. If so, the returned slice header should be a view
|
|
// of the original slice.
|
|
func (s *secureSession) decrypt(out, ciphertext []byte) ([]byte, error) {
|
|
if s.dec == nil {
|
|
return nil, errors.New("cannot decrypt, handshake incomplete")
|
|
}
|
|
return s.dec.Decrypt(out, nil, ciphertext)
|
|
}
|