aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/ecdsa/ecdsa.go
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2019-06-27 18:48:02 -0400
committerFilippo Valsorda <filippo@golang.org>2019-06-27 18:48:02 -0400
commit98188f3001e7216f61098958e64ded2e95e7be27 (patch)
tree9f39ff6d1818cf0bd3f950c05255b56f2d6cd679 /src/crypto/ecdsa/ecdsa.go
parent5c354e66d175094e5a3007d0133d82d3f21c9d03 (diff)
parent0b3a57b5374bba3fdf88258e2be4c8be65e6a5de (diff)
downloadgo-98188f3001e7216f61098958e64ded2e95e7be27.tar.gz
go-98188f3001e7216f61098958e64ded2e95e7be27.zip
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: Ic1d89215bb3e37a722d3d3bc7698edea940a83d9
Diffstat (limited to 'src/crypto/ecdsa/ecdsa.go')
-rw-r--r--src/crypto/ecdsa/ecdsa.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/crypto/ecdsa/ecdsa.go b/src/crypto/ecdsa/ecdsa.go
index 0e6bb8b23f..be01a29606 100644
--- a/src/crypto/ecdsa/ecdsa.go
+++ b/src/crypto/ecdsa/ecdsa.go
@@ -21,13 +21,12 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/elliptic"
+ "crypto/internal/randutil"
"crypto/sha512"
"encoding/asn1"
"errors"
"io"
"math/big"
-
- "crypto/internal/randutil"
)
import (
@@ -226,14 +225,21 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
// See [NSA] 3.4.1
c := priv.PublicKey.Curve
+ e := hashToInt(hash, c)
+ r, s, err = sign(priv, &csprng, c, e)
+ return
+}
+
+func signGeneric(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, e *big.Int) (r, s *big.Int, err error) {
N := c.Params().N
if N.Sign() == 0 {
return nil, nil, errZeroParam
}
+
var k, kInv *big.Int
for {
for {
- k, err = randFieldElement(c, csprng)
+ k, err = randFieldElement(c, *csprng)
if err != nil {
r = nil
return
@@ -251,8 +257,6 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
break
}
}
-
- e := hashToInt(hash, c)
s = new(big.Int).Mul(priv.D, r)
s.Add(s, e)
s.Mul(s, kInv)
@@ -261,7 +265,6 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
break
}
}
-
return
}
@@ -288,8 +291,12 @@ func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool {
return false
}
e := hashToInt(hash, c)
+ return verify(pub, c, e, r, s)
+}
+func verifyGeneric(pub *PublicKey, c elliptic.Curve, e, r, s *big.Int) bool {
var w *big.Int
+ N := c.Params().N
if in, ok := c.(invertible); ok {
w = in.Inverse(s)
} else {