diff options
author | Pascal S. de Kloe <pascal@quies.net> | 2018-03-31 15:45:35 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-04-03 15:55:48 +0000 |
commit | daa2d547734a3e5693b06d7d09e38ff1e617c89f (patch) | |
tree | 692a9184c1e7774bbf3053843edc98ed118a5269 /src/crypto/rsa/rsa.go | |
parent | 01237b1362db59c583d136289a9a4b0ac8ea5170 (diff) | |
download | go-daa2d547734a3e5693b06d7d09e38ff1e617c89f.tar.gz go-daa2d547734a3e5693b06d7d09e38ff1e617c89f.zip |
crypto/rsa: add PublicKey.Size accessor
Provide the fixed size from the key pair.
Change-Id: I365c8d0f7d915229ef089e46458d4c83273fc648
Reviewed-on: https://go-review.googlesource.com/103876
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/crypto/rsa/rsa.go')
-rw-r--r-- | src/crypto/rsa/rsa.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go index 0faca43e43..c9fa6fbc35 100644 --- a/src/crypto/rsa/rsa.go +++ b/src/crypto/rsa/rsa.go @@ -42,6 +42,11 @@ type PublicKey struct { E int // public exponent } +// Size returns the number of bytes for signatures from this key. +func (pub *PublicKey) Size() int { + return (pub.N.BitLen() + 7) / 8 +} + // OAEPOptions is an interface for passing options to OAEP decryption using the // crypto.Decrypter interface. type OAEPOptions struct { @@ -373,7 +378,7 @@ func EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, l return nil, err } hash.Reset() - k := (pub.N.BitLen() + 7) / 8 + k := pub.Size() if len(msg) > k-2*hash.Size()-2 { return nil, ErrMessageTooLong } @@ -587,7 +592,7 @@ func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext if err := checkPub(&priv.PublicKey); err != nil { return nil, err } - k := (priv.N.BitLen() + 7) / 8 + k := priv.Size() if len(ciphertext) > k || k < hash.Size()*2+2 { return nil, ErrDecryption |