pub struct Gcm<C> { /* private fields */ }Expand description
Galois/Counter Mode (GCM) with a full 128-bit authentication tag.
Per NIST SP 800-38D, this implementation enforces a per-call payload limit
of (2^32 - 2) counter blocks (68_719_476_704 bytes) so the 32-bit
counter field cannot wrap.
Callers must still ensure nonce uniqueness per key; this API is stateless and
cannot enforce global (key, nonce) uniqueness.
§Examples
use cryptography::{Aes256, Gcm};
let key = [0x11u8; 32];
let nonce = [0x22u8; 12];
let aad = b"hdr";
let mut ciphertext = *b"payload";
let aead = Gcm::new(Aes256::new(&key));
let tag = aead.encrypt(&nonce, aad, &mut ciphertext);
let mut recovered = ciphertext;
assert!(aead.decrypt(&nonce, aad, &mut recovered, &tag));
assert_eq!(recovered, *b"payload");Implementations§
Source§impl<C: BlockCipher> Gcm<C>
impl<C: BlockCipher> Gcm<C>
Sourcepub fn compute_tag(
&self,
nonce: &[u8],
aad: &[u8],
ciphertext: &[u8],
) -> [u8; 16]
pub fn compute_tag( &self, nonce: &[u8], aad: &[u8], ciphertext: &[u8], ) -> [u8; 16]
Compute the GCM authentication tag over aad and ciphertext.
Panics if ciphertext.len() exceeds the SP 800-38D per-call bound of
68_719_476_704 bytes.
Trait Implementations§
Source§impl<C: BlockCipher> Aead for Gcm<C>
impl<C: BlockCipher> Aead for Gcm<C>
Source§fn encrypt_in_place(
&self,
nonce: &[u8],
aad: &[u8],
data: &mut [u8],
) -> Self::Tag
fn encrypt_in_place( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], ) -> Self::Tag
Encrypt
data in place and return its authentication tag.Source§fn decrypt_in_place(
&self,
nonce: &[u8],
aad: &[u8],
data: &mut [u8],
tag: &Self::Tag,
) -> bool
fn decrypt_in_place( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], tag: &Self::Tag, ) -> bool
Decrypt
data in place after authenticating tag.Auto Trait Implementations§
impl<C> Freeze for Gcm<C>where
C: Freeze,
impl<C> RefUnwindSafe for Gcm<C>where
C: RefUnwindSafe,
impl<C> Send for Gcm<C>where
C: Send,
impl<C> Sync for Gcm<C>where
C: Sync,
impl<C> Unpin for Gcm<C>where
C: Unpin,
impl<C> UnsafeUnpin for Gcm<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for Gcm<C>where
C: 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