]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/crypto/ecdsa/ecdsa.go
[dev.boringcrypto] all: merge master into dev.boringcrypto
[gostls13.git] / src / crypto / ecdsa / ecdsa.go
index 0e6bb8b23fc4679a0b249f4e86374c5533888bf5..be01a296062feee17d5eafbe48e88d261bcc3dc2 100644 (file)
@@ -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 {