func Hash(message []byte) []byte {
	hash := make([]byte, HashSize)

	C.crypto_hash(array(hash), array(message), C.ulonglong(len(message)))

	return hash
}
Example #2
0
func CryptoHash(in []byte) ([]byte, int) {
	out := make([]byte, CryptoHashBytes())
	exit := int(C.crypto_hash(
		(*C.uchar)(&out[0]),
		(*C.uchar)(&in[0]),
		(C.ulonglong)(len(in))))

	return out, exit
}
Example #3
0
File: hash.go Project: jaked122/Sia
// Uses the hash in libsodium
func CalculateHash(data []byte) (hash Hash, err error) {
	hashPointer := (*C.uchar)(unsafe.Pointer(&hash[0]))
	messagePointer := (*C.uchar)(unsafe.Pointer(&data[0]))
	sizeOfMessage := C.ulonglong(len(data))
	success := C.crypto_hash(hashPointer, messagePointer, sizeOfMessage)
	if success != 0 {
		err = fmt.Errorf("Error in calculating hash")
	}

	return
}