Skip to content

Commit 507ca08

Browse files
committed
crypto/{ecdsa,rsa}: rename argument to PrivateKey.Sign.
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>
1 parent 5a4b6bc commit 507ca08

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/crypto/ecdsa/ecdsa.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ func (priv *PrivateKey) Public() crypto.PublicKey {
6464
return &priv.PublicKey
6565
}
6666

67-
// Sign signs msg with priv, reading randomness from rand. This method is
68-
// intended to support keys where the private part is kept in, for example, a
69-
// hardware module. Common uses should use the Sign function in this package
70-
// directly.
71-
func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
72-
r, s, err := Sign(rand, priv, msg)
67+
// Sign signs digest with priv, reading randomness from rand. The opts argument
68+
// is not currently used but, in keeping with the crypto.Signer interface,
69+
// should be the hash function used to digest the message.
70+
//
71+
// This method implements crypto.Signer, which is an interface to support keys
72+
// where the private part is kept in, for example, a hardware module. Common
73+
// uses should use the Sign function in this package directly.
74+
func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
75+
r, s, err := Sign(rand, priv, digest)
7376
if err != nil {
7477
return nil, err
7578
}

src/crypto/rsa/rsa.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,19 @@ func (priv *PrivateKey) Public() crypto.PublicKey {
9292
return &priv.PublicKey
9393
}
9494

95-
// Sign signs msg with priv, reading randomness from rand. If opts is a
95+
// Sign signs digest with priv, reading randomness from rand. If opts is a
9696
// *PSSOptions then the PSS algorithm will be used, otherwise PKCS#1 v1.5 will
97-
// be used. This method is intended to support keys where the private part is
98-
// kept in, for example, a hardware module. Common uses should use the Sign*
99-
// functions in this package.
100-
func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
97+
// be used.
98+
//
99+
// This method implements crypto.Signer, which is an interface to support keys
100+
// where the private part is kept in, for example, a hardware module. Common
101+
// uses should use the Sign* functions in this package directly.
102+
func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
101103
if pssOpts, ok := opts.(*PSSOptions); ok {
102-
return SignPSS(rand, priv, pssOpts.Hash, msg, pssOpts)
104+
return SignPSS(rand, priv, pssOpts.Hash, digest, pssOpts)
103105
}
104106

105-
return SignPKCS1v15(rand, priv, opts.HashFunc(), msg)
107+
return SignPKCS1v15(rand, priv, opts.HashFunc(), digest)
106108
}
107109

108110
// Decrypt decrypts ciphertext with priv. If opts is nil or of type

0 commit comments

Comments
 (0)