예제 #1
0
func Hash(message []byte) []byte {
	hash := make([]byte, HashSize)

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

	return hash
}
예제 #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
}
예제 #3
0
파일: hash.go 프로젝트: 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
}