if err := checkPub(pub); err != nil {
return nil, err
}
- k := (pub.N.BitLen() + 7) / 8
+ k := pub.Size()
if len(msg) > k-11 {
return nil, ErrMessageTooLong
}
if err := checkPub(&priv.PublicKey); err != nil {
return err
}
- k := (priv.N.BitLen() + 7) / 8
+ k := priv.Size()
if k-(len(key)+3+8) < 0 {
return ErrDecryption
}
// in order to maintain constant memory access patterns. If the plaintext was
// valid then index contains the index of the original message in em.
func decryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) (valid int, em []byte, index int, err error) {
- k := (priv.N.BitLen() + 7) / 8
+ k := priv.Size()
if k < 11 {
err = ErrDecryption
return
}
tLen := len(prefix) + hashLen
- k := (priv.N.BitLen() + 7) / 8
+ k := priv.Size()
if k < tLen+11 {
return nil, ErrMessageTooLong
}
}
tLen := len(prefix) + hashLen
- k := (pub.N.BitLen() + 7) / 8
+ k := pub.Size()
if k < tLen+11 {
return ErrVerification
}
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 {
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
}
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