Add chacha8-ietf cipher(Uncompleted)

This commit is contained in:
passingwang 2024-07-19 16:40:56 +08:00
parent 9e3589d638
commit a82ab21ed8

View file

@ -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 }