aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/rsa/rsa.go
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2020-05-07 23:27:25 -0400
committerDmitri Shuralyov <dmitshur@golang.org>2020-05-07 23:31:52 -0400
commitdd98c0ca3f19a8de7a8422c92839ff985f9827e4 (patch)
tree6f13317816f13a9cdddf2561a70c6757ab6331b2 /src/crypto/rsa/rsa.go
parenta9d2e3abf772ee2c49394430545df1fa83699f04 (diff)
parent7d232ab276fe81c1c8552d4a809af7a593bb294b (diff)
downloadgo-dd98c0ca3f19a8de7a8422c92839ff985f9827e4.tar.gz
go-dd98c0ca3f19a8de7a8422c92839ff985f9827e4.zip
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: I083d1e4e997b30d9fab10940401eaf160e36f6c1
Diffstat (limited to 'src/crypto/rsa/rsa.go')
-rw-r--r--src/crypto/rsa/rsa.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
index 4c67644ccb..94a66216a5 100644
--- a/src/crypto/rsa/rsa.go
+++ b/src/crypto/rsa/rsa.go
@@ -51,6 +51,9 @@ type PublicKey struct {
boring unsafe.Pointer
}
+// Any methods implemented on PublicKey might need to also be implemented on
+// PrivateKey, as the latter embeds the former and will expose its methods.
+
// Size returns the modulus size in bytes. Raw signatures and ciphertexts
// for or by this public key will have the same size.
func (pub *PublicKey) Size() int {
@@ -118,6 +121,27 @@ func (priv *PrivateKey) Public() crypto.PublicKey {
return &priv.PublicKey
}
+// Equal reports whether priv and x have equivalent values. It ignores
+// Precomputed values.
+func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool {
+ xx, ok := x.(*PrivateKey)
+ if !ok {
+ return false
+ }
+ if !priv.PublicKey.Equal(&xx.PublicKey) || priv.D.Cmp(xx.D) != 0 {
+ return false
+ }
+ if len(priv.Primes) != len(xx.Primes) {
+ return false
+ }
+ for i := range priv.Primes {
+ if priv.Primes[i].Cmp(xx.Primes[i]) != 0 {
+ return false
+ }
+ }
+ return true
+}
+
// 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. digest must be the result of hashing the input message using