コード例 #1
1
ファイル: session.go プロジェクト: postfix/logstash-forwarder
func (s *Session) Open(nonce []byte, ciphertext []byte) []byte {
	// This function assumes the verbatim []byte given by Session.Box() is passed
	m := make([]byte, crypto_box_BOXZEROBYTES+len(ciphertext))
	copy(m[crypto_box_BOXZEROBYTES:], ciphertext)
	plaintext := make([]byte, len(m))
	if len(nonce) != crypto_box_NONCEBYTES {
		panic(fmt.Sprintf("Invalid nonce length (%d). Expected %d\n",
			len(nonce), crypto_box_NONCEBYTES))
	}

	C.crypto_box_curve25519xsalsa20poly1305_ref_open_afternm(
		(*C.uchar)(unsafe.Pointer(&plaintext[0])),
		(*C.uchar)(unsafe.Pointer(&m[0])), (C.ulonglong)(len(m)),
		(*C.uchar)(unsafe.Pointer(&nonce[0])),
		(*C.uchar)(unsafe.Pointer(&s.k[0])))

	return plaintext[crypto_box_ZEROBYTES:]
}
コード例 #2
0
ファイル: session.go プロジェクト: rif/golang-stuff
func (s *Session) Open(nonce [crypto_box_NONCEBYTES]byte, ciphertext []byte) []byte {
	// This function assumes the verbatim []byte given by Session.Box() is passed
	plaintext := make([]byte, crypto_box_ZEROBYTES+len(ciphertext))

	C.crypto_box_curve25519xsalsa20poly1305_ref_open_afternm(
		(*C.uchar)(unsafe.Pointer(&plaintext[0])),
		(*C.uchar)(unsafe.Pointer(&ciphertext[0])), (C.ulonglong)(len(ciphertext)),
		(*C.uchar)(unsafe.Pointer(&nonce[0])),
		(*C.uchar)(unsafe.Pointer(&s.k[0])))

	return plaintext[crypto_box_ZEROBYTES:len(ciphertext)]
}