R=r, gri CC=golang-dev https://golang.org/cl/156115v1.2.3
@@ -29,16 +29,16 @@ func (m *clientHelloMsg) marshal() []byte { | |||
copy(x[6:38], m.random); | |||
x[38] = uint8(len(m.sessionId)); | |||
copy(x[39:39+len(m.sessionId)], m.sessionId); | |||
y := x[39+len(m.sessionId) : len(x)]; | |||
y := x[39+len(m.sessionId):]; | |||
y[0] = uint8(len(m.cipherSuites) >> 7); | |||
y[1] = uint8(len(m.cipherSuites) << 1); | |||
for i, suite := range m.cipherSuites { | |||
y[2+i*2] = uint8(suite >> 8); | |||
y[3+i*2] = uint8(suite); | |||
} | |||
z := y[2+len(m.cipherSuites)*2 : len(y)]; | |||
z := y[2+len(m.cipherSuites)*2:]; | |||
z[0] = uint8(len(m.compressionMethods)); | |||
copy(z[1:len(z)], m.compressionMethods); | |||
copy(z[1:], m.compressionMethods); | |||
m.raw = x; | |||
return x; | |||
@@ -57,7 +57,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { | |||
return false | |||
} | |||
m.sessionId = data[39 : 39+sessionIdLen]; | |||
data = data[39+sessionIdLen : len(data)]; | |||
data = data[39+sessionIdLen:]; | |||
if len(data) < 2 { | |||
return false | |||
} | |||
@@ -72,7 +72,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { | |||
for i := 0; i < numCipherSuites; i++ { | |||
m.cipherSuites[i] = uint16(data[2+2*i])<<8 | uint16(data[3+2*i]) | |||
} | |||
data = data[2+cipherSuiteLen : len(data)]; | |||
data = data[2+cipherSuiteLen:]; | |||
if len(data) < 2 { | |||
return false | |||
} | |||
@@ -111,7 +111,7 @@ func (m *serverHelloMsg) marshal() []byte { | |||
copy(x[6:38], m.random); | |||
x[38] = uint8(len(m.sessionId)); | |||
copy(x[39:39+len(m.sessionId)], m.sessionId); | |||
z := x[39+len(m.sessionId) : len(x)]; | |||
z := x[39+len(m.sessionId):]; | |||
z[0] = uint8(m.cipherSuite >> 8); | |||
z[1] = uint8(m.cipherSuite); | |||
z[2] = uint8(m.compressionMethod); | |||
@@ -147,13 +147,13 @@ func (m *certificateMsg) marshal() (x []byte) { | |||
x[5] = uint8(certificateOctets >> 8); | |||
x[6] = uint8(certificateOctets); | |||
y := x[7:len(x)]; | |||
y := x[7:]; | |||
for _, slice := range m.certificates { | |||
y[0] = uint8(len(slice) >> 16); | |||
y[1] = uint8(len(slice) >> 8); | |||
y[2] = uint8(len(slice)); | |||
copy(y[3:len(y)], slice); | |||
y = y[3+len(slice) : len(y)]; | |||
copy(y[3:], slice); | |||
y = y[3+len(slice):]; | |||
} | |||
m.raw = x; | |||
@@ -185,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)); | |||
copy(x[6:len(x)], m.ciphertext); | |||
copy(x[6:], m.ciphertext); | |||
m.raw = x; | |||
return x; | |||
@@ -200,7 +200,7 @@ func (m *clientKeyExchangeMsg) unmarshal(data []byte) bool { | |||
if len(data) != 6+cipherTextLen { | |||
return false | |||
} | |||
m.ciphertext = data[6:len(data)]; | |||
m.ciphertext = data[6:]; | |||
return true; | |||
} | |||
@@ -217,7 +217,7 @@ func (m *finishedMsg) marshal() (x []byte) { | |||
x = make([]byte, 16); | |||
x[0] = typeFinished; | |||
x[3] = 12; | |||
copy(x[4:len(x)], m.verifyData); | |||
copy(x[4:], m.verifyData); | |||
m.raw = x; | |||
return; | |||
} | |||
@@ -227,6 +227,6 @@ func (m *finishedMsg) unmarshal(data []byte) bool { | |||
if len(data) != 4+12 { | |||
return false | |||
} | |||
m.verifyData = data[4:len(data)]; | |||
m.verifyData = data[4:]; | |||
return true; | |||
} |
@@ -102,7 +102,7 @@ func (h *serverHandshake) loop(writeChan chan<- interface{}, controlChan chan<- | |||
hello.random[1] = byte(currentTime >> 16); | |||
hello.random[2] = byte(currentTime >> 8); | |||
hello.random[3] = byte(currentTime); | |||
_, err := io.ReadFull(config.Rand, hello.random[4:len(hello.random)]); | |||
_, err := io.ReadFull(config.Rand, hello.random[4:]); | |||
if err != nil { | |||
h.error(alertInternalError); | |||
return; | |||
@@ -135,7 +135,7 @@ func (h *serverHandshake) loop(writeChan chan<- interface{}, controlChan chan<- | |||
finishedHash.Write(ckx.marshal()); | |||
preMasterSecret := make([]byte, 48); | |||
_, err = io.ReadFull(config.Rand, preMasterSecret[2:len(preMasterSecret)]); | |||
_, err = io.ReadFull(config.Rand, preMasterSecret[2:]); | |||
if err != nil { | |||
h.error(alertInternalError); | |||
return; | |||
@@ -16,7 +16,7 @@ import ( | |||
// Split a premaster secret in two as specified in RFC 4346, section 5. | |||
func splitPreMasterSecret(secret []byte) (s1, s2 []byte) { | |||
s1 = secret[0 : (len(secret)+1)/2]; | |||
s2 = secret[len(secret)/2 : len(secret)]; | |||
s2 = secret[len(secret)/2:]; | |||
return; | |||
} | |||
@@ -52,7 +52,7 @@ func pRF11(result, secret, label, seed []byte) { | |||
labelAndSeed := make([]byte, len(label)+len(seed)); | |||
copy(labelAndSeed, label); | |||
copy(labelAndSeed[len(label):len(labelAndSeed)], seed); | |||
copy(labelAndSeed[len(label):], seed); | |||
s1, s2 := splitPreMasterSecret(secret); | |||
pHash(result, s1, labelAndSeed, hashMD5); | |||
@@ -81,20 +81,20 @@ var serverFinishedLabel = strings.Bytes("server finished") | |||
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) { | |||
var seed [tlsRandomLength * 2]byte; | |||
copy(seed[0:len(clientRandom)], clientRandom); | |||
copy(seed[len(clientRandom):len(seed)], serverRandom); | |||
copy(seed[len(clientRandom):], serverRandom); | |||
masterSecret = make([]byte, masterSecretLength); | |||
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]); | |||
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:]); | |||
copy(seed[0:len(clientRandom)], serverRandom); | |||
copy(seed[len(serverRandom):len(seed)], clientRandom); | |||
copy(seed[len(serverRandom):], clientRandom); | |||
n := 2*macLen + 2*keyLen; | |||
keyMaterial := make([]byte, n); | |||
pRF11(keyMaterial, masterSecret, keyExpansionLabel, seed[0:len(seed)]); | |||
pRF11(keyMaterial, masterSecret, keyExpansionLabel, seed[0:]); | |||
clientMAC = keyMaterial[0:macLen]; | |||
serverMAC = keyMaterial[macLen : macLen*2]; | |||
clientKey = keyMaterial[macLen*2 : macLen*2+keyLen]; | |||
serverKey = keyMaterial[macLen*2+keyLen : len(keyMaterial)]; | |||
serverKey = keyMaterial[macLen*2+keyLen:]; | |||
return; | |||
} | |||
@@ -124,7 +124,7 @@ func (h finishedHash) Write(msg []byte) (n int, err os.Error) { | |||
func finishedSum(md5, sha1, label, masterSecret []byte) []byte { | |||
seed := make([]byte, len(md5)+len(sha1)); | |||
copy(seed, md5); | |||
copy(seed[len(md5):len(seed)], sha1); | |||
copy(seed[len(md5):], sha1); | |||
out := make([]byte, finishedVerifyLength); | |||
pRF11(out, masterSecret, label, seed); | |||
return out; | |||
@@ -180,7 +180,7 @@ func (p *recordProcessor) processRecord(r *record) { | |||
p.mac.Write(r.payload[0 : len(r.payload)-p.mac.Size()]); | |||
macBytes := p.mac.Sum(); | |||
if subtle.ConstantTimeCompare(macBytes, r.payload[len(r.payload)-p.mac.Size():len(r.payload)]) != 1 { | |||
if subtle.ConstantTimeCompare(macBytes, r.payload[len(r.payload)-p.mac.Size():]) != 1 { | |||
p.error(alertBadRecordMAC); | |||
return; | |||
} | |||
@@ -228,7 +228,7 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) { | |||
} | |||
newBuf := make([]byte, len(p.handshakeBuf)+len(data)); | |||
copy(newBuf, p.handshakeBuf); | |||
copy(newBuf[len(p.handshakeBuf):len(newBuf)], data); | |||
copy(newBuf[len(p.handshakeBuf):], data); | |||
p.handshakeBuf = newBuf; | |||
} | |||
@@ -241,7 +241,7 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) { | |||
} | |||
bytes := p.handshakeBuf[0 : handshakeLen+4]; | |||
p.handshakeBuf = p.handshakeBuf[handshakeLen+4 : len(p.handshakeBuf)]; | |||
p.handshakeBuf = p.handshakeBuf[handshakeLen+4:]; | |||
if bytes[0] == typeFinished { | |||
// Special case because Finished is synchronous: the | |||
// handshake handler has to tell us if it's ok to start | |||
@@ -21,7 +21,7 @@ func recordReader(c chan<- *record, source io.Reader) { | |||
for { | |||
var header [5]byte; | |||
n, _ := buf.Read(header[0:len(header)]); | |||
n, _ := buf.Read(header[0:]); | |||
if n != 5 { | |||
return | |||
} | |||
@@ -59,7 +59,7 @@ func (tls *Conn) Read(p []byte) (int, os.Error) { | |||
} | |||
n := copy(p, tls.readBuf); | |||
tls.readBuf = tls.readBuf[n:len(tls.readBuf)]; | |||
tls.readBuf = tls.readBuf[n:]; | |||
return n, nil; | |||
} | |||