go-blockchain/crypto/crypto.go
Virgil 5789325690 fix(blockchain): complete AX v0.8.0 polish pass
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 16:58:23 +00:00

33 lines
943 B
Go

// SPDX-Licence-Identifier: EUPL-1.2
package crypto
/*
#cgo CPPFLAGS: -I${SRCDIR}/upstream -I${SRCDIR}/compat -I${SRCDIR}/randomx
#cgo LDFLAGS: -L${SRCDIR}/build -lcryptonote -lrandomx -lstdc++ -lpthread
#include "bridge.h"
*/
import "C"
import "unsafe"
// FastHash computes the CryptoNote fast hash (Keccak-256) of the input.
// Usage: crypto.FastHash(...)
func FastHash(data []byte) [32]byte {
var hash [32]byte
if len(data) == 0 {
C.bridge_fast_hash(nil, 0, (*C.uint8_t)(unsafe.Pointer(&hash[0])))
} else {
C.bridge_fast_hash((*C.uint8_t)(unsafe.Pointer(&data[0])),
C.size_t(len(data)),
(*C.uint8_t)(unsafe.Pointer(&hash[0])))
}
return hash
}
// ScReduce32 reduces a 32-byte value modulo the Ed25519 group order l.
// This is required when converting a hash output to a valid secret key scalar.
// Usage: crypto.ScReduce32(...)
func ScReduce32(key *[32]byte) {
C.cn_sc_reduce32((*C.uint8_t)(unsafe.Pointer(&key[0])))
}