Skip to content

Commit

Permalink
Use md5sum of password to initialize RC4 cipher.
Browse files Browse the repository at this point in the history
Makes shadowsocks-go compatible with nodejs version's rc4 encryption.
  • Loading branch information
cyfdecyf committed Jan 22, 2013
1 parent 794472b commit 09c0192
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions TODO
@@ -0,0 +1 @@
Add test script to test both server and client.
12 changes: 6 additions & 6 deletions shadowsocks/encrypt.go
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/rc4"
"encoding/binary"
"errors"
"io"
)

type Cipher interface {
Expand Down Expand Up @@ -36,7 +35,7 @@ func NewTableCipher(key string) (c Cipher, err error) {
table := make([]uint64, tbl_size, tbl_size)

h := md5.New()
io.WriteString(h, key)
h.Write([]byte(key))

s := h.Sum(nil)

Expand Down Expand Up @@ -84,13 +83,14 @@ type RC4Cipher struct {
}

func NewRC4Cipher(key string) (c Cipher, err error) {
keybytes := []byte(key)
enc, err := rc4.NewCipher(keybytes)
h := md5.New()
h.Write([]byte(key))
enc, err := rc4.NewCipher(h.Sum(nil))
if err != nil {
return
}
dec, _ := rc4.NewCipher(keybytes)
c = &RC4Cipher{dec, enc}
dec := *enc // create a copy
c = &RC4Cipher{&dec, enc}
return
}

Expand Down

0 comments on commit 09c0192

Please sign in to comment.