@@ -84,39 +84,47 @@ func Precompute(sharedKey, peersPublicKey, privateKey *[32]byte) {
8484}
8585
8686// Seal appends an encrypted and authenticated copy of message to out, which
87- // will be Overhead bytes longer than the original and must not overlap it. The
88- // nonce must be unique for each distinct message for a given pair of keys.
87+ // will be Overhead bytes longer than the original and must not overlap it.
88+ // The return value is a slice containing the appended output, which may
89+ // point to a newly allocated buffer if out lacks sufficient capacity.
8990func Seal (out , message []byte , nonce * [24 ]byte , peersPublicKey , privateKey * [32 ]byte ) []byte {
9091 var sharedKey [32 ]byte
9192 Precompute (& sharedKey , peersPublicKey , privateKey )
9293 return secretbox .Seal (out , message , nonce , & sharedKey )
9394}
9495
9596// SealAfterPrecomputation performs the same actions as Seal, but takes a
96- // shared key as generated by Precompute.
97+ // shared key as generated by Precompute. The return value is a slice containing
98+ // the appended output, which may point to a newly allocated buffer if out lacks
99+ // sufficient capacity.
97100func SealAfterPrecomputation (out , message []byte , nonce * [24 ]byte , sharedKey * [32 ]byte ) []byte {
98101 return secretbox .Seal (out , message , nonce , sharedKey )
99102}
100103
101104// Open authenticates and decrypts a box produced by Seal and appends the
102105// message to out, which must not overlap box. The output will be Overhead
103- // bytes smaller than box.
106+ // bytes smaller than box. The return value is the updated out slice containing
107+ // the decrypted message and a boolean indicating whether authentication was
108+ // successful.
104109func Open (out , box []byte , nonce * [24 ]byte , peersPublicKey , privateKey * [32 ]byte ) ([]byte , bool ) {
105110 var sharedKey [32 ]byte
106111 Precompute (& sharedKey , peersPublicKey , privateKey )
107112 return secretbox .Open (out , box , nonce , & sharedKey )
108113}
109114
110115// OpenAfterPrecomputation performs the same actions as Open, but takes a
111- // shared key as generated by Precompute.
116+ // shared key as generated by Precompute. The return value is the updated out
117+ // slice containing the decrypted message and a boolean indicating whether
118+ // authentication was successful.
112119func OpenAfterPrecomputation (out , box []byte , nonce * [24 ]byte , sharedKey * [32 ]byte ) ([]byte , bool ) {
113120 return secretbox .Open (out , box , nonce , sharedKey )
114121}
115122
116123// SealAnonymous appends an encrypted and authenticated copy of message to out,
117124// which will be AnonymousOverhead bytes longer than the original and must not
118125// overlap it. This differs from Seal in that the sender is not required to
119- // provide a private key.
126+ // provide a private key. The return value is the updated out slice containing
127+ // the appended output.
120128func SealAnonymous (out , message []byte , recipient * [32 ]byte , rand io.Reader ) ([]byte , error ) {
121129 if rand == nil {
122130 rand = cryptorand .Reader
0 commit comments