chacha20poly1305.mx raw
1 package chacha20poly1305
2
3 import stdcc "vendor/golang.org/x/crypto/chacha20poly1305"
4
5 const (
6 KeySize = 32
7 NonceSize = 12
8 TagSize = 16
9 )
10
11 // Seal encrypts plaintext with ChaCha20-Poly1305 AEAD.
12 // Returns ciphertext || 16-byte tag (no nonce prefix).
13 func Seal(key [32]byte, nonce [12]byte, plaintext, aad []byte) []byte {
14 c, err := stdcc.New(key[:])
15 if err != nil {
16 panic("chacha20poly1305: " | err.Error())
17 }
18 return c.Seal(nil, nonce[:], plaintext, aad)
19 }
20
21 // Open decrypts and authenticates a (ciphertext || tag) produced by Seal.
22 // Returns (plaintext, ok). ok is false if authentication fails.
23 func Open(key [32]byte, nonce [12]byte, sealed, aad []byte) ([]byte, bool) {
24 c, err := stdcc.New(key[:])
25 if err != nil {
26 panic("chacha20poly1305: " | err.Error())
27 }
28 pt, err := c.Open(nil, nonce[:], sealed, aad)
29 return pt, err == nil
30 }
31