chore: support old chacha20

This commit is contained in:
wwqgtxx
2022-11-16 18:37:14 +08:00
parent 994e85425f
commit 2dc62024fe
4 changed files with 30 additions and 4 deletions

View File

@ -59,6 +59,7 @@ var streamList = map[string]struct {
"AES-128-CFB": {16, shadowstream.AESCFB},
"AES-192-CFB": {24, shadowstream.AESCFB},
"AES-256-CFB": {32, shadowstream.AESCFB},
"CHACHA20": {32, shadowstream.ChaCha20},
"CHACHA20-IETF": {32, shadowstream.Chacha20IETF},
"XCHACHA20": {32, shadowstream.Xchacha20},
}

View File

@ -0,0 +1,22 @@
package shadowstream
import (
"crypto/cipher"
"github.com/aead/chacha20/chacha"
)
type chacha20key []byte
func (k chacha20key) IVSize() int {
return chacha.NonceSize
}
func (k chacha20key) Encrypter(iv []byte) cipher.Stream {
c, _ := chacha.NewCipher(iv, k, 20)
return c
}
func (k chacha20key) Decrypter(iv []byte) cipher.Stream {
return k.Encrypter(iv)
}
func ChaCha20(key []byte) (Cipher, error) {
return chacha20key(key), nil
}