// SecretBox takes a message buffer, a random nonce, and a key and writes the encrypted, authenticated // cypher text into the cypherTextOut buffer. The message buffer must have SecretBoxZeroBytes() worth // of zero-padding at the start of it. The key may be reused across messages, but the nonce must be // used only once for a given key. \ // // Returns: 0 on success, non-zero on failure. func SecretBox(cypherTextOut, message, nonce, key []byte) int { checkSize(cypherTextOut, len(message), "cypher text output") checkSize(nonce, SecretBoxNonceBytes(), "nonce") checkSize(key, SecretBoxKeyBytes(), "key") return int(C.crypto_secretbox( (*C.uchar)(&cypherTextOut[0]), (*C.uchar)(&message[0]), (C.ulonglong)(len(message)), (*C.uchar)(&nonce[0]), (*C.uchar)(&key[0]))) }
func CryptoSecretBox(m []byte, n []byte, k []byte) ([]byte, int) { support.CheckSize(n, CryptoSecretBoxNonceBytes(), "nonce") support.CheckSize(k, CryptoSecretBoxKeyBytes(), "key") c := make([]byte, len(m)+CryptoSecretBoxMacBytes()) exit := int(C.crypto_secretbox( (*C.uchar)(&c[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&n[0]), (*C.uchar)(&k[0]))) return c, exit }