aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/secp256k1/secp256_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/secp256k1/secp256_test.go')
-rw-r--r--crypto/secp256k1/secp256_test.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/crypto/secp256k1/secp256_test.go b/crypto/secp256k1/secp256_test.go
index 468c50db9..3599fde38 100644
--- a/crypto/secp256k1/secp256_test.go
+++ b/crypto/secp256k1/secp256_test.go
@@ -5,6 +5,8 @@ import (
"fmt"
"log"
"testing"
+
+ "github.com/ethereum/go-ethereum/crypto/randentropy"
)
const TESTS = 10000 // how many tests
@@ -12,7 +14,7 @@ const SigSize = 65 //64+1
func Test_Secp256_00(t *testing.T) {
- var nonce []byte = RandByte(32) //going to get bitcoins stolen!
+ var nonce []byte = randentropy.GetEntropyMixed(32) //going to get bitcoins stolen!
if len(nonce) != 32 {
t.Fatal()
@@ -50,7 +52,7 @@ func Test_Secp256_01(t *testing.T) {
//test size of messages
func Test_Secp256_02s(t *testing.T) {
pubkey, seckey := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
CompactSigTest(sig)
if sig == nil {
@@ -73,7 +75,7 @@ func Test_Secp256_02s(t *testing.T) {
//test signing message
func Test_Secp256_02(t *testing.T) {
pubkey1, seckey := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
if sig == nil {
t.Fatal("Signature nil")
@@ -96,7 +98,7 @@ func Test_Secp256_02(t *testing.T) {
//test pubkey recovery
func Test_Secp256_02a(t *testing.T) {
pubkey1, seckey1 := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey1)
if sig == nil {
@@ -125,7 +127,7 @@ func Test_Secp256_02a(t *testing.T) {
func Test_Secp256_03(t *testing.T) {
_, seckey := GenerateKeyPair()
for i := 0; i < TESTS; i++ {
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
CompactSigTest(sig)
@@ -141,7 +143,7 @@ func Test_Secp256_03(t *testing.T) {
func Test_Secp256_04(t *testing.T) {
for i := 0; i < TESTS; i++ {
pubkey1, seckey := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
CompactSigTest(sig)
@@ -164,7 +166,7 @@ func Test_Secp256_04(t *testing.T) {
// -SIPA look at this
func randSig() []byte {
- sig := RandByte(65)
+ sig := randentropy.GetEntropyMixed(65)
sig[32] &= 0x70
sig[64] %= 4
return sig
@@ -172,7 +174,7 @@ func randSig() []byte {
func Test_Secp256_06a_alt0(t *testing.T) {
pubkey1, seckey := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
if sig == nil {
@@ -203,12 +205,12 @@ func Test_Secp256_06a_alt0(t *testing.T) {
func Test_Secp256_06b(t *testing.T) {
pubkey1, seckey := GenerateKeyPair()
- msg := RandByte(32)
+ msg := randentropy.GetEntropyMixed(32)
sig, _ := Sign(msg, seckey)
fail_count := 0
for i := 0; i < TESTS; i++ {
- msg = RandByte(32)
+ msg = randentropy.GetEntropyMixed(32)
pubkey2, _ := RecoverPubkey(msg, sig)
if bytes.Equal(pubkey1, pubkey2) == true {
t.Fail()
@@ -226,3 +228,11 @@ func Test_Secp256_06b(t *testing.T) {
fmt.Printf("ERROR: Accepted signature for %v of %v random messages\n", fail_count, TESTS)
}
}
+
+func TestInvalidKey(t *testing.T) {
+ p1 := make([]byte, 32)
+ err := VerifySeckeyValidity(p1)
+ if err == nil {
+ t.Errorf("pvk %x varify sec key should have returned error", p1)
+ }
+}