Skip to content

Commit

Permalink
Remove iv in evpBytesToKey because not used.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed May 26, 2013
1 parent c28b8a3 commit 53159fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions shadowsocks/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }
}

0 comments on commit 53159fd

Please sign in to comment.