Add tests for sign and verify.

This commit is contained in:
Geert-Johan Riemer 2014-05-15 13:16:24 +02:00 committed by Dave Collins
parent ac7a367950
commit af82a73fe4
2 changed files with 39 additions and 24 deletions

View file

@ -219,7 +219,7 @@ var pubKeyTests = []pubKeyTest{
func TestPrivKeys(t *testing.T) { func TestPrivKeys(t *testing.T) {
for _, test := range privKeyTests { for _, test := range privKeyTests {
_, pub := btcec.PrivKeyFromBytes(btcec.S256(), test.key) priv, pub := btcec.PrivKeyFromBytes(btcec.S256(), test.key)
_, err := btcec.ParsePubKey( _, err := btcec.ParsePubKey(
pub.SerializeUncompressed(), btcec.S256()) pub.SerializeUncompressed(), btcec.S256())
@ -227,6 +227,18 @@ func TestPrivKeys(t *testing.T) {
t.Errorf("%s privkey: %v", test.name, err) t.Errorf("%s privkey: %v", test.name, err)
continue continue
} }
hash := []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}
sig, err := priv.Sign(hash)
if err != nil {
t.Errorf("%s could not sign: %v", test.name, err)
continue
}
if !pub.Verify(hash, sig) {
t.Errorf("%s could not verify: %v", test.name, err)
continue
}
} }
} }

View file

@ -4,8 +4,8 @@ github.com/conformal/btcec/field.go fieldVal.Inverse 100.00% (88/88)
github.com/conformal/btcec/field.go fieldVal.Mul2 100.00% (73/73) github.com/conformal/btcec/field.go fieldVal.Mul2 100.00% (73/73)
github.com/conformal/btcec/field.go fieldVal.SquareVal 100.00% (73/73) github.com/conformal/btcec/field.go fieldVal.SquareVal 100.00% (73/73)
github.com/conformal/btcec/signature.go parseSig 100.00% (51/51) github.com/conformal/btcec/signature.go parseSig 100.00% (51/51)
github.com/conformal/btcec/btcec.go KoblitzCurve.addGeneric 100.00% (35/35)
github.com/conformal/btcec/btcec.go KoblitzCurve.addZ2EqualsOne 100.00% (35/35) github.com/conformal/btcec/btcec.go KoblitzCurve.addZ2EqualsOne 100.00% (35/35)
github.com/conformal/btcec/btcec.go KoblitzCurve.addGeneric 100.00% (35/35)
github.com/conformal/btcec/field.go fieldVal.PutBytes 100.00% (32/32) github.com/conformal/btcec/field.go fieldVal.PutBytes 100.00% (32/32)
github.com/conformal/btcec/btcec.go KoblitzCurve.addZ1EqualsZ2 100.00% (30/30) github.com/conformal/btcec/btcec.go KoblitzCurve.addZ1EqualsZ2 100.00% (30/30)
github.com/conformal/btcec/btcec.go KoblitzCurve.addZ1AndZ2EqualsOne 100.00% (29/29) github.com/conformal/btcec/btcec.go KoblitzCurve.addZ1AndZ2EqualsOne 100.00% (29/29)
@ -15,52 +15,55 @@ github.com/conformal/btcec/btcec.go KoblitzCurve.doubleGeneric 100.00% (18/18
github.com/conformal/btcec/signature.go Signature.Serialize 100.00% (13/13) github.com/conformal/btcec/signature.go Signature.Serialize 100.00% (13/13)
github.com/conformal/btcec/field.go fieldVal.MulInt 100.00% (12/12) github.com/conformal/btcec/field.go fieldVal.MulInt 100.00% (12/12)
github.com/conformal/btcec/btcec.go KoblitzCurve.fieldJacobianToBigAffine 100.00% (12/12) github.com/conformal/btcec/btcec.go KoblitzCurve.fieldJacobianToBigAffine 100.00% (12/12)
github.com/conformal/btcec/field.go fieldVal.Add2 100.00% (11/11)
github.com/conformal/btcec/field.go fieldVal.Add 100.00% (11/11) github.com/conformal/btcec/field.go fieldVal.Add 100.00% (11/11)
github.com/conformal/btcec/field.go fieldVal.NegateVal 100.00% (11/11) github.com/conformal/btcec/field.go fieldVal.NegateVal 100.00% (11/11)
github.com/conformal/btcec/field.go fieldVal.SetBytes 100.00% (11/11) github.com/conformal/btcec/field.go fieldVal.SetBytes 100.00% (11/11)
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarMult 100.00% (10/10) github.com/conformal/btcec/field.go fieldVal.Add2 100.00% (11/11)
github.com/conformal/btcec/btcec.go KoblitzCurve.Add 100.00% (10/10)
github.com/conformal/btcec/field.go fieldVal.Zero 100.00% (10/10) github.com/conformal/btcec/field.go fieldVal.Zero 100.00% (10/10)
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleJacobian 100.00% (9/9) github.com/conformal/btcec/btcec.go KoblitzCurve.Add 100.00% (10/10)
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarMult 100.00% (10/10)
github.com/conformal/btcec/btcec.go initS256 100.00% (9/9) github.com/conformal/btcec/btcec.go initS256 100.00% (9/9)
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleJacobian 100.00% (9/9)
github.com/conformal/btcec/signature.go canonicalizeInt 100.00% (8/8) github.com/conformal/btcec/signature.go canonicalizeInt 100.00% (8/8)
github.com/conformal/btcec/pubkey.go PublicKey.SerializeHybrid 100.00% (7/7)
github.com/conformal/btcec/btcec.go KoblitzCurve.Double 100.00% (7/7) github.com/conformal/btcec/btcec.go KoblitzCurve.Double 100.00% (7/7)
github.com/conformal/btcec/pubkey.go PublicKey.SerializeHybrid 100.00% (7/7)
github.com/conformal/btcec/pubkey.go PublicKey.SerializeCompressed 100.00% (6/6) github.com/conformal/btcec/pubkey.go PublicKey.SerializeCompressed 100.00% (6/6)
github.com/conformal/btcec/field.go fieldVal.SetByteSlice 100.00% (5/5) github.com/conformal/btcec/field.go fieldVal.SetByteSlice 100.00% (5/5)
github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
github.com/conformal/btcec/btcec.go KoblitzCurve.IsOnCurve 100.00% (4/4) github.com/conformal/btcec/btcec.go KoblitzCurve.IsOnCurve 100.00% (4/4)
github.com/conformal/btcec/pubkey.go PublicKey.SerializeUncompressed 100.00% (4/4) github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
github.com/conformal/btcec/field.go fieldVal.SetHex 100.00% (4/4) github.com/conformal/btcec/field.go fieldVal.SetHex 100.00% (4/4)
github.com/conformal/btcec/pubkey.go PublicKey.SerializeUncompressed 100.00% (4/4)
github.com/conformal/btcec/signature.go canonicalPadding 100.00% (4/4) github.com/conformal/btcec/signature.go canonicalPadding 100.00% (4/4)
github.com/conformal/btcec/privkey.go PrivKeyFromBytes 100.00% (3/3) github.com/conformal/btcec/privkey.go PrivKeyFromBytes 100.00% (3/3)
github.com/conformal/btcec/pubkey.go paddedAppend 100.00% (3/3)
github.com/conformal/btcec/field.go fieldVal.Bytes 100.00% (3/3) github.com/conformal/btcec/field.go fieldVal.Bytes 100.00% (3/3)
github.com/conformal/btcec/field.go fieldVal.SetInt 100.00% (3/3) github.com/conformal/btcec/field.go fieldVal.SetInt 100.00% (3/3)
github.com/conformal/btcec/pubkey.go paddedAppend 100.00% (3/3)
github.com/conformal/btcec/field.go fieldVal.Set 100.00% (2/2) github.com/conformal/btcec/field.go fieldVal.Set 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.String 100.00% (2/2)
github.com/conformal/btcec/btcec.go S256 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.IsZero 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.Equals 100.00% (2/2) github.com/conformal/btcec/field.go fieldVal.Equals 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.AddInt 100.00% (2/2) github.com/conformal/btcec/field.go fieldVal.AddInt 100.00% (2/2)
github.com/conformal/btcec/pubkey.go isOdd 100.00% (1/1) github.com/conformal/btcec/field.go fieldVal.IsZero 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.IsOdd 100.00% (1/1) github.com/conformal/btcec/btcec.go S256 100.00% (2/2)
github.com/conformal/btcec/field.go fieldVal.String 100.00% (2/2)
github.com/conformal/btcec/btcec.go KoblitzCurve.Params 100.00% (1/1)
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarBaseMult 100.00% (1/1) github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarBaseMult 100.00% (1/1)
github.com/conformal/btcec/btcec.go KoblitzCurve.QPlus1Div4 100.00% (1/1) github.com/conformal/btcec/btcec.go KoblitzCurve.QPlus1Div4 100.00% (1/1)
github.com/conformal/btcec/btcec.go initAll 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.IsOdd 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Negate 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Mul 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Square 100.00% (1/1)
github.com/conformal/btcec/privkey.go PrivateKey.ToECDSA 100.00% (1/1)
github.com/conformal/btcec/pubkey.go isOdd 100.00% (1/1)
github.com/conformal/btcec/pubkey.go PublicKey.ToECDSA 100.00% (1/1)
github.com/conformal/btcec/pubkey.go PublicKey.Verify 100.00% (1/1)
github.com/conformal/btcec/signature.go ParseSignature 100.00% (1/1) github.com/conformal/btcec/signature.go ParseSignature 100.00% (1/1)
github.com/conformal/btcec/signature.go ParseDERSignature 100.00% (1/1) github.com/conformal/btcec/signature.go ParseDERSignature 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Negate 100.00% (1/1)
github.com/conformal/btcec/btcec.go initAll 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Square 100.00% (1/1)
github.com/conformal/btcec/btcec.go KoblitzCurve.Params 100.00% (1/1)
github.com/conformal/btcec/field.go fieldVal.Mul 100.00% (1/1)
github.com/conformal/btcec/pubkey.go ParsePubKey 92.86% (26/28) github.com/conformal/btcec/pubkey.go ParsePubKey 92.86% (26/28)
github.com/conformal/btcec/signature.go SignCompact 90.91% (20/22)
github.com/conformal/btcec/pubkey.go decompressPoint 88.89% (8/9) github.com/conformal/btcec/pubkey.go decompressPoint 88.89% (8/9)
github.com/conformal/btcec/signature.go recoverKeyFromSignature 86.96% (20/23) github.com/conformal/btcec/signature.go recoverKeyFromSignature 86.96% (20/23)
github.com/conformal/btcec/signature.go RecoverCompact 77.78% (7/9) github.com/conformal/btcec/signature.go SignCompact 81.82% (18/22)
github.com/conformal/btcec/privkey.go PrivateKey.Sign 80.00% (4/5)
github.com/conformal/btcec/signature.go hashToInt 77.78% (7/9) github.com/conformal/btcec/signature.go hashToInt 77.78% (7/9)
github.com/conformal/btcec/pubkey.go PublicKey.ToECDSA 0.00% (0/1) github.com/conformal/btcec/signature.go RecoverCompact 77.78% (7/9)
github.com/conformal/btcec ------------------------------------- 98.58% (902/915) github.com/conformal/btcec ------------------------------------- 98.37% (907/922)