#[repr(u8)]
pub enum SymmetricKeyAlgorithm {
Show 14 variants Plaintext = 0, IDEA = 1, TripleDES = 2, CAST5 = 3, Blowfish = 4, AES128 = 7, AES192 = 8, AES256 = 9, Twofish = 10, Camellia128 = 11, Camellia192 = 12, Camellia256 = 13, Private10 = 110, Other(u8),
}
Expand description

Variants§

§

Plaintext = 0

Plaintext or unencrypted data

§

IDEA = 1

IDEA

§

TripleDES = 2

Triple-DES

§

CAST5 = 3

CAST5

§

Blowfish = 4

Blowfish

§

AES128 = 7

AES with 128-bit key

§

AES192 = 8

AES with 192-bit key

§

AES256 = 9

AES with 256-bit key

§

Twofish = 10

Twofish with 256-bit key

§

Camellia128 = 11

Camellia with 128-bit key

§

Camellia192 = 12

Camellia with 192-bit key

§

Camellia256 = 13

Camellia with 256-bit key

§

Private10 = 110

§

Other(u8)

Implementations§

source§

impl SymmetricKeyAlgorithm

source

pub fn block_size(self) -> usize

The size of a single block in bytes. Based on https://github.com/gpg/libgcrypt/blob/master/cipher

source

pub fn key_size(self) -> usize

The size of a single block in bytes. Based on https://github.com/gpg/libgcrypt/blob/master/cipher

source

pub fn decrypt<'a>( self, key: &[u8], ciphertext: &'a mut [u8] ) -> Result<&'a [u8]>

Decrypt the data using CFB mode, without padding. Overwrites the input. Uses an IV of all zeroes, as specified in the openpgp cfb mode. Does resynchronization.

source

pub fn decrypt_protected<'a>( self, key: &[u8], ciphertext: &'a mut [u8] ) -> Result<&'a [u8]>

Decrypt the data using CFB mode, without padding. Overwrites the input. Uses an IV of all zeroes, as specified in the openpgp cfb mode. Does not do resynchronization.

source

pub fn decrypt_with_iv<'a>( self, key: &[u8], iv_vec: &[u8], ciphertext: &'a mut [u8], resync: bool ) -> Result<(&'a [u8], &'a [u8])>

Decrypt the data using CFB mode, without padding. Overwrites the input.

OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and prefixes the plaintext with BS+2 octets of random data, such that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB resynchronization after encrypting those BS+2 octets.

Thus, for an algorithm that has a block size of 8 octets (64 bits), the IV is 10 octets long and octets 7 and 8 of the IV are the same as octets 9 and 10. For an algorithm with a block size of 16 octets (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate octets 15 and 16. Those extra two octets are an easy check for a correct key.

source

pub fn decrypt_with_iv_regular( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8] ) -> Result<()>

Decrypt the data using CFB mode, without padding. Overwrites the input. This is regular CFB, not OpenPgP CFB.

source

pub fn encrypt_with_rng<R: CryptoRng + Rng>( self, rng: &mut R, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8>>

Encrypt the data using CFB mode, without padding. Overwrites the input. Uses an IV of all zeroes, as specified in the openpgp cfb mode.

source

pub fn encrypt(self, key: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>

Same as encrypt_with_rng, but uses rand::thread_rng for RNG.

source

pub fn encrypt_protected_with_rng<R: CryptoRng + Rng>( self, rng: &mut R, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8>>

source

pub fn encrypt_protected(self, key: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>

source

pub fn encrypt_with_iv( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8], resync: bool ) -> Result<()>

Encrypt the data using CFB mode, without padding. Overwrites the input.

OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and prefixes the plaintext with BS+2 octets of random data, such that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB resynchronization after encrypting those BS+2 octets.

source

pub fn encrypt_with_iv_regular( self, key: &[u8], iv_vec: &[u8], plaintext: &mut [u8] ) -> Result<()>

Encrypt the data using CFB mode, without padding. Overwrites the input.

source

pub fn new_session_key<R: Rng + CryptoRng>(self, rng: &mut R) -> Vec<u8>

Generate a new session key.

Trait Implementations§

source§

impl Clone for SymmetricKeyAlgorithm

source§

fn clone(&self) -> SymmetricKeyAlgorithm

Returns a copy 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 Debug for SymmetricKeyAlgorithm

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for SymmetricKeyAlgorithm

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<SymmetricKeyAlgorithm> for u8

source§

fn from(enum_value: SymmetricKeyAlgorithm) -> Self

Converts to this type from the input type.
source§

impl From<u8> for SymmetricKeyAlgorithm

source§

fn from(number: u8) -> Self

Converts to this type from the input type.
source§

impl FromPrimitive for SymmetricKeyAlgorithm

§

type Primitive = u8

source§

fn from_primitive(number: Self::Primitive) -> Self

source§

impl PartialEq for SymmetricKeyAlgorithm

source§

fn eq(&self, other: &SymmetricKeyAlgorithm) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for SymmetricKeyAlgorithm

source§

impl DefaultIsZeroes for SymmetricKeyAlgorithm

source§

impl Eq for SymmetricKeyAlgorithm

source§

impl StructuralPartialEq for SymmetricKeyAlgorithm

Auto Trait Implementations§

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

source§

impl<Z> Zeroize for Z
where Z: DefaultIsZeroes,

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.