This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from libp2p/raul-review
- Loading branch information
Showing
13 changed files
with
338 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
package noise | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
) | ||
|
||
func (s *secureSession) encrypt(plaintext []byte) (ciphertext []byte, err error) { | ||
// 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") | ||
} | ||
|
||
// TODO: use pre-allocated buffers | ||
ciphertext = s.enc.Encrypt(nil, nil, plaintext) | ||
return ciphertext, nil | ||
return s.enc.Encrypt(out, nil, plaintext), nil | ||
} | ||
|
||
func (s *secureSession) decrypt(ciphertext []byte) (plaintext []byte, err error) { | ||
// 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") | ||
} | ||
|
||
// TODO: use pre-allocated buffers | ||
return s.dec.Decrypt(nil, nil, ciphertext) | ||
return s.dec.Decrypt(out, nil, ciphertext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
module github.com/libp2p/go-libp2p-noise | ||
|
||
go 1.12 | ||
go 1.14 | ||
|
||
require ( | ||
github.com/ChainSafe/log15 v1.0.0 | ||
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 | ||
github.com/gogo/protobuf v1.3.1 | ||
github.com/golang/protobuf v1.3.4 | ||
github.com/ipfs/go-log v1.0.4 | ||
github.com/libp2p/go-libp2p v0.7.2 | ||
github.com/libp2p/go-libp2p-core v0.3.1 | ||
github.com/libp2p/go-msgio v0.0.4 | ||
github.com/libp2p/go-buffer-pool v0.0.2 | ||
github.com/libp2p/go-libp2p v0.8.1 | ||
github.com/libp2p/go-libp2p-core v0.5.1 | ||
github.com/multiformats/go-multiaddr v0.2.1 | ||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 | ||
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 | ||
) |
Oops, something went wrong.