pub trait AES128<'a> {
// 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§
Sourcefn set_client(&'a self, client: &'a dyn Client<'a>)
fn set_client(&'a self, client: &'a dyn Client<'a>)
Set the client instance which will receive crypt_done()
callbacks
Sourcefn set_key(&self, key: &[u8]) -> Result<(), ErrorCode>
fn set_key(&self, key: &[u8]) -> Result<(), ErrorCode>
Set the encryption key.
Returns INVAL
if length is not AES128_KEY_SIZE
Sourcefn set_iv(&self, iv: &[u8]) -> Result<(), ErrorCode>
fn set_iv(&self, iv: &[u8]) -> Result<(), ErrorCode>
Set the IV (or initial counter).
Returns INVAL
if length is not AES128_BLOCK_SIZE
Sourcefn start_message(&self)
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.
Sourcefn 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])>
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
AES128_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()
.