github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/others/cgo/openssl/openssl.go (about) 1 package openssl 2 3 /* 4 #cgo !windows LDFLAGS: -lcrypto 5 #cgo windows LDFLAGS: /DEV/openssl-1.0.2a/libcrypto.a -lgdi32 6 #cgo windows CFLAGS: -I /DEV/openssl-1.0.2a/include 7 8 #include <stdio.h> 9 #include <openssl/ec.h> 10 #include <openssl/ecdsa.h> 11 #include <openssl/obj_mac.h> 12 13 int verify(void *pkey, unsigned int pkl, void *sign, unsigned int sil, void *hasz) { 14 EC_KEY* ecpkey; 15 ecpkey = EC_KEY_new_by_curve_name(NID_secp256k1); 16 if (!ecpkey) { 17 printf("EC_KEY_new_by_curve_name error!\n"); 18 return -1; 19 } 20 if (!o2i_ECPublicKey(&ecpkey, (const unsigned char **)&pkey, pkl)) { 21 //printf("o2i_ECPublicKey fail!\n"); 22 return -2; 23 } 24 int res = ECDSA_verify(0, hasz, 32, sign, sil, ecpkey); 25 EC_KEY_free(ecpkey); 26 return res; 27 } 28 */ 29 import "C" 30 import "unsafe" 31 32 33 // EC_Verify verifies an ECDSA signature. 34 func EC_Verify(pkey, sign, hash []byte) int { 35 return int(C.verify(unsafe.Pointer(&pkey[0]), C.uint(len(pkey)), 36 unsafe.Pointer(&sign[0]), C.uint(len(sign)), unsafe.Pointer(&hash[0]))) 37 }