@cryptotaxi247 / kubo / commits / 3994762ca

fix bug

Jeromy committed Oct 26, 2014 at 08:38 UTC 3994762ca6583c8f96f0fb2182405a9b37f5a40d
1 file changed +6 -11
crypto/spipe/handshake.go
+6 -11
@@ -275,7 +275,6 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte)
275
276 myMac, macSize := makeMac(hashType, mMKey)
277
278 - basebuf := make([]byte, 1<<22)
278 for {
279 var data []byte
280 ok := true
@@ -295,23 +294,19 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte)
294 continue
295 }
296
298 - buff := basebuf[:len(data)+macSize]
297 + buff := make([]byte, len(data)+macSize)
298
300 - encData(data, buff, myCipher, myMac)
299 + myCipher.XORKeyStream(buff, data)
300 +
301 + myMac.Write(buff[0:len(data)])
302 + copy(buff[len(data):], myMac.Sum(nil))
303 + myMac.Reset()
304
305 // log.Debug("[peer %s] secure out [to = %s] %d", s.local, s.remote, len(buff))
306 s.insecure.Out <- buff
307 }
308 }
309
307 -func encData(data, buff []byte, ciph cipher.Stream, mac hash.Hash) {
308 - ciph.XORKeyStream(buff, data)
309 -
310 - mac.Write(buff[0:len(data)])
311 - copy(buff[len(data):], mac.Sum(nil))
312 - mac.Reset()
313 -}
314 -
310 // Determines which algorithm to use. Note: f(a, b) = f(b, a)
311 func selectBest(myPrefs, theirPrefs string) (string, error) {
312 // Person with greatest hash gets first choice.