github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/tools/sipa_dll/sipadll.go (about)

     1  package spiadll
     2  
     3  import (
     4  	"unsafe"
     5  	"syscall"
     6  )
     7  
     8  var (
     9  	dll = syscall.NewLazyDLL("secp256k1.dll")
    10  	DLL_EC_Verify = dll.NewProc("EC_Verify")
    11  	DLL_Schnorr_Verify = dll.NewProc("Schnorr_Verify")
    12  	DLL_CheckPayToContract = dll.NewProc("CheckPayToContract")
    13  )
    14  
    15  
    16  func EC_Verify(pkey, sign, hash []byte) int32 {
    17  	r1, _, _ := syscall.Syscall6(DLL_EC_Verify.Addr(), 6,
    18  		uintptr(unsafe.Pointer(&hash[0])), uintptr(32),
    19  		uintptr(unsafe.Pointer(&sign[0])), uintptr(len(sign)),
    20  		uintptr(unsafe.Pointer(&pkey[0])), uintptr(len(pkey)))
    21  	return int32(r1)
    22  }
    23  
    24  
    25  func Schnorr_Verify(pkey, sign, msg []byte) int {
    26  	r1, _, _ := syscall.Syscall(DLL_Schnorr_Verify.Addr(), 3,
    27  		uintptr(unsafe.Pointer(&msg[0])),
    28  		uintptr(unsafe.Pointer(&sign[0])),
    29  		uintptr(unsafe.Pointer(&pkey[0])))
    30  	return int(r1)
    31  }
    32  
    33  func CheckPayToContract(kd, base, hash []byte, parity int) int {
    34  	r1, _, _ := syscall.Syscall6(DLL_CheckPayToContract.Addr(), 4,
    35  		uintptr(unsafe.Pointer(&kd[0])),
    36  		uintptr(unsafe.Pointer(&base[0])),
    37  		uintptr(unsafe.Pointer(&hash[0])), uintptr(parity), 0, 0)
    38  	return int(r1)
    39  }