remove bytes.Copy
replace all calls with calls to copy use copy in regexp and bytes.Buffer R=rsc CC=golang-dev https://golang.org/cl/157073
This commit is contained in:
父節點
d1f931a694
當前提交
a1e7e65e2d
@ -4,10 +4,6 @@
|
||||
|
||||
package tls
|
||||
|
||||
import (
|
||||
"bytes";
|
||||
)
|
||||
|
||||
type clientHelloMsg struct {
|
||||
raw []byte;
|
||||
major, minor uint8;
|
||||
@ -30,9 +26,9 @@ func (m *clientHelloMsg) marshal() []byte {
|
||||
x[3] = uint8(length);
|
||||
x[4] = m.major;
|
||||
x[5] = m.minor;
|
||||
bytes.Copy(x[6:38], m.random);
|
||||
copy(x[6:38], m.random);
|
||||
x[38] = uint8(len(m.sessionId));
|
||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||
y := x[39+len(m.sessionId) : len(x)];
|
||||
y[0] = uint8(len(m.cipherSuites) >> 7);
|
||||
y[1] = uint8(len(m.cipherSuites) << 1);
|
||||
@ -42,7 +38,7 @@ func (m *clientHelloMsg) marshal() []byte {
|
||||
}
|
||||
z := y[2+len(m.cipherSuites)*2 : len(y)];
|
||||
z[0] = uint8(len(m.compressionMethods));
|
||||
bytes.Copy(z[1:len(z)], m.compressionMethods);
|
||||
copy(z[1:len(z)], m.compressionMethods);
|
||||
m.raw = x;
|
||||
|
||||
return x;
|
||||
@ -112,9 +108,9 @@ func (m *serverHelloMsg) marshal() []byte {
|
||||
x[3] = uint8(length);
|
||||
x[4] = m.major;
|
||||
x[5] = m.minor;
|
||||
bytes.Copy(x[6:38], m.random);
|
||||
copy(x[6:38], m.random);
|
||||
x[38] = uint8(len(m.sessionId));
|
||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||
z := x[39+len(m.sessionId) : len(x)];
|
||||
z[0] = uint8(m.cipherSuite >> 8);
|
||||
z[1] = uint8(m.cipherSuite);
|
||||
@ -156,7 +152,7 @@ func (m *certificateMsg) marshal() (x []byte) {
|
||||
y[0] = uint8(len(slice) >> 16);
|
||||
y[1] = uint8(len(slice) >> 8);
|
||||
y[2] = uint8(len(slice));
|
||||
bytes.Copy(y[3:len(y)], slice);
|
||||
copy(y[3:len(y)], slice);
|
||||
y = y[3+len(slice) : len(y)];
|
||||
}
|
||||
|
||||
@ -189,7 +185,7 @@ func (m *clientKeyExchangeMsg) marshal() []byte {
|
||||
x[3] = uint8(length);
|
||||
x[4] = uint8(len(m.ciphertext) >> 8);
|
||||
x[5] = uint8(len(m.ciphertext));
|
||||
bytes.Copy(x[6:len(x)], m.ciphertext);
|
||||
copy(x[6:len(x)], m.ciphertext);
|
||||
|
||||
m.raw = x;
|
||||
return x;
|
||||
@ -221,7 +217,7 @@ func (m *finishedMsg) marshal() (x []byte) {
|
||||
x = make([]byte, 16);
|
||||
x[0] = typeFinished;
|
||||
x[3] = 12;
|
||||
bytes.Copy(x[4:len(x)], m.verifyData);
|
||||
copy(x[4:len(x)], m.verifyData);
|
||||
m.raw = x;
|
||||
return;
|
||||
}
|
||||
|
19
prf.go
19
prf.go
@ -5,7 +5,6 @@
|
||||
package tls
|
||||
|
||||
import (
|
||||
"bytes";
|
||||
"crypto/hmac";
|
||||
"crypto/md5";
|
||||
"crypto/sha1";
|
||||
@ -37,7 +36,7 @@ func pHash(result, secret, seed []byte, hash hash.Hash) {
|
||||
if j+todo > len(result) {
|
||||
todo = len(result) - j
|
||||
}
|
||||
bytes.Copy(result[j:j+todo], b);
|
||||
copy(result[j:j+todo], b);
|
||||
j += todo;
|
||||
|
||||
h.Reset();
|
||||
@ -52,8 +51,8 @@ func pRF11(result, secret, label, seed []byte) {
|
||||
hashMD5 := md5.New();
|
||||
|
||||
labelAndSeed := make([]byte, len(label)+len(seed));
|
||||
bytes.Copy(labelAndSeed, label);
|
||||
bytes.Copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
||||
copy(labelAndSeed, label);
|
||||
copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
||||
|
||||
s1, s2 := splitPreMasterSecret(secret);
|
||||
pHash(result, s1, labelAndSeed, hashMD5);
|
||||
@ -81,13 +80,13 @@ var serverFinishedLabel = strings.Bytes("server finished")
|
||||
// 4346, section 6.3.
|
||||
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
|
||||
var seed [tlsRandomLength * 2]byte;
|
||||
bytes.Copy(seed[0:len(clientRandom)], clientRandom);
|
||||
bytes.Copy(seed[len(clientRandom):len(seed)], serverRandom);
|
||||
copy(seed[0:len(clientRandom)], clientRandom);
|
||||
copy(seed[len(clientRandom):len(seed)], serverRandom);
|
||||
masterSecret = make([]byte, masterSecretLength);
|
||||
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]);
|
||||
|
||||
bytes.Copy(seed[0:len(clientRandom)], serverRandom);
|
||||
bytes.Copy(seed[len(serverRandom):len(seed)], clientRandom);
|
||||
copy(seed[0:len(clientRandom)], serverRandom);
|
||||
copy(seed[len(serverRandom):len(seed)], clientRandom);
|
||||
|
||||
n := 2*macLen + 2*keyLen;
|
||||
keyMaterial := make([]byte, n);
|
||||
@ -124,8 +123,8 @@ func (h finishedHash) Write(msg []byte) (n int, err os.Error) {
|
||||
// message given the MD5 and SHA1 hashes of a set of handshake messages.
|
||||
func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
|
||||
seed := make([]byte, len(md5)+len(sha1));
|
||||
bytes.Copy(seed, md5);
|
||||
bytes.Copy(seed[len(md5):len(seed)], sha1);
|
||||
copy(seed, md5);
|
||||
copy(seed[len(md5):len(seed)], sha1);
|
||||
out := make([]byte, finishedVerifyLength);
|
||||
pRF11(out, masterSecret, label, seed);
|
||||
return out;
|
||||
|
@ -10,7 +10,6 @@ package tls
|
||||
// state, or for a notification when the state changes.
|
||||
|
||||
import (
|
||||
"bytes";
|
||||
"container/list";
|
||||
"crypto/subtle";
|
||||
"hash";
|
||||
@ -228,8 +227,8 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) {
|
||||
return;
|
||||
}
|
||||
newBuf := make([]byte, len(p.handshakeBuf)+len(data));
|
||||
bytes.Copy(newBuf, p.handshakeBuf);
|
||||
bytes.Copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
||||
copy(newBuf, p.handshakeBuf);
|
||||
copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
||||
p.handshakeBuf = newBuf;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user