github.com/metacubex/mihomo@v1.18.5/transport/shadowsocks/shadowstream/old_chacha20.go (about)

     1  package shadowstream
     2  
     3  import (
     4  	"crypto/cipher"
     5  	"github.com/aead/chacha20/chacha"
     6  )
     7  
     8  type chacha20key []byte
     9  
    10  func (k chacha20key) IVSize() int {
    11  	return chacha.NonceSize
    12  }
    13  func (k chacha20key) Encrypter(iv []byte) cipher.Stream {
    14  	c, _ := chacha.NewCipher(iv, k, 20)
    15  	return c
    16  }
    17  func (k chacha20key) Decrypter(iv []byte) cipher.Stream {
    18  	return k.Encrypter(iv)
    19  }
    20  func ChaCha20(key []byte) (Cipher, error) {
    21  	return chacha20key(key), nil
    22  }