// NewChaCha20Poly1305 returns a cipher.AEAD implementing the // ChaCha20Poly1305 construction specified in RFC 7539 with a // 128 bit auth. tag. func NewChaCha20Poly1305(key *[32]byte) cipher.AEAD { var defaultNonce [12]byte c := &aead{ engine: chacha.NewCipher(&defaultNonce, key, 20), tagsize: TagSize, } return c }
// NewChaCha20Poly1305WithTagSize returns a cipher.AEAD implementing the // ChaCha20Poly1305 construction specified in RFC 7539 with arbitrary tag size. // The tagsize must be between 1 and the TagSize constant. func NewChaCha20Poly1305WithTagSize(key *[32]byte, tagsize int) (cipher.AEAD, error) { if tagsize < 1 || tagsize > TagSize { return nil, errInvalidTagSize } var defaultNonce [12]byte c := &aead{ engine: chacha.NewCipher(&defaultNonce, key, 20), } c.tagsize = tagsize return c, nil }
// NewCipher returns a new cipher.Stream implementing the ChaCha20 // stream cipher. The nonce must be unique for one // key for all time. func NewCipher(nonce *[NonceSize]byte, key *[32]byte) cipher.Stream { return chacha.NewCipher(nonce, key, 20) }