pub struct AESCCM<E>where
E: Encrypt,{ /* private fields */ }Expand description
The primary AES-CCM engine context carrying encryption keys, active nonces, and the peripheral driver.
Implementations§
Source§impl<E> AESCCM<E>where
E: Encrypt,
impl<E> AESCCM<E>where
E: Encrypt,
Sourcepub fn new(aes: E, key: [u8; 16]) -> Self
pub fn new(aes: E, key: [u8; 16]) -> Self
Creates a new AES-CCM peripheral engine using a key and an hardware peripheral implementation.
Sourcepub fn encrypt<T>(
&mut self,
packet_data: &PacketData<T>,
) -> Result<Frame, Error>where
T: Serialize + DeserializeOwned,
pub fn encrypt<T>(
&mut self,
packet_data: &PacketData<T>,
) -> Result<Frame, Error>where
T: Serialize + DeserializeOwned,
Encrypts packet data into a lightweight, authenticated over-the-air AES-CCM format.
+-----------------------------------------------------------------------+
| OVER-THE-AIR FRAME |
+--------------------------+--------------------+-----------------------+
| dst (6 Bytes) | flags (1 Byte) | ctr (5 Bytes) | -> HEADER (12 Bytes)
+--------------------------+--------------------+-----------------------+
| Ciphertext (N Bytes) | -> PAYLOAD
+-----------------------------------------------------------------------+
| Tag (16 Bytes) | -> MAC/TAG
+-----------------------------------------------------------------------+§Errors
Returns Err(PacketError::BufferOverflow) if serialization fails or
Err(PacketError::AESCounterOverflow) if the nonce limits are exceeded.
Sourcepub fn decrypt<T>(&mut self, bytes: &mut [u8]) -> Result<PacketData<T>, Error>where
T: Serialize + DeserializeOwned,
pub fn decrypt<T>(&mut self, bytes: &mut [u8]) -> Result<PacketData<T>, Error>where
T: Serialize + DeserializeOwned,
Decrypts and authenticates an incoming packet from a mutable slice buffer in-place.
§Errors
Returns:
PacketError::InvalidFormatif parsing fails.PacketError::Duplicateif a potential replay attack is intercepted.PacketError::Corruptedif the tag verification fails.
Auto Trait Implementations§
impl<E> Freeze for AESCCM<E>where
E: Freeze,
impl<E> RefUnwindSafe for AESCCM<E>where
E: RefUnwindSafe,
impl<E> Send for AESCCM<E>where
E: Send,
impl<E> Sync for AESCCM<E>where
E: Sync,
impl<E> Unpin for AESCCM<E>where
E: Unpin,
impl<E> UnsafeUnpin for AESCCM<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for AESCCM<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more