Beispiel #1
0
// BoxBeforeNm is the first have of the box operation and generates a unique key per
// public, secret key pair (recipient, sender). The key is returned in KeyOut which can
// then be pssed to BoxAfterNm or BoxOpenAfterNm. The same key can be used for all messages between
// the same recipient/sender (same key pairs) provided that a unique nonce is used each time.
// This function is an optimization as it allows the shared key to be generated once for
// multiple messages.
//
// Returns 0 on sucess, non-zero result on error.
func BoxBeforeNm(keyOut []byte, pk, sk []byte) int {
	checkSize(keyOut, BoxBeforeNmBytes(), "key output")
	checkSize(pk, BoxPublicKeyBytes(), "public key")
	checkSize(sk, BoxSecretKeyBytes(), "secret key")

	return int(C.crypto_box_beforenm((*C.uchar)(&keyOut[0]), (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0])))
}
func NewBoxer(pk PublicKey, sk SecretKey) Boxer {
	key := make([]byte, C.crypto_box_BEFORENMBYTES)

	C.crypto_box_beforenm(array(key), array(pk), array(sk))

	return key
}
Beispiel #3
0
func CryptoBoxBeforeNm(pk []byte, sk []byte) ([]byte, int) {
	support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key")
	support.CheckSize(sk, CryptoBoxSecretKeyBytes(), "sender's secret key")
	k := make([]byte, CryptoBoxBeforeNmBytes())
	exit := int(C.crypto_box_beforenm(
		(*C.uchar)(&k[0]),
		(*C.uchar)(&pk[0]),
		(*C.uchar)(&sk[0])))

	return k, exit
}