Struct hacl::aead::Aead

source ·
pub struct Aead { /* private fields */ }
Expand description

The Aead struct allows to re-use a key without having to initialize it every time.

Implementations§

source§

impl Aead

source

pub fn new(alg: Algorithm, k: &[u8]) -> Result<Self, Error>

Create a new Aead cipher with the given Algorithm alg and key k. If the algorithm is not supported or the state generation fails, this function returns an Error.

To get an Aead instance without setting a key immediately see init.

source

pub fn init(mode: Algorithm) -> Result<Self, Error>

Initialize a new Aead object without a key. Use set_key to do so later.

source

pub fn set_key(self, k: &[u8]) -> Result<Self, Error>

Set the key for this instance. This consumes the Aead and returns a new instance with the key.

source

pub fn set_random_key(&mut self) -> Result<(), Error>

Generate a new random key for this instance. This consumes the Aead and returns a new instance with the key.

source

pub fn key_gen(&self) -> Vec<u8>

Generate a random key.

source

pub fn nonce_gen(&self) -> Vec<u8>

Generate a nonce.

source

pub const fn nonce_size(&self) -> usize

Get the nonce size of this Aead in bytes.

source

pub const fn key_size(&self) -> usize

Get the key size of this Aead in bytes.

source

pub const fn tag_size(&self) -> usize

Get the tag size of this Aead in bytes.

source

pub fn encrypt( &self, msg: &[u8], iv: &[u8], aad: &Aad, ) -> Result<(Ciphertext, Vec<u8>), Error>

Encrypt with the algorithm and key of this Aead. Returns (ctxt, tag) or an Error.

source

pub fn encrypt_combined( &self, msg: &[u8], iv: &[u8], aad: &Aad, ) -> Result<Ciphertext, Error>

Encrypt with the algorithm and key of this Aead. Returns (ctxt || tag) or an Error. This is more efficient if the tag needs to be appended to the cipher text.

source

pub fn encrypt_in_place( &self, payload: &mut [u8], iv: &[u8], aad: &Aad, ) -> Result<Vec<u8>, Error>

Encrypt with the algorithm and key of this Aead. Returns the cipher text in the payload and a tag or an Error.

source

pub fn decrypt( &self, ctxt: &[u8], tag: &[u8], iv: &[u8], aad: &Aad, ) -> Result<Vec<u8>, Error>

Decrypt with the algorithm and key of this Aead. Returns msg or an Error.

source

pub fn decrypt_combined( &self, ctxt: &[u8], iv: &[u8], aad: &Aad, ) -> Result<Vec<u8>, Error>

Decrypt with the algorithm and key of this Aead. Returns msg or an Error. This takes the combined ctxt || tag as input and might be more efficient than decrypt.

source

pub fn decrypt_in_place( &self, payload: &mut [u8], tag: &[u8], iv: &[u8], aad: &Aad, ) -> Result<(), Error>

Decrypt with the algorithm and key of this Aead.

Returns an Error if decryption failed. The decrypted payload is written into payload.

Trait Implementations§

source§

impl Drop for Aead

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Aead

§

impl RefUnwindSafe for Aead

§

impl !Send for Aead

§

impl !Sync for Aead

§

impl Unpin for Aead

§

impl UnwindSafe for Aead

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

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

§

fn vzip(self) -> V