pub struct Gcm<B: BlockCipher + Zeroize + ZeroizeOnDrop> { /* private fields */ }Expand description
GCM mode implementation
Implementations§
Source§impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Gcm<B>
impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Gcm<B>
Sourcepub fn new(cipher: B) -> Result<Self>
pub fn new(cipher: B) -> Result<Self>
Creates a key-only GCM instance with a fixed 16-byte tag.
The nonce is deliberately supplied to each encrypt/decrypt operation; retaining it in this reusable object made accidental nonce reuse easy.
Sourcepub fn new_with_tag_len(cipher: B, tag_len: usize) -> Result<Self>
pub fn new_with_tag_len(cipher: B, tag_len: usize) -> Result<Self>
Creates a new GCM mode instance with specified tag length (in bytes).
Truncated tags are supported only from 12 through 16 bytes.
Sourcepub fn internal_encrypt<const N: usize>(
&self,
nonce: &Nonce<N>,
plaintext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<Vec<u8>>where
Nonce<N>: AesGcmCompatible,
pub fn internal_encrypt<const N: usize>(
&self,
nonce: &Nonce<N>,
plaintext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<Vec<u8>>where
Nonce<N>: AesGcmCompatible,
Internal encrypt method - exposed for testing
Sourcepub fn internal_decrypt<const N: usize>(
&self,
nonce: &Nonce<N>,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<Vec<u8>>where
Nonce<N>: AesGcmCompatible,
pub fn internal_decrypt<const N: usize>(
&self,
nonce: &Nonce<N>,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<Vec<u8>>where
Nonce<N>: AesGcmCompatible,
Internal decrypt method; exposed for testing.
Sourcepub fn internal_decrypt_protected<const N: usize>(
&self,
nonce: &Nonce<N>,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<ZeroizingBytes>where
Nonce<N>: AesGcmCompatible,
pub fn internal_decrypt_protected<const N: usize>(
&self,
nonce: &Nonce<N>,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> Result<ZeroizingBytes>where
Nonce<N>: AesGcmCompatible,
Decrypt into exact-size storage that clears itself on all internal error and drop paths. Callers should use this for intermediate plaintext that has not yet crossed a public output boundary.
Trait Implementations§
Source§impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> AuthenticatedCipher for Gcm<B>
impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> AuthenticatedCipher for Gcm<B>
Source§impl<B: Clone + BlockCipher + Zeroize + ZeroizeOnDrop> Clone for Gcm<B>
impl<B: Clone + BlockCipher + Zeroize + ZeroizeOnDrop> Clone for Gcm<B>
Source§impl<'a, B> DecryptOperation<'a, Gcm<B>> for GcmDecryptOperation<'a, B>
impl<'a, B> DecryptOperation<'a, Gcm<B>> for GcmDecryptOperation<'a, B>
Source§fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self
fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self
Set the nonce for decryption
Source§fn decrypt(
self,
ciphertext: &'a <Gcm<B> as SymmetricCipher>::Ciphertext,
) -> Result<Vec<u8>, CoreError>
fn decrypt( self, ciphertext: &'a <Gcm<B> as SymmetricCipher>::Ciphertext, ) -> Result<Vec<u8>, CoreError>
Set ciphertext and execute decryption
Source§impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Drop for Gcm<B>
impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Drop for Gcm<B>
Source§impl<'a, B> EncryptOperation<'a, Gcm<B>> for GcmEncryptOperation<'a, B>
impl<'a, B> EncryptOperation<'a, Gcm<B>> for GcmEncryptOperation<'a, B>
Source§fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self
fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self
Set the nonce for encryption
Source§impl<B> SymmetricCipher for Gcm<B>
impl<B> SymmetricCipher for Gcm<B>
Source§type Key = <B as BlockCipher>::Key
type Key = <B as BlockCipher>::Key
Key type with appropriate algorithm binding
Source§type Ciphertext = Ciphertext
type Ciphertext = Ciphertext
Ciphertext output type
Source§type EncryptOperation<'a> = GcmEncryptOperation<'a, B>
where
Self: 'a
type EncryptOperation<'a> = GcmEncryptOperation<'a, B> where Self: 'a
Operation type for encryption operations
Source§type DecryptOperation<'a> = GcmDecryptOperation<'a, B>
where
Self: 'a
type DecryptOperation<'a> = GcmDecryptOperation<'a, B> where Self: 'a
Operation type for decryption operations
Source§fn encrypt(&self) -> <Self as SymmetricCipher>::EncryptOperation<'_>
fn encrypt(&self) -> <Self as SymmetricCipher>::EncryptOperation<'_>
Begin encryption operation
Source§fn decrypt(&self) -> <Self as SymmetricCipher>::DecryptOperation<'_>
fn decrypt(&self) -> <Self as SymmetricCipher>::DecryptOperation<'_>
Begin decryption operation
Source§fn generate_key<R: RngCore + CryptoRng>(
rng: &mut R,
) -> Result<<Self as SymmetricCipher>::Key, CoreError>
fn generate_key<R: RngCore + CryptoRng>( rng: &mut R, ) -> Result<<Self as SymmetricCipher>::Key, CoreError>
Generate a new random key
Source§fn generate_nonce<R: RngCore + CryptoRng>(
rng: &mut R,
) -> Result<<Self as SymmetricCipher>::Nonce, CoreError>
fn generate_nonce<R: RngCore + CryptoRng>( rng: &mut R, ) -> Result<<Self as SymmetricCipher>::Nonce, CoreError>
Generate a new random nonce
Source§fn derive_key_from_bytes(
bytes: &[u8],
) -> Result<<Self as SymmetricCipher>::Key, CoreError>
fn derive_key_from_bytes( bytes: &[u8], ) -> Result<<Self as SymmetricCipher>::Key, CoreError>
Derive a key from arbitrary bytes
Source§impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Zeroize for Gcm<B>
impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Zeroize for Gcm<B>
impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> ZeroizeOnDrop for Gcm<B>
Auto Trait Implementations§
impl<B> Freeze for Gcm<B>where
B: Freeze,
impl<B> RefUnwindSafe for Gcm<B>where
B: RefUnwindSafe,
impl<B> Send for Gcm<B>where
B: Send,
impl<B> Sync for Gcm<B>where
B: Sync,
impl<B> Unpin for Gcm<B>where
B: Unpin,
impl<B> UnsafeUnpin for Gcm<B>where
B: UnsafeUnpin,
impl<B> UnwindSafe for Gcm<B>where
B: 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