Skip to main content

decrypt

Function decrypt 

Source
pub fn decrypt(
    key: &[u8; 16],
    nonce: &[u8; 13],
    aad: &[u8],
    ciphertext: &[u8],
) -> Result<Vec<u8>>
Expand description

AES-128-CCM-128 decrypt: input is ciphertext || tag (so ciphertext.len() >= AEAD_TAG_LEN). Returns the plaintext if the tag verifies.

aad may be empty. The ccm crate verifies the tag in constant time internally via subtle.

This builds a fresh key schedule on every call. Prefer SessionAead for any path that decrypts more than once per key (e.g. every inbound message on a session) to avoid repeating AES key expansion.

§Errors

Returns Error::EncryptedBlobDecryptionFailed on any authentication or decryption failure. The error is intentionally not specific — distinguishing “wrong key” from “tampered ciphertext” is a spec-level design choice that prevents oracle attacks.