git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/crypto/chacha20/chacha20.go (about) 1 // Package chacha20 implements the ChaCha20 / XChaCha20 stream chipher. 2 // Notice that one specific key-nonce combination must be unique for all time. 3 // 4 // There are three versions of ChaCha20: 5 // - ChaCha20 with a 64 bit nonce (en/decrypt up to 2^64 * 64 bytes for one key-nonce combination) 6 // - ChaCha20 with a 96 bit nonce (en/decrypt up to 2^32 * 64 bytes (~256 GB) for one key-nonce combination) 7 // - XChaCha20 with a 192 bit nonce (en/decrypt up to 2^64 * 64 bytes for one key-nonce combination) 8 package chacha20 9 10 import ( 11 "crypto/cipher" 12 "errors" 13 ) 14 15 const ( 16 KeySize = 32 17 NonceSize = 8 18 ) 19 20 var ( 21 ErrBadKeyLength = errors.New("chacha20: bad key length. 32 bytes required") 22 ErrBadNonceLength = errors.New("chacha20: bad nonce length for ChaCha20. 8 bytes required") 23 ) 24 25 type StreamCipher interface { 26 cipher.Stream 27 SetCounter(n uint32) 28 }