aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/crypto/ecdsa
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-01-09 01:23:08 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 01:23:08 +0000
commit1a2f01efa63036a5104f203a4789e682c0e0915d (patch)
tree373e15778dc8295354584e1f86915ae493b604ff /libgo/go/crypto/ecdsa
parent8799df67f2dab88f9fda11739c501780a85575e2 (diff)
downloadgcc-1a2f01efa63036a5104f203a4789e682c0e0915d.zip
gcc-1a2f01efa63036a5104f203a4789e682c0e0915d.tar.gz
gcc-1a2f01efa63036a5104f203a4789e682c0e0915d.tar.bz2
libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
Diffstat (limited to 'libgo/go/crypto/ecdsa')
-rw-r--r--libgo/go/crypto/ecdsa/ecdsa.go17
-rw-r--r--libgo/go/crypto/ecdsa/ecdsa_test.go58
2 files changed, 56 insertions, 19 deletions
diff --git a/libgo/go/crypto/ecdsa/ecdsa.go b/libgo/go/crypto/ecdsa/ecdsa.go
index 02848fd..755ed28 100644
--- a/libgo/go/crypto/ecdsa/ecdsa.go
+++ b/libgo/go/crypto/ecdsa/ecdsa.go
@@ -49,7 +49,7 @@ type PublicKey struct {
X, Y *big.Int
}
-// PrivateKey represents a ECDSA private key.
+// PrivateKey represents an ECDSA private key.
type PrivateKey struct {
PublicKey
D *big.Int
@@ -64,12 +64,15 @@ func (priv *PrivateKey) Public() crypto.PublicKey {
return &priv.PublicKey
}
-// Sign signs msg with priv, reading randomness from rand. This method is
-// intended to support keys where the private part is kept in, for example, a
-// hardware module. Common uses should use the Sign function in this package
-// directly.
-func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
- r, s, err := Sign(rand, priv, msg)
+// Sign signs digest with priv, reading randomness from rand. The opts argument
+// is not currently used but, in keeping with the crypto.Signer interface,
+// should be the hash function used to digest the message.
+//
+// This method implements crypto.Signer, which is an interface to support keys
+// where the private part is kept in, for example, a hardware module. Common
+// uses should use the Sign function in this package directly.
+func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
+ r, s, err := Sign(rand, priv, digest)
if err != nil {
return nil, err
}
diff --git a/libgo/go/crypto/ecdsa/ecdsa_test.go b/libgo/go/crypto/ecdsa/ecdsa_test.go
index 9546f67..9224a03 100644
--- a/libgo/go/crypto/ecdsa/ecdsa_test.go
+++ b/libgo/go/crypto/ecdsa/ecdsa_test.go
@@ -48,10 +48,13 @@ func BenchmarkSignP256(b *testing.B) {
hashed := []byte("testing")
priv, _ := GenerateKey(p256, rand.Reader)
+ b.ReportAllocs()
b.ResetTimer()
- for i := 0; i < b.N; i++ {
- _, _, _ = Sign(rand.Reader, priv, hashed)
- }
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ _, _, _ = Sign(rand.Reader, priv, hashed)
+ }
+ })
}
func BenchmarkSignP384(b *testing.B) {
@@ -60,10 +63,13 @@ func BenchmarkSignP384(b *testing.B) {
hashed := []byte("testing")
priv, _ := GenerateKey(p384, rand.Reader)
+ b.ReportAllocs()
b.ResetTimer()
- for i := 0; i < b.N; i++ {
- _, _, _ = Sign(rand.Reader, priv, hashed)
- }
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ _, _, _ = Sign(rand.Reader, priv, hashed)
+ }
+ })
}
func BenchmarkVerifyP256(b *testing.B) {
@@ -73,20 +79,26 @@ func BenchmarkVerifyP256(b *testing.B) {
priv, _ := GenerateKey(p256, rand.Reader)
r, s, _ := Sign(rand.Reader, priv, hashed)
+ b.ReportAllocs()
b.ResetTimer()
- for i := 0; i < b.N; i++ {
- Verify(&priv.PublicKey, hashed, r, s)
- }
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ Verify(&priv.PublicKey, hashed, r, s)
+ }
+ })
}
func BenchmarkKeyGeneration(b *testing.B) {
b.ResetTimer()
p256 := elliptic.P256()
+ b.ReportAllocs()
b.ResetTimer()
- for i := 0; i < b.N; i++ {
- GenerateKey(p256, rand.Reader)
- }
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ GenerateKey(p256, rand.Reader)
+ }
+ })
}
func testSignAndVerify(t *testing.T, c elliptic.Curve, tag string) {
@@ -331,3 +343,25 @@ func TestNegativeInputs(t *testing.T) {
testNegativeInputs(t, elliptic.P384(), "p384")
testNegativeInputs(t, elliptic.P521(), "p521")
}
+
+func TestZeroHashSignature(t *testing.T) {
+ zeroHash := make([]byte, 64)
+
+ for _, curve := range []elliptic.Curve{elliptic.P224(), elliptic.P256(), elliptic.P384(), elliptic.P521()} {
+ privKey, err := GenerateKey(curve, rand.Reader)
+ if err != nil {
+ panic(err)
+ }
+
+ // Sign a hash consisting of all zeros.
+ r, s, err := Sign(rand.Reader, privKey, zeroHash)
+ if err != nil {
+ panic(err)
+ }
+
+ // Confirm that it can be verified.
+ if !Verify(&privKey.PublicKey, zeroHash, r, s) {
+ t.Errorf("zero hash signature verify failed for %T", curve)
+ }
+ }
+}