github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/others/cgo/openssl/openssl_test.go (about)

     1  package openssl
     2  
     3  import (
     4  	"testing"
     5  	"encoding/hex"
     6  )
     7  
     8  func TestVerify(t *testing.T) {
     9  	pkey, _ := hex.DecodeString("040eaebcd1df2df853d66ce0e1b0fda07f67d1cabefde98514aad795b86a6ea66dbeb26b67d7a00e2447baeccc8a4cef7cd3cad67376ac1c5785aeebb4f6441c16")
    10  	hasz, _ := hex.DecodeString("3382219555ddbb5b00e0090f469e590ba1eae03c7f28ab937de330aa60294ed6")
    11  	sign, _ := hex.DecodeString("3045022100fe00e013c244062847045ae7eb73b03fca583e9aa5dbd030a8fd1c6dfcf11b1002207d0d04fed8fa1e93007468d5a9e134b0a7023b6d31db4e50942d43a250f4d07c")
    12  	res := EC_Verify(pkey, sign, hasz)
    13  	if res!=1 {
    14  		t.Error("Verify failed")
    15  	}
    16  	hasz[0]++
    17  	res = EC_Verify(pkey, sign, hasz)
    18  	if res!=0 {
    19  		t.Error("Verify not failed while it should")
    20  	}
    21  	res = EC_Verify(pkey[:1], sign, hasz)
    22  	if res!=-2 {
    23  		t.Error("Negative result expected", res)
    24  	}
    25  	res = EC_Verify(pkey, sign[:1], hasz)
    26  	if res!=-1 {
    27  		t.Error("Yet negative result expected", res)
    28  	}
    29  	res = EC_Verify(pkey, sign, hasz[:1])
    30  	if res!=0 {
    31  		t.Error("Zero expected", res)
    32  	}
    33  }