Example #1
0
// Create returns a new encrypted and authenticated box from the given byte
// slice m with 24-byte nonce n and 32-byte key k.
//
// The returned byte slice is 16 bytes longer than m (it contains 16-byte
// authenticator concatenated with encrypted message).
//
// This function allocates memory for the returned byte slice.
func Create(m []byte, n *[24]byte, k *[32]byte) []byte {
	mpad := make([]byte, ZeroBytes+len(m))
	copy(mpad[ZeroBytes:], m)
	xsalsa20.Xor(mpad, mpad, n, k)
	poly1305.OneTimeAuth(mpad[16:], mpad[32:], mpad[0:32])
	return mpad[BoxZeroBytes:]
}
Example #2
0
func CreateTo(c, m []byte, n *[24]byte, k *[32]byte) {
	if len(m) < ZeroBytes {
		panic("secretbox: message must expected to contain ZeroBytes")
	}
	xsalsa20.Xor(c, m, n, k)
	poly1305.OneTimeAuth(c[16:], c[32:], c[0:32])
	for i := 0; i < 16; i++ {
		c[i] = 0
	}
}