]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: remove bookkeeping code from pHash function
authorJoe Kyo <xunianzu@gmail.com>
Mon, 16 Oct 2017 06:25:14 +0000 (07:25 +0100)
committerFilippo Valsorda <hi@filippo.io>
Tue, 31 Oct 2017 19:11:03 +0000 (19:11 +0000)
Since copy function can figure out how many bytes of data to copy when
two slices have different length, it is not necessary to check how many
bytes need to copy each time before copying the data.

Change-Id: I5151ddfe46af5575566fe9c9a2648e111575ec3d
Reviewed-on: https://go-review.googlesource.com/71090
Reviewed-by: Filippo Valsorda <hi@filippo.io>
Run-TryBot: Filippo Valsorda <hi@filippo.io>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/crypto/tls/prf.go

index 27a22f1e3a06429e5e2b0a4bf77a4b3c31f1f2f1..d07be11cddc63fe9300763c4bd4543f1d0319765 100644 (file)
@@ -35,12 +35,8 @@ func pHash(result, secret, seed []byte, hash func() hash.Hash) {
                h.Write(a)
                h.Write(seed)
                b := h.Sum(nil)
-               todo := len(b)
-               if j+todo > len(result) {
-                       todo = len(result) - j
-               }
-               copy(result[j:j+todo], b)
-               j += todo
+               copy(result[j:], b)
+               j += len(b)
 
                h.Reset()
                h.Write(a)