gofmt -r 'α[β:len(α)] -> α[β:]' -w src/cmd src/pkg

R=r, gri
CC=golang-dev
https://golang.org/cl/156115
This commit is contained in:
Russ Cox 2009-11-20 11:45:05 -08:00
parent a1e7e65e2d
commit 4625777977
6 changed files with 28 additions and 28 deletions

View File

@ -29,16 +29,16 @@ func (m *clientHelloMsg) marshal() []byte {
copy(x[6:38], m.random); copy(x[6:38], m.random);
x[38] = uint8(len(m.sessionId)); x[38] = uint8(len(m.sessionId));
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 := x[39+len(m.sessionId):];
y[0] = uint8(len(m.cipherSuites) >> 7); y[0] = uint8(len(m.cipherSuites) >> 7);
y[1] = uint8(len(m.cipherSuites) << 1); y[1] = uint8(len(m.cipherSuites) << 1);
for i, suite := range m.cipherSuites { for i, suite := range m.cipherSuites {
y[2+i*2] = uint8(suite >> 8); y[2+i*2] = uint8(suite >> 8);
y[3+i*2] = uint8(suite); 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)); z[0] = uint8(len(m.compressionMethods));
copy(z[1:len(z)], m.compressionMethods); copy(z[1:], m.compressionMethods);
m.raw = x; m.raw = x;
return x; return x;
@ -57,7 +57,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
return false return false
} }
m.sessionId = data[39 : 39+sessionIdLen]; m.sessionId = data[39 : 39+sessionIdLen];
data = data[39+sessionIdLen : len(data)]; data = data[39+sessionIdLen:];
if len(data) < 2 { if len(data) < 2 {
return false return false
} }
@ -72,7 +72,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
for i := 0; i < numCipherSuites; i++ { for i := 0; i < numCipherSuites; i++ {
m.cipherSuites[i] = uint16(data[2+2*i])<<8 | uint16(data[3+2*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 { if len(data) < 2 {
return false return false
} }
@ -111,7 +111,7 @@ func (m *serverHelloMsg) marshal() []byte {
copy(x[6:38], m.random); copy(x[6:38], m.random);
x[38] = uint8(len(m.sessionId)); x[38] = uint8(len(m.sessionId));
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 := x[39+len(m.sessionId):];
z[0] = uint8(m.cipherSuite >> 8); z[0] = uint8(m.cipherSuite >> 8);
z[1] = uint8(m.cipherSuite); z[1] = uint8(m.cipherSuite);
z[2] = uint8(m.compressionMethod); z[2] = uint8(m.compressionMethod);
@ -147,13 +147,13 @@ func (m *certificateMsg) marshal() (x []byte) {
x[5] = uint8(certificateOctets >> 8); x[5] = uint8(certificateOctets >> 8);
x[6] = uint8(certificateOctets); x[6] = uint8(certificateOctets);
y := x[7:len(x)]; y := x[7:];
for _, slice := range m.certificates { for _, slice := range m.certificates {
y[0] = uint8(len(slice) >> 16); y[0] = uint8(len(slice) >> 16);
y[1] = uint8(len(slice) >> 8); y[1] = uint8(len(slice) >> 8);
y[2] = uint8(len(slice)); y[2] = uint8(len(slice));
copy(y[3:len(y)], slice); copy(y[3:], slice);
y = y[3+len(slice) : len(y)]; y = y[3+len(slice):];
} }
m.raw = x; m.raw = x;
@ -185,7 +185,7 @@ func (m *clientKeyExchangeMsg) marshal() []byte {
x[3] = uint8(length); x[3] = uint8(length);
x[4] = uint8(len(m.ciphertext) >> 8); x[4] = uint8(len(m.ciphertext) >> 8);
x[5] = uint8(len(m.ciphertext)); x[5] = uint8(len(m.ciphertext));
copy(x[6:len(x)], m.ciphertext); copy(x[6:], m.ciphertext);
m.raw = x; m.raw = x;
return x; return x;
@ -200,7 +200,7 @@ func (m *clientKeyExchangeMsg) unmarshal(data []byte) bool {
if len(data) != 6+cipherTextLen { if len(data) != 6+cipherTextLen {
return false return false
} }
m.ciphertext = data[6:len(data)]; m.ciphertext = data[6:];
return true; return true;
} }
@ -217,7 +217,7 @@ func (m *finishedMsg) marshal() (x []byte) {
x = make([]byte, 16); x = make([]byte, 16);
x[0] = typeFinished; x[0] = typeFinished;
x[3] = 12; x[3] = 12;
copy(x[4:len(x)], m.verifyData); copy(x[4:], m.verifyData);
m.raw = x; m.raw = x;
return; return;
} }
@ -227,6 +227,6 @@ func (m *finishedMsg) unmarshal(data []byte) bool {
if len(data) != 4+12 { if len(data) != 4+12 {
return false return false
} }
m.verifyData = data[4:len(data)]; m.verifyData = data[4:];
return true; return true;
} }

View File

@ -102,7 +102,7 @@ func (h *serverHandshake) loop(writeChan chan<- interface{}, controlChan chan<-
hello.random[1] = byte(currentTime >> 16); hello.random[1] = byte(currentTime >> 16);
hello.random[2] = byte(currentTime >> 8); hello.random[2] = byte(currentTime >> 8);
hello.random[3] = byte(currentTime); 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 { if err != nil {
h.error(alertInternalError); h.error(alertInternalError);
return; return;
@ -135,7 +135,7 @@ func (h *serverHandshake) loop(writeChan chan<- interface{}, controlChan chan<-
finishedHash.Write(ckx.marshal()); finishedHash.Write(ckx.marshal());
preMasterSecret := make([]byte, 48); preMasterSecret := make([]byte, 48);
_, err = io.ReadFull(config.Rand, preMasterSecret[2:len(preMasterSecret)]); _, err = io.ReadFull(config.Rand, preMasterSecret[2:]);
if err != nil { if err != nil {
h.error(alertInternalError); h.error(alertInternalError);
return; return;

16
prf.go
View File

@ -16,7 +16,7 @@ import (
// Split a premaster secret in two as specified in RFC 4346, section 5. // Split a premaster secret in two as specified in RFC 4346, section 5.
func splitPreMasterSecret(secret []byte) (s1, s2 []byte) { func splitPreMasterSecret(secret []byte) (s1, s2 []byte) {
s1 = secret[0 : (len(secret)+1)/2]; s1 = secret[0 : (len(secret)+1)/2];
s2 = secret[len(secret)/2 : len(secret)]; s2 = secret[len(secret)/2:];
return; return;
} }
@ -52,7 +52,7 @@ func pRF11(result, secret, label, seed []byte) {
labelAndSeed := make([]byte, len(label)+len(seed)); labelAndSeed := make([]byte, len(label)+len(seed));
copy(labelAndSeed, label); copy(labelAndSeed, label);
copy(labelAndSeed[len(label):len(labelAndSeed)], seed); copy(labelAndSeed[len(label):], seed);
s1, s2 := splitPreMasterSecret(secret); s1, s2 := splitPreMasterSecret(secret);
pHash(result, s1, labelAndSeed, hashMD5); 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) { func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
var seed [tlsRandomLength * 2]byte; var seed [tlsRandomLength * 2]byte;
copy(seed[0:len(clientRandom)], clientRandom); copy(seed[0:len(clientRandom)], clientRandom);
copy(seed[len(clientRandom):len(seed)], serverRandom); copy(seed[len(clientRandom):], serverRandom);
masterSecret = make([]byte, masterSecretLength); 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[0:len(clientRandom)], serverRandom);
copy(seed[len(serverRandom):len(seed)], clientRandom); copy(seed[len(serverRandom):], clientRandom);
n := 2*macLen + 2*keyLen; n := 2*macLen + 2*keyLen;
keyMaterial := make([]byte, n); keyMaterial := make([]byte, n);
pRF11(keyMaterial, masterSecret, keyExpansionLabel, seed[0:len(seed)]); pRF11(keyMaterial, masterSecret, keyExpansionLabel, seed[0:]);
clientMAC = keyMaterial[0:macLen]; clientMAC = keyMaterial[0:macLen];
serverMAC = keyMaterial[macLen : macLen*2]; serverMAC = keyMaterial[macLen : macLen*2];
clientKey = keyMaterial[macLen*2 : macLen*2+keyLen]; clientKey = keyMaterial[macLen*2 : macLen*2+keyLen];
serverKey = keyMaterial[macLen*2+keyLen : len(keyMaterial)]; serverKey = keyMaterial[macLen*2+keyLen:];
return; return;
} }
@ -124,7 +124,7 @@ func (h finishedHash) Write(msg []byte) (n int, err os.Error) {
func finishedSum(md5, sha1, label, masterSecret []byte) []byte { func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
seed := make([]byte, len(md5)+len(sha1)); seed := make([]byte, len(md5)+len(sha1));
copy(seed, md5); copy(seed, md5);
copy(seed[len(md5):len(seed)], sha1); copy(seed[len(md5):], sha1);
out := make([]byte, finishedVerifyLength); out := make([]byte, finishedVerifyLength);
pRF11(out, masterSecret, label, seed); pRF11(out, masterSecret, label, seed);
return out; return out;

View File

@ -180,7 +180,7 @@ func (p *recordProcessor) processRecord(r *record) {
p.mac.Write(r.payload[0 : len(r.payload)-p.mac.Size()]); p.mac.Write(r.payload[0 : len(r.payload)-p.mac.Size()]);
macBytes := p.mac.Sum(); 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); p.error(alertBadRecordMAC);
return; return;
} }
@ -228,7 +228,7 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) {
} }
newBuf := make([]byte, len(p.handshakeBuf)+len(data)); newBuf := make([]byte, len(p.handshakeBuf)+len(data));
copy(newBuf, p.handshakeBuf); copy(newBuf, p.handshakeBuf);
copy(newBuf[len(p.handshakeBuf):len(newBuf)], data); copy(newBuf[len(p.handshakeBuf):], data);
p.handshakeBuf = newBuf; p.handshakeBuf = newBuf;
} }
@ -241,7 +241,7 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) {
} }
bytes := p.handshakeBuf[0 : handshakeLen+4]; 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 { if bytes[0] == typeFinished {
// Special case because Finished is synchronous: the // Special case because Finished is synchronous: the
// handshake handler has to tell us if it's ok to start // handshake handler has to tell us if it's ok to start

View File

@ -21,7 +21,7 @@ func recordReader(c chan<- *record, source io.Reader) {
for { for {
var header [5]byte; var header [5]byte;
n, _ := buf.Read(header[0:len(header)]); n, _ := buf.Read(header[0:]);
if n != 5 { if n != 5 {
return return
} }

2
tls.go
View File

@ -59,7 +59,7 @@ func (tls *Conn) Read(p []byte) (int, os.Error) {
} }
n := copy(p, tls.readBuf); n := copy(p, tls.readBuf);
tls.readBuf = tls.readBuf[n:len(tls.readBuf)]; tls.readBuf = tls.readBuf[n:];
return n, nil; return n, nil;
} }