[][src]Trait kernel::hil::symmetric_encryption::AES128

pub trait AES128<'a> {
    fn enable(&self);
fn disable(&self);
fn set_client(&'a self, client: &'a dyn Client<'a>);
fn set_key(&self, key: &[u8]) -> ReturnCode;
fn set_iv(&self, iv: &[u8]) -> ReturnCode;
fn start_message(&self);
fn crypt(
        &'a self,
        source: Option<&'a mut [u8]>,
        dest: &'a mut [u8],
        start_index: usize,
        stop_index: usize
    ) -> Option<(ReturnCode, Option<&'a mut [u8]>, &'a mut [u8])>; }

Required methods

fn enable(&self)

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

fn disable(&self)

Disable the AES hardware

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

Set the client instance which will receive crypt_done() callbacks

fn set_key(&self, key: &[u8]) -> ReturnCode

Set the encryption key. Returns EINVAL if length is not AES128_KEY_SIZE

fn set_iv(&self, iv: &[u8]) -> ReturnCode

Set the IV (or initial counter). Returns EINVAL if length is not AES128_BLOCK_SIZE

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.

fn crypt(
    &'a self,
    source: Option<&'a mut [u8]>,
    dest: &'a mut [u8],
    start_index: usize,
    stop_index: usize
) -> Option<(ReturnCode, Option<&'a mut [u8]>, &'a 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 AES128_BLOCK_SIZE. Otherwise, Some(EINVAL, ...) will be returned.

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

If an encryption operation is already in progress, Some(EBUSY, ...) 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().

Loading content...

Implementors

Loading content...