Grumble gofmt run.

This commit is contained in:
Mikkel Krautz 2011-05-13 15:46:45 +02:00
parent 0a40f7fa98
commit d535cbc6fa
5 changed files with 47 additions and 47 deletions

View file

@ -11,23 +11,23 @@ import (
"os" "os"
) )
const AESBlockSize = 16 const AESBlockSize = 16
const DecryptHistorySize = 0x100 const DecryptHistorySize = 0x100
type CryptState struct { type CryptState struct {
RawKey [AESBlockSize]byte RawKey [AESBlockSize]byte
EncryptIV [AESBlockSize]byte EncryptIV [AESBlockSize]byte
DecryptIV [AESBlockSize]byte DecryptIV [AESBlockSize]byte
decryptHistory [DecryptHistorySize]byte decryptHistory [DecryptHistorySize]byte
Good int Good int
Late int Late int
Lost int Lost int
Resync int Resync int
RemoteGood int RemoteGood int
RemoteLate int RemoteLate int
RemoteLost int RemoteLost int
RemoteResync int RemoteResync int
cipher *aes.Cipher cipher *aes.Cipher
@ -52,7 +52,7 @@ func (cs *CryptState) GenerateKey() (err os.Error) {
return return
} }
func (cs *CryptState) SetKey(key []byte, eiv []byte, div[]byte) (err os.Error) { func (cs *CryptState) SetKey(key []byte, eiv []byte, div []byte) (err os.Error) {
if copy(cs.RawKey[0:], key[0:]) != AESBlockSize { if copy(cs.RawKey[0:], key[0:]) != AESBlockSize {
err = os.NewError("Unable to copy key") err = os.NewError("Unable to copy key")
return return
@ -103,7 +103,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) (err os.Error) {
return return
} }
if byte(cs.DecryptIV[0] + 1) == ivbyte { if byte(cs.DecryptIV[0]+1) == ivbyte {
// In order as expected // In order as expected
if ivbyte > cs.DecryptIV[0] { if ivbyte > cs.DecryptIV[0] {
cs.DecryptIV[0] = ivbyte cs.DecryptIV[0] = ivbyte
@ -246,7 +246,7 @@ func times2(block []byte) {
} }
func times3(block []byte) { func times3(block []byte) {
carry := (block[0] >> 7) & 0x1; carry := (block[0] >> 7) & 0x1
for i := 0; i < AESBlockSize-1; i++ { for i := 0; i < AESBlockSize-1; i++ {
block[i] ^= (block[i] << 1) | ((block[i+1] >> 7) & 0x1) block[i] ^= (block[i] << 1) | ((block[i+1] >> 7) & 0x1)
} }
@ -286,7 +286,7 @@ func (cs *CryptState) OCBEncrypt(dst []byte, src []byte, nonce []byte, tag []byt
err = os.NewError("Copy failed") err = os.NewError("Copy failed")
return return
} }
if copy(tmp[copied:], pad[copied:]) != (AESBlockSize-remain) { if copy(tmp[copied:], pad[copied:]) != (AESBlockSize - remain) {
err = os.NewError("Copy failed") err = os.NewError("Copy failed")
return return
} }

View file

@ -37,7 +37,7 @@ func TestTimes3(t *testing.T) {
msg := [AESBlockSize]byte{ msg := [AESBlockSize]byte{
0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
} }
expected := [AESBlockSize]byte { expected := [AESBlockSize]byte{
0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85,
} }
@ -71,22 +71,22 @@ func TestXor(t *testing.T) {
} }
func TestEncrypt(t *testing.T) { func TestEncrypt(t *testing.T) {
msg := [15]byte { msg := [15]byte{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
} }
key := [AESBlockSize]byte { key := [AESBlockSize]byte{
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32, 0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
} }
eiv := [AESBlockSize]byte { eiv := [AESBlockSize]byte{
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, 0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
} }
div := [AESBlockSize]byte { div := [AESBlockSize]byte{
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07, 0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
} }
expected := [19]byte { expected := [19]byte{
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4, 0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
} }
expected_eiv := [AESBlockSize]byte { expected_eiv := [AESBlockSize]byte{
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
} }
@ -109,22 +109,22 @@ func TestEncrypt(t *testing.T) {
} }
func TestDecrypt(t *testing.T) { func TestDecrypt(t *testing.T) {
key := [AESBlockSize]byte { key := [AESBlockSize]byte{
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32, 0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
} }
eiv := [AESBlockSize]byte { eiv := [AESBlockSize]byte{
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, 0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
} }
div := [AESBlockSize]byte { div := [AESBlockSize]byte{
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07, 0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
} }
crypted := [19]byte { crypted := [19]byte{
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4, 0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
} }
expected := [15]byte { expected := [15]byte{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
} }
post_div := [AESBlockSize]byte { post_div := [AESBlockSize]byte{
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
} }

View file

@ -10,11 +10,11 @@ import (
) )
type PacketDataStream struct { type PacketDataStream struct {
Buf []byte Buf []byte
offset int offset int
maxsize int maxsize int
overshoot int overshoot int
ok bool ok bool
} }
func New(buf []byte) (pds *PacketDataStream) { func New(buf []byte) (pds *PacketDataStream) {
@ -76,7 +76,7 @@ func (pds *PacketDataStream) Next8() (ret uint8) {
// Put a byte (represented in an uint64) into the // Put a byte (represented in an uint64) into the
// PacketDataStream. // PacketDataStream.
func (pds *PacketDataStream) append(val uint64) { func (pds *PacketDataStream) append(val uint64) {
if (val > 0xff) { if val > 0xff {
pds.ok = false pds.ok = false
return return
} }
@ -97,7 +97,7 @@ func (pds *PacketDataStream) append(val uint64) {
func (pds *PacketDataStream) addVarint(val uint64) { func (pds *PacketDataStream) addVarint(val uint64) {
i := val i := val
if (i & 0x8000000000000000) != 0 && ^i < 0x100000000 { if (i&0x8000000000000000) != 0 && ^i < 0x100000000 {
// Signed number // Signed number
i = ^i i = ^i
if i <= 0x3 { if i <= 0x3 {
@ -146,13 +146,13 @@ func (pds *PacketDataStream) getVarint() (i uint64) {
if (v & 0x80) == 0x00 { if (v & 0x80) == 0x00 {
i = (v & 0x7f) i = (v & 0x7f)
} else if (v & 0xc0) == 0x80 { } else if (v & 0xc0) == 0x80 {
i = (v & 0x3f) << 8 | pds.next() i = (v&0x3f)<<8 | pds.next()
} else if (v & 0xf0) == 0xf0 { } else if (v & 0xf0) == 0xf0 {
switch v & 0xfc { switch v & 0xfc {
case 0xf0: case 0xf0:
i = pds.next() << 24 | pds.next() << 16 | pds.next() << 8 | pds.next() i = pds.next()<<24 | pds.next()<<16 | pds.next()<<8 | pds.next()
case 0xf4: case 0xf4:
i = pds.next() << 56 | pds.next() << 48 | pds.next() << 40 | pds.next() << 32 | pds.next() << 24 | pds.next() << 16 | pds.next() << 8 | pds.next() i = pds.next()<<56 | pds.next()<<48 | pds.next()<<40 | pds.next()<<32 | pds.next()<<24 | pds.next()<<16 | pds.next()<<8 | pds.next()
case 0xf8: case 0xf8:
i = ^pds.getVarint() i = ^pds.getVarint()
case 0xfc: case 0xfc:
@ -162,9 +162,9 @@ func (pds *PacketDataStream) getVarint() (i uint64) {
i = 0 i = 0
} }
} else if (v & 0xf0) == 0xe0 { } else if (v & 0xf0) == 0xe0 {
i = (v & 0x0f) << 24 | pds.next() << 16 | pds.next() << 8 | pds.next() i = (v&0x0f)<<24 | pds.next()<<16 | pds.next()<<8 | pds.next()
} else if (v & 0xe0) == 0xc0 { } else if (v & 0xe0) == 0xc0 {
i = (v & 0x1f) << 16 | pds.next() << 8 | pds.next() i = (v&0x1f)<<16 | pds.next()<<8 | pds.next()
} }
return return
@ -260,7 +260,7 @@ func (pds *PacketDataStream) GetFloat32() float32 {
var val uint32 var val uint32
val = uint32(pds.Next8()) << 24 | uint32(pds.Next8()) << 16 | uint32(pds.Next8()) << 8 | uint32(pds.Next8()) val = uint32(pds.Next8())<<24 | uint32(pds.Next8())<<16 | uint32(pds.Next8())<<8 | uint32(pds.Next8())
return math.Float32frombits(val) return math.Float32frombits(val)
} }
@ -281,7 +281,7 @@ func (pds *PacketDataStream) GetFloat64() float64 {
} }
var val uint64 var val uint64
val = uint64(pds.Next8()) << 56 | uint64(pds.Next8()) << 48 | uint64(pds.Next8()) << 40 | uint64(pds.Next8()) << 32 | uint64(pds.Next8()) << 24 | uint64(pds.Next8()) << 16 | uint64(pds.Next8()) << 8 | uint64(pds.Next8()) val = uint64(pds.Next8())<<56 | uint64(pds.Next8())<<48 | uint64(pds.Next8())<<40 | uint64(pds.Next8())<<32 | uint64(pds.Next8())<<24 | uint64(pds.Next8())<<16 | uint64(pds.Next8())<<8 | uint64(pds.Next8())
return math.Float64frombits(val) return math.Float64frombits(val)
} }

View file

@ -32,7 +32,7 @@ func TestSelfUint64(t *testing.T) {
buf := make([]byte, 500) buf := make([]byte, 500)
pds := New(buf) pds := New(buf)
for i := uint64(1 << 54); i < (uint64(1 << 54)+10); i++ { for i := uint64(1 << 54); i < (uint64(1<<54) + 10); i++ {
pds.PutUint64(i) pds.PutUint64(i)
if !pds.IsValid() { if !pds.IsValid() {
t.Errorf("Invalid PDS") t.Errorf("Invalid PDS")
@ -41,7 +41,7 @@ func TestSelfUint64(t *testing.T) {
} }
pds2 := New(buf) pds2 := New(buf)
for i := uint64(1 << 54); i < (uint64(1 << 54)+10); i++ { for i := uint64(1 << 54); i < (uint64(1<<54) + 10); i++ {
val := pds2.GetUint64() val := pds2.GetUint64()
if !pds.IsValid() { if !pds.IsValid() {
t.Errorf("Invalid PDS") t.Errorf("Invalid PDS")
@ -121,7 +121,7 @@ func TestSelfFloat32(t *testing.T) {
} }
func TestSelfBytes(t *testing.T) { func TestSelfBytes(t *testing.T) {
msg := [15]byte{ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, } msg := [15]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}
buf := make([]byte, 500) buf := make([]byte, 500)
pds := New(buf) pds := New(buf)
pds2 := New(buf) pds2 := New(buf)

View file

@ -42,7 +42,7 @@ func (cfg *Config) GetAll() (all map[string]string) {
defer cfg.mutex.RUnlock() defer cfg.mutex.RUnlock()
all = make(map[string]string) all = make(map[string]string)
for k,v := range cfg.cfgMap { for k, v := range cfg.cfgMap {
all[k] = v all[k] = v
} }
return return