2015-07-05 14:49:07 +05:00
|
|
|
package hashing
|
|
|
|
|
|
|
|
// #cgo CFLAGS: -std=c11 -D_GNU_SOURCE
|
2016-12-06 14:37:21 +05:00
|
|
|
// #cgo LDFLAGS: -L${SRCDIR} -lhashing -Wl,-rpath ${SRCDIR} -lstdc++
|
2015-07-05 14:49:07 +05:00
|
|
|
// #include <stdlib.h>
|
|
|
|
// #include <stdint.h>
|
|
|
|
// #include "src/hashing.h"
|
|
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
func Hash(blob []byte, fast bool) []byte {
|
|
|
|
output := make([]byte, 32)
|
|
|
|
if fast {
|
|
|
|
C.cryptonight_fast_hash((*C.char)(unsafe.Pointer(&blob[0])), (*C.char)(unsafe.Pointer(&output[0])), (C.uint32_t)(len(blob)))
|
|
|
|
} else {
|
|
|
|
C.cryptonight_hash((*C.char)(unsafe.Pointer(&blob[0])), (*C.char)(unsafe.Pointer(&output[0])), (C.uint32_t)(len(blob)))
|
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
2016-12-08 17:50:36 +05:00
|
|
|
|
|
|
|
func FastHash(blob []byte) []byte {
|
|
|
|
return Hash(append([]byte{byte(len(blob))}, blob...), true)
|
|
|
|
}
|