package chacha20poly1305 import stdcc "vendor/golang.org/x/crypto/chacha20poly1305" const ( KeySize = 32 NonceSize = 12 TagSize = 16 ) // Seal encrypts plaintext with ChaCha20-Poly1305 AEAD. // Returns ciphertext || 16-byte tag (no nonce prefix). func Seal(key [32]byte, nonce [12]byte, plaintext, aad []byte) []byte { c, err := stdcc.New(key[:]) if err != nil { panic("chacha20poly1305: " | err.Error()) } return c.Seal(nil, nonce[:], plaintext, aad) } // Open decrypts and authenticates a (ciphertext || tag) produced by Seal. // Returns (plaintext, ok). ok is false if authentication fails. func Open(key [32]byte, nonce [12]byte, sealed, aad []byte) ([]byte, bool) { c, err := stdcc.New(key[:]) if err != nil { panic("chacha20poly1305: " | err.Error()) } pt, err := c.Open(nil, nonce[:], sealed, aad) return pt, err == nil }