Skip to main content

AES

Trait AES 

Source
pub trait AES<'a, K: AESKeySize> {
    // Required methods
    fn enable(&self);
    fn disable(&self);
    fn set_client(&'a self, client: &'a dyn Client<'a>);
    fn set_key(&self, key: &[u8]) -> Result<(), ErrorCode>;
    fn set_iv(&self, iv: &[u8]) -> Result<(), ErrorCode>;
    fn start_message(&self);
    fn crypt(
        &self,
        source: Option<&'static mut [u8]>,
        dest: &'static mut [u8],
        start_index: usize,
        stop_index: usize,
    ) -> Option<(Result<(), ErrorCode>, Option<&'static mut [u8]>, &'static mut [u8])>;
}

Required Methods§

Source

fn enable(&self)

Enable the AES hardware. Must be called before any other methods

Source

fn disable(&self)

Disable the AES hardware

Source

fn set_client(&'a self, client: &'a dyn Client<'a>)

Set the client instance which will receive crypt_done() callbacks

Source

fn set_key(&self, key: &[u8]) -> Result<(), ErrorCode>

Set the encryption key. Returns INVAL if length is not AESKeySize::LENGTH

Source

fn set_iv(&self, iv: &[u8]) -> Result<(), ErrorCode>

Set the IV (or initial counter). Returns INVAL if length is not AES_BLOCK_SIZE

Source

fn start_message(&self)

Begin a new message (with the configured IV) when crypt() is next called. Multiple calls to crypt() may be made between calls to start_message(), allowing the encryption context to extend over non-contiguous extents of data.

If an encryption operation is in progress, this method instead has no effect.

Source

fn crypt( &self, source: Option<&'static mut [u8]>, dest: &'static mut [u8], start_index: usize, stop_index: usize, ) -> Option<(Result<(), ErrorCode>, Option<&'static mut [u8]>, &'static mut [u8])>

Request an encryption/decryption

If the source buffer is not None, the encryption input will be that entire buffer. Otherwise the destination buffer at indices between start_index and stop_index will provide the input, which will be overwritten.

If None is returned, the client’s crypt_done method will eventually be called, and the portion of the data buffer between start_index and stop_index will hold the result of the encryption/decryption.

If Some(result, source, dest) is returned, result is the error condition and source and dest are the buffers that were passed to crypt.

The indices start_index and stop_index must be valid offsets in the destination buffer, and the length stop_index - start_index must be a multiple of AES_BLOCK_SIZE. Otherwise, Some(INVAL, ...) will be returned.

If the source buffer is not None, its length must be stop_index - start_index. Otherwise, Some(INVAL, ...) will be returned.

If an encryption operation is already in progress, Some(BUSY, ...) will be returned.

For correct operation, the methods set_key and set_iv must have previously been called to set the buffers containing the key and the IV (or initial counter value), and a method set_mode_*() must have been called to set the desired mode. These settings persist across calls to crypt().

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§