1 //! RSA OAEP encryption. 2 3 use super::super::{padding, public, PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN}; 4 use crate::{error, rand}; 5 use alloc::boxed::Box; 6 7 impl public::Key { 8 /// OAEP Encrypts `plaintext`, returning the ciphertext. encrypt_oaep_bytes_less_safe( &self, encoding: &'static padding::OaepEncoding, plaintext: &[u8], rng: &dyn rand::SecureRandom, ) -> Result<Box<[u8]>, error::Unspecified>9 pub fn encrypt_oaep_bytes_less_safe( 10 &self, 11 encoding: &'static padding::OaepEncoding, 12 plaintext: &[u8], 13 rng: &dyn rand::SecureRandom, 14 ) -> Result<Box<[u8]>, error::Unspecified> { 15 let padded = padding::oaep_encode(encoding, plaintext, self.n().len_bits(), rng)?; 16 let mut ciphertext = [0u8; PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN]; 17 let ciphertext = self.exponentiate(untrusted::Input::from(&padded), &mut ciphertext)?; 18 Ok(ciphertext.into()) 19 } 20 } 21