diff --git a/shadowsocks/encrypt.go b/shadowsocks/encrypt.go index ebf4f34..5eb771a 100644 --- a/shadowsocks/encrypt.go +++ b/shadowsocks/encrypt.go @@ -19,10 +19,10 @@ func md5sum(d []byte) []byte { return h.Sum(nil) } -func evpBytesToKey(password string, keyLen, ivLen int) (key, iv []byte) { +func evpBytesToKey(password string, keyLen int) (key []byte) { const md5Len = 16 - cnt := (keyLen+ivLen-1)/md5Len + 1 + cnt := (keyLen-1)/md5Len + 1 m := make([]byte, cnt*md5Len) copy(m, md5sum([]byte(password))) @@ -36,7 +36,7 @@ func evpBytesToKey(password string, keyLen, ivLen int) (key, iv []byte) { copy(d[md5Len:], password) copy(m[start:], md5sum(d)) } - return m[:keyLen], m[keyLen : keyLen+ivLen] + return m[:keyLen] } func (tbl tableCipher) XORKeyStream(dst, src []byte) { diff --git a/shadowsocks/encrypt_test.go b/shadowsocks/encrypt_test.go index 78cd0a2..ad47f70 100644 --- a/shadowsocks/encrypt_test.go +++ b/shadowsocks/encrypt_test.go @@ -78,11 +78,11 @@ func TestRC4Cipher(t *testing.T) { func TestEvpBytesToKey(t *testing.T) { key, iv := evpBytesToKey("foobar", 32, 16) keyTarget := []byte{0x38, 0x58, 0xf6, 0x22, 0x30, 0xac, 0x3c, 0x91, 0x5f, 0x30, 0x0c, 0x66, 0x43, 0x12, 0xc6, 0x3f, 0x56, 0x83, 0x78, 0x52, 0x96, 0x14, 0xd2, 0x2d, 0xdb, 0x49, 0x23, 0x7d, 0x2f, 0x60, 0xbf, 0xdf} - ivTarget := []byte{0x0e, 0xbf, 0x58, 0x78, 0xe8, 0x2a, 0xf7, 0xda, 0x61, 0x8e, 0xd5, 0x6f, 0xc6, 0x7d, 0x4a, 0xb7} + // ivTarget := []byte{0x0e, 0xbf, 0x58, 0x78, 0xe8, 0x2a, 0xf7, 0xda, 0x61, 0x8e, 0xd5, 0x6f, 0xc6, 0x7d, 0x4a, 0xb7} if !reflect.DeepEqual(key, keyTarget) { t.Errorf("key not correct\n\texpect: %v\n\tgot: %v\n", keyTarget, key) } - if !reflect.DeepEqual(iv, ivTarget) { - t.Errorf("iv not correct\n\texpect: %v\n\tgot: %v\n", ivTarget, iv) - } + // if !reflect.DeepEqual(iv, ivTarget) { + // t.Errorf("iv not correct\n\texpect: %v\n\tgot: %v\n", ivTarget, iv) + // } }