Skip to main content

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(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.

Source

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.

Source

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

Internal encrypt method - exposed for testing

Source

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

Internal decrypt method; exposed for testing.

Source

pub fn internal_decrypt_protected<const N: usize>( &self, nonce: &Nonce<N>, ciphertext: &[u8], associated_data: Option<&[u8]>, ) -> Result<ZeroizingBytes>

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>

Source§

const TAG_SIZE: usize = GCM_TAG_SIZE

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 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, B> 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§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a, B> 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> SymmetricCipher for Gcm<B>

Source§

type Key = <B as BlockCipher>::Key

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: BlockCipher + Zeroize + ZeroizeOnDrop> Zeroize for Gcm<B>

Source§

fn zeroize(&mut self)

Source§

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> 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.