@@ -84,39 +84,47 @@ func Precompute(sharedKey, peersPublicKey, privateKey *[32]byte) {
84
84
}
85
85
86
86
// 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.
89
90
func Seal (out , message []byte , nonce * [24 ]byte , peersPublicKey , privateKey * [32 ]byte ) []byte {
90
91
var sharedKey [32 ]byte
91
92
Precompute (& sharedKey , peersPublicKey , privateKey )
92
93
return secretbox .Seal (out , message , nonce , & sharedKey )
93
94
}
94
95
95
96
// 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.
97
100
func SealAfterPrecomputation (out , message []byte , nonce * [24 ]byte , sharedKey * [32 ]byte ) []byte {
98
101
return secretbox .Seal (out , message , nonce , sharedKey )
99
102
}
100
103
101
104
// Open authenticates and decrypts a box produced by Seal and appends the
102
105
// 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.
104
109
func Open (out , box []byte , nonce * [24 ]byte , peersPublicKey , privateKey * [32 ]byte ) ([]byte , bool ) {
105
110
var sharedKey [32 ]byte
106
111
Precompute (& sharedKey , peersPublicKey , privateKey )
107
112
return secretbox .Open (out , box , nonce , & sharedKey )
108
113
}
109
114
110
115
// 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.
112
119
func OpenAfterPrecomputation (out , box []byte , nonce * [24 ]byte , sharedKey * [32 ]byte ) ([]byte , bool ) {
113
120
return secretbox .Open (out , box , nonce , sharedKey )
114
121
}
115
122
116
123
// SealAnonymous appends an encrypted and authenticated copy of message to out,
117
124
// which will be AnonymousOverhead bytes longer than the original and must not
118
125
// 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.
120
128
func SealAnonymous (out , message []byte , recipient * [32 ]byte , rand io.Reader ) ([]byte , error ) {
121
129
if rand == nil {
122
130
rand = cryptorand .Reader
0 commit comments