diff options
Diffstat (limited to 'openpgp/src/crypto/backend/nettle/asymmetric.rs')
-rw-r--r-- | openpgp/src/crypto/backend/nettle/asymmetric.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/openpgp/src/crypto/backend/nettle/asymmetric.rs b/openpgp/src/crypto/backend/nettle/asymmetric.rs index e6f6eb72..c2af71e8 100644 --- a/openpgp/src/crypto/backend/nettle/asymmetric.rs +++ b/openpgp/src/crypto/backend/nettle/asymmetric.rs @@ -227,7 +227,13 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> { match self.mpis() { mpi::PublicKey::RSA { e, n } => { // The ciphertext has the length of the modulus. - let mut esk = vec![0u8; n.value().len()]; + let ciphertext_len = n.value().len(); + if data.len() + 11 > ciphertext_len { + return Err(Error::InvalidArgument( + "Plaintext data too large".into()).into()); + } + + let mut esk = vec![0u8; ciphertext_len]; let mut rng = Yarrow::default(); let pk = rsa::PublicKey::new(n.value(), e.value())?; rsa::encrypt_pkcs1(&pk, &mut rng, data, |