2013-06-14 02:11:06 +02:00
|
|
|
// Copyright (c) 2013 Conformal Systems LLC.
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package btcec_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/conformal/btcec"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type signatureTest struct {
|
|
|
|
name string
|
|
|
|
sig []byte
|
2013-10-24 22:13:27 +02:00
|
|
|
der bool
|
2013-06-14 02:11:06 +02:00
|
|
|
isValid bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var signatureTests = []signatureTest{
|
|
|
|
// signatures from bitcoin blockchain tx
|
|
|
|
// 0437cd7f8525ceed2324359c2d0ba26006d92d85
|
|
|
|
signatureTest{
|
|
|
|
name: "valid signature.",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-14 02:11:06 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-14 02:11:06 +02:00
|
|
|
isValid: true,
|
|
|
|
},
|
2013-06-17 17:18:58 +02:00
|
|
|
signatureTest{
|
2013-06-17 18:38:16 +02:00
|
|
|
name: "empty.",
|
|
|
|
sig: []byte{},
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "bad magic.",
|
|
|
|
sig: []byte{0x31, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "bad 1st int marker magic.",
|
|
|
|
sig: []byte{0x30, 0x44, 0x03, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "bad 2nd int marker.",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x03, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "short len",
|
|
|
|
sig: []byte{0x30, 0x43, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "long len",
|
|
|
|
sig: []byte{0x30, 0x45, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "long X",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x42, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "long Y",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x21, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "short Y",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x19, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 18:38:16 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-17 18:38:16 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "trailing crap.",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
2013-06-17 17:18:58 +02:00
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09, 0x01,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-24 19:06:01 +02:00
|
|
|
|
|
|
|
// This test is now passing (used to be failing) because there
|
|
|
|
// are signatures in the blockchain that have trailing zero
|
2013-09-11 05:14:30 +02:00
|
|
|
// bytes before the hashtype. So ParseSignature was fixed to
|
2013-06-24 19:06:01 +02:00
|
|
|
// permit buffers with trailing nonsense after the actual
|
|
|
|
// signature.
|
|
|
|
isValid: true,
|
2013-06-17 17:18:58 +02:00
|
|
|
},
|
2013-06-18 00:57:36 +02:00
|
|
|
signatureTest{
|
|
|
|
name: "X == N ",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48,
|
|
|
|
0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-18 00:57:36 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "X == N ",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48,
|
|
|
|
0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41,
|
|
|
|
0x42, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: false,
|
2013-06-18 00:57:36 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "Y == N",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
|
|
|
|
0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-18 00:57:36 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "Y > N",
|
|
|
|
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
|
|
|
|
0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x42,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: false,
|
2013-06-18 00:57:36 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
2013-06-18 01:17:32 +02:00
|
|
|
signatureTest{
|
|
|
|
name: "0 len X.",
|
|
|
|
sig: []byte{0x30, 0x24, 0x02, 0x00, 0x02, 0x20, 0x18, 0x15,
|
|
|
|
0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4,
|
|
|
|
0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c,
|
|
|
|
0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76,
|
|
|
|
0x8d, 0x1d, 0x09,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-18 01:17:32 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "0 len Y.",
|
|
|
|
sig: []byte{0x30, 0x24, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x00,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: true,
|
2013-06-18 01:17:32 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
signatureTest{
|
|
|
|
name: "extra R padding.",
|
|
|
|
sig: []byte{0x30, 0x45, 0x02, 0x21, 0x00, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
|
|
|
der: true,
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "extra S padding.",
|
|
|
|
sig: []byte{0x30, 0x45, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x21, 0x00, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
|
|
|
|
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
|
|
|
|
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
|
|
|
|
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
|
|
|
der: true,
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
// Standard checks (in BER format, without checking for 'canonical' DER
|
|
|
|
// signatures) don't test for negative numbers here because there isn't
|
|
|
|
// a way that is the same between openssl and go that will mark a number
|
|
|
|
// as negative. The Go ASN.1 parser marks numbers as negative when
|
|
|
|
// openssl does not (it doesn't handle negative numbers that I can tell
|
|
|
|
// at all. When not parsing DER signatures, which is done by by bitcoind
|
|
|
|
// when accepting transactions into its mempool, we otherwise only check
|
|
|
|
// for the coordinates being zero.
|
2013-06-18 01:17:32 +02:00
|
|
|
signatureTest{
|
|
|
|
name: "X == 0",
|
|
|
|
sig: []byte{0x30, 0x25, 0x02, 0x01, 0x00, 0x02, 0x20, 0x18,
|
|
|
|
0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60,
|
|
|
|
0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5,
|
|
|
|
0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8,
|
|
|
|
0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: false,
|
2013-06-18 01:17:32 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
signatureTest{
|
|
|
|
name: "Y == 0.",
|
|
|
|
sig: []byte{0x30, 0x25, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
|
|
|
|
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
|
|
|
|
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
|
|
|
|
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x01, 0x00,
|
|
|
|
},
|
2013-10-24 22:13:27 +02:00
|
|
|
der: false,
|
2013-06-18 01:17:32 +02:00
|
|
|
isValid: false,
|
|
|
|
},
|
2013-06-14 02:11:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSignatures(t *testing.T) {
|
|
|
|
for _, test := range signatureTests {
|
2013-10-24 22:13:27 +02:00
|
|
|
var err error
|
|
|
|
if test.der {
|
|
|
|
_, err = btcec.ParseDERSignature(test.sig, btcec.S256())
|
|
|
|
} else {
|
|
|
|
_, err = btcec.ParseSignature(test.sig, btcec.S256())
|
|
|
|
}
|
2013-06-14 02:11:06 +02:00
|
|
|
if err != nil {
|
|
|
|
if test.isValid {
|
|
|
|
t.Errorf("%s signature failed when shouldn't %v",
|
|
|
|
test.name, err)
|
2013-06-17 18:38:16 +02:00
|
|
|
} /* else {
|
|
|
|
t.Errorf("%s got error %v", test.name, err)
|
|
|
|
} */
|
2013-06-14 02:11:06 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !test.isValid {
|
|
|
|
t.Errorf("%s counted as valid when it should fail",
|
|
|
|
test.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|