func (b Boxer) Box(message []byte, nonce []byte) []byte {
	result := make([]byte, C.crypto_box_ZEROBYTES+len(message))

	copy(result[C.crypto_box_ZEROBYTES:], message)

	C.crypto_box_afternm(array(result), array(result), C.ulonglong(len(result)), array(nonce), array(b))

	return result[C.crypto_box_BOXZEROBYTES:]
}
示例#2
0
func BoxAfterNm(cypherTextOut []byte, message []byte, nonce, key []byte) int {
	checkSize(cypherTextOut, len(message), "cypher text output")
	checkSize(nonce, BoxNonceBytes(), "nonce")
	checkSize(key, BoxBeforeNmBytes(), "intermediate key")

	return int(C.crypto_box_afternm((*C.uchar)(&cypherTextOut[0]),
		(*C.uchar)(&message[0]), (C.ulonglong)(len(message)),
		(*C.uchar)(&nonce[0]),
		(*C.uchar)(&key[0])))
}
示例#3
0
func CryptoBoxOpenAfteNm(c []byte, n []byte, k []byte) ([]byte, int) {
	support.CheckSize(n, CryptoBoxNonceBytes(), "nonce")
	support.CheckSize(k, CryptoBoxBeforeNmBytes(), "shared secret key")
	m := make([]byte, len(c))
	exit := int(C.crypto_box_afternm(
		(*C.uchar)(&m[0]),
		(*C.uchar)(&c[0]),
		(C.ulonglong)(len(c)),
		(*C.uchar)(&n[0]),
		(*C.uchar)(&k[0])))

	return m, exit
}