From a82ab21ed8b88a2b706422840ce61a9310f143f5 Mon Sep 17 00:00:00 2001 From: passingwang Date: Fri, 19 Jul 2024 16:40:56 +0800 Subject: [PATCH] Add chacha8-ietf cipher(Uncompleted) --- transport/shadowsocks/shadowstream/cipher.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/transport/shadowsocks/shadowstream/cipher.go b/transport/shadowsocks/shadowstream/cipher.go index dd39d03b..a357bbf9 100644 --- a/transport/shadowsocks/shadowstream/cipher.go +++ b/transport/shadowsocks/shadowstream/cipher.go @@ -7,6 +7,7 @@ import ( "crypto/rc4" "strconv" + "github.com/chocolatkey/chacha8" "golang.org/x/crypto/chacha20" ) @@ -73,6 +74,18 @@ func Chacha20IETF(key []byte) (Cipher, error) { return chacha20ietfkey(key), nil } +type chacha8ietfkey []byte + +func (k chacha8ietfkey) IVSize() int { return chacha8.NonceSize } +func (k chacha8ietfkey) Decrypter(iv []byte) cipher.Stream { return k.Encrypter(iv) } +func (k chacha8ietfkey) Encrypter(iv []byte) cipher.Stream { + ciph, err := chacha8.New(k, iv) + if err != nil { + panic(err) // should never happen + } + return ciph +} + type xchacha20key []byte func (k xchacha20key) IVSize() int { return chacha20.NonceSizeX }