]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/{ecdsa,rsa}: rename argument to PrivateKey.Sign.
authorAdam Langley <agl@golang.org>
Sat, 14 Oct 2017 18:43:17 +0000 (11:43 -0700)
committerAdam Langley <agl@golang.org>
Sun, 29 Oct 2017 19:45:11 +0000 (19:45 +0000)
The crypto.Signer interface takes pre-hased messages for ECDSA and RSA,
but the argument in the implementations was called “msg”, not “digest”,
which is confusing.

This change renames them to help clarify the intended use.

Change-Id: Ie2fb8753ca5280e493810d211c7c66223f94af88
Reviewed-on: https://go-review.googlesource.com/70950
Reviewed-by: Filippo Valsorda <hi@filippo.io>
src/crypto/ecdsa/ecdsa.go
src/crypto/rsa/rsa.go

index 817bf7deb635ab12140d9b8fa3f5ad47920a468e..755ed284a910b8c6093f5507cbbd00d697b35ffc 100644 (file)
@@ -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
        }
index 69a2b58a5a6980d6f0385625b842f87852edf179..0faca43e430766dac34d87a6c4b5e864866bb0f4 100644 (file)
@@ -92,17 +92,19 @@ func (priv *PrivateKey) Public() crypto.PublicKey {
        return &priv.PublicKey
 }
 
-// Sign signs msg with priv, reading randomness from rand. If opts is a
+// Sign signs digest with priv, reading randomness from rand. If opts is a
 // *PSSOptions then the PSS algorithm will be used, otherwise PKCS#1 v1.5 will
-// be used. 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*
-// functions in this package.
-func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
+// be used.
+//
+// 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* functions in this package directly.
+func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
        if pssOpts, ok := opts.(*PSSOptions); ok {
-               return SignPSS(rand, priv, pssOpts.Hash, msg, pssOpts)
+               return SignPSS(rand, priv, pssOpts.Hash, digest, pssOpts)
        }
 
-       return SignPKCS1v15(rand, priv, opts.HashFunc(), msg)
+       return SignPKCS1v15(rand, priv, opts.HashFunc(), digest)
 }
 
 // Decrypt decrypts ciphertext with priv. If opts is nil or of type