add test for testing IsOnCurve
This commit is contained in:
parent
506c3eacac
commit
a97fd5fe2c
1 changed files with 34 additions and 0 deletions
|
@ -6,11 +6,17 @@ package btcec_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/ecdsa"
|
||||||
"github.com/conformal/btcec"
|
"github.com/conformal/btcec"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type privKeyTest struct {
|
||||||
|
name string
|
||||||
|
key []byte
|
||||||
|
}
|
||||||
|
|
||||||
type pubKeyTest struct {
|
type pubKeyTest struct {
|
||||||
name string
|
name string
|
||||||
key []byte
|
key []byte
|
||||||
|
@ -18,6 +24,18 @@ type pubKeyTest struct {
|
||||||
isValid bool
|
isValid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var privKeyTests = []privKeyTest{
|
||||||
|
privKeyTest{
|
||||||
|
name: "check curve",
|
||||||
|
key: []byte{
|
||||||
|
0xea, 0xf0, 0x2c, 0xa3, 0x48, 0xc5, 0x24, 0xe6,
|
||||||
|
0x39, 0x26, 0x55, 0xba, 0x4d, 0x29, 0x60, 0x3c,
|
||||||
|
0xd1, 0xa7, 0x34, 0x7d, 0x9d, 0x65, 0xcf, 0xe9,
|
||||||
|
0x3c, 0xe1, 0xeb, 0xff, 0xdc, 0xa2, 0x26, 0x94,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var pubKeyTests = []pubKeyTest{
|
var pubKeyTests = []pubKeyTest{
|
||||||
// pubkey from bitcoin blockchain tx
|
// pubkey from bitcoin blockchain tx
|
||||||
// 0437cd7f8525ceed2324359c2d0ba26006d92d85
|
// 0437cd7f8525ceed2324359c2d0ba26006d92d85
|
||||||
|
@ -200,6 +218,22 @@ var pubKeyTests = []pubKeyTest{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrivKeys(t *testing.T) {
|
||||||
|
for _, test := range privKeyTests {
|
||||||
|
x, y := btcec.S256().ScalarBaseMult(test.key)
|
||||||
|
pub := (*btcec.PublicKey)(&ecdsa.PublicKey{
|
||||||
|
Curve: btcec.S256(),
|
||||||
|
X: x,
|
||||||
|
Y: y,
|
||||||
|
})
|
||||||
|
_, err := btcec.ParsePubKey(pub.SerializeUncompressed(), btcec.S256())
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s privkey: %v", test.name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPubKeys(t *testing.T) {
|
func TestPubKeys(t *testing.T) {
|
||||||
for _, test := range pubKeyTests {
|
for _, test := range pubKeyTests {
|
||||||
pk, err := btcec.ParsePubKey(test.key, btcec.S256())
|
pk, err := btcec.ParsePubKey(test.key, btcec.S256())
|
||||||
|
|
Loading…
Reference in a new issue