Gcm

Struct Gcm 

Source
pub struct Gcm<B: BlockCipher + Zeroize + ZeroizeOnDrop> { /* private fields */ }
Expand description

GCM mode implementation

Implementations§

Source§

impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> Gcm<B>

Source

pub fn new<const N: usize>(cipher: B, nonce: &Nonce<N>) -> Result<Self>

Creates a new GCM mode instance with default (16-byte) tag.

Source

pub fn new_with_tag_len<const N: usize>( cipher: B, nonce: &Nonce<N>, tag_len: usize, ) -> Result<Self>

Creates a new GCM mode instance with specified tag length (in bytes).

tag_len must be between 1 and 16 (inclusive).

Source

pub fn internal_encrypt( &self, plaintext: &[u8], associated_data: Option<&[u8]>, ) -> Result<Vec<u8>>

Internal encrypt method - exposed for testing

Source

pub fn internal_decrypt( &self, ciphertext: &[u8], associated_data: Option<&[u8]>, ) -> Result<Vec<u8>>

Internal decrypt method with improved constant-time implementation - exposed for testing

Trait Implementations§

Source§

impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> AuthenticatedCipher for Gcm<B>

Source§

const TAG_SIZE: usize = 16usize

Authentication tag size in bytes
Source§

const ALGORITHM_ID: &'static str = "GCM"

Static algorithm identifier for compile-time checking
Source§

fn name() -> String

Returns the authenticated cipher algorithm name
Source§

impl<B: Clone + BlockCipher + Zeroize + ZeroizeOnDrop> Clone for Gcm<B>

Source§

fn clone(&self) -> Gcm<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, B: BlockCipher + Zeroize + ZeroizeOnDrop> DecryptOperation<'a, Gcm<B>> for GcmDecryptOperation<'a, B>

Source§

fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self

Set the nonce for decryption
Source§

fn with_aad(self, aad: &'a [u8]) -> Self

Set associated data for authenticated decryption
Source§

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>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, B: BlockCipher + Zeroize + ZeroizeOnDrop> EncryptOperation<'a, Gcm<B>> for GcmEncryptOperation<'a, B>

Source§

fn with_nonce(self, nonce: &'a <Gcm<B> as SymmetricCipher>::Nonce) -> Self

Set the nonce for encryption
Source§

fn with_aad(self, aad: &'a [u8]) -> Self

Set associated data for authenticated encryption
Source§

fn encrypt(self, plaintext: &'a [u8]) -> Result<Ciphertext, CoreError>

Set plaintext and execute encryption
Source§

impl<B: BlockCipher + Clone + Zeroize + ZeroizeOnDrop> SecureZeroingType for Gcm<B>

Source§

fn zeroed() -> Self

Create a zeroed instance
Source§

fn secure_clone(&self) -> Self

Create a secure clone that preserves security properties Read more
Source§

impl<B: BlockCipher + Zeroize + ZeroizeOnDrop> SymmetricCipher for Gcm<B>

Source§

type Key = SecretBytes<32>

Key type with appropriate algorithm binding
Source§

type Nonce = Nonce<12>

Nonce type with appropriate size constraint
Source§

type Ciphertext = Ciphertext

Ciphertext output type
Source§

type EncryptOperation<'a> = GcmEncryptOperation<'a, B> where Self: 'a

Operation type for encryption operations
Source§

type DecryptOperation<'a> = GcmDecryptOperation<'a, B> where Self: 'a

Operation type for decryption operations
Source§

fn name() -> &'static str

Returns the symmetric cipher algorithm name
Source§

fn encrypt(&self) -> <Self as SymmetricCipher>::EncryptOperation<'_>

Begin encryption operation
Source§

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>

Generate a new random key
Source§

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>

Derive a key from arbitrary bytes
Source§

impl<B> Zeroize for Gcm<B>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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> UnwindSafe for Gcm<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V