fn unwrap_with_padding()

in aws-lc-rs/src/key_wrap.rs [370:408]


    fn unwrap_with_padding<'output>(
        self,
        ciphertext: &[u8],
        output: &'output mut [u8],
    ) -> Result<&'output mut [u8], Unspecified> {
        let mut aes_key = MaybeUninit::<AES_KEY>::uninit();

        if 0 != unsafe {
            AES_set_decrypt_key(
                self.key.as_ptr(),
                (self.key.len() * 8).try_into().map_err(|_| Unspecified)?,
                aes_key.as_mut_ptr(),
            )
        } {
            return Err(Unspecified);
        }

        let aes_key = unsafe { aes_key.assume_init() };

        let mut out_len: usize = 0;

        // AWS-LC validates the following:
        // * in_len >= AES_BLOCK_SIZE
        // * max_out >= in_len - 8
        if 1 != indicator_check!(unsafe {
            AES_unwrap_key_padded(
                &aes_key,
                output.as_mut_ptr(),
                &mut out_len,
                output.len(),
                ciphertext.as_ptr(),
                ciphertext.len(),
            )
        }) {
            return Err(Unspecified);
        }

        Ok(&mut output[..out_len])
    }