-
-
Save haltingstate/cf84b5418ac889d192a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package secp256k1 | |
import ( | |
"encoding/hex" | |
//"log" | |
"log" | |
"math/rand" | |
"testing" | |
) | |
/* | |
Test strings, that will cause failure | |
*/ | |
//problem seckeys | |
var _test_seckey []string = []string{ | |
"08efb79385c9a8b0d1c6f5f6511be0c6f6c2902963d874a3a4bacc18802528d3", | |
"78298d9ecdc0640c9ae6883201a53f4518055442642024d23c45858f45d0c3e6", | |
"04e04fe65bfa6ded50a12769a3bd83d7351b2dbff08c9bac14662b23a3294b9e", | |
"2f5141f1b75747996c5de77c911dae062d16ae48799052c04ead20ccd5afa113", | |
} | |
func RandBytes(n int) []byte { | |
b := make([]byte, n, n) | |
for i := 0; i < n; i++ { | |
b[i] = byte(rand.Intn(256)) | |
} | |
return b | |
} | |
//tests some keys that should work | |
func Test_Abnormal_Keys1(t *testing.T) { | |
for i := 0; i < len(_test_seckey); i++ { | |
seckey1, _ := hex.DecodeString(_test_seckey[i]) | |
pubkey1 := make([]byte, 33) | |
ret := BaseMultiply(seckey1, pubkey1) | |
if ret == false { | |
t.Errorf("base multiplication fail") | |
} | |
//func BaseMultiply(k, out []byte) bool { | |
var pubkey2 XY | |
ret = pubkey2.ParsePubkey(pubkey1) | |
if ret == false { | |
t.Errorf("pubkey parse fail") | |
} | |
if pubkey2.IsValid() == false { | |
t.Errorf("pubkey is not valid") | |
} | |
} | |
} | |
//tests random keys | |
func Test_Abnormal_Keys2(t *testing.T) { | |
for i := 0; i < 64*1024; i++ { | |
seckey1 := RandBytes(32) | |
pubkey1 := make([]byte, 33) | |
ret := BaseMultiply(seckey1, pubkey1) | |
if ret == false { | |
t.Errorf("base multiplication fail") | |
} | |
//func BaseMultiply(k, out []byte) bool { | |
var pubkey2 XY | |
ret = pubkey2.ParsePubkey(pubkey1) | |
if ret == false { | |
t.Errorf("pubkey parse fail") | |
} | |
if pubkey2.IsValid() == false { | |
log.Printf("fail = %n", i) | |
log.Printf("seckey = %s", hex.EncodeToString(seckey1)) | |
log.Printf("pubkey = %s", hex.EncodeToString(pubkey1)) | |
t.Errorf("pubkey is not valid, i=%n", i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment