github.com/MicalKarl/sing-shadowsocks@v0.0.5/ssv/cipher.go (about)

     1  package ssv
     2  
     3  // A Cipher is an instance of RC4 using a particular key.
     4  type Cipher struct {
     5  }
     6  
     7  // copied from RC4
     8  func NewCipher(key []byte) (*Cipher, error) {
     9  	var c Cipher
    10  	return &c, nil
    11  }
    12  
    13  func (c *Cipher) XORKeyStream(dst, src []byte) {
    14  	if len(src) == 0 {
    15  		return
    16  	}
    17  	dst = dst[:len(src)] // eliminate bounds check from loop
    18  	for k, v := range src {
    19  		dst[k] = uint8(^v)
    20  	}
    21  }