#[repr(u8)]pub enum SymmetricKeyAlgorithm {
Show 13 variants
Plaintext,
IDEA,
TripleDES,
CAST5,
Blowfish,
AES128,
AES192,
AES256,
Twofish,
Camellia128,
Camellia192,
Camellia256,
Private10,
}
Expand description
Available symmetric key algorithms.
Variants§
Plaintext
Plaintext or unencrypted data
IDEA
IDEA
TripleDES
Triple-DES
CAST5
CAST5
Blowfish
Blowfish
AES128
AES with 128-bit key
AES192
AES with 192-bit key
AES256
AES with 256-bit key
Twofish
Twofish with 256-bit key
Camellia128
Camellia with 128-bit key
Camellia192
Camellia with 192-bit key
Camellia256
Camellia with 256-bit key
Private10
Implementations§
source§impl SymmetricKeyAlgorithm
impl SymmetricKeyAlgorithm
sourcepub fn block_size(self) -> usize
pub fn block_size(self) -> usize
The size of a single block in bytes. Based on https://github.com/gpg/libgcrypt/blob/master/cipher
sourcepub fn key_size(self) -> usize
pub fn key_size(self) -> usize
The size of a single block in bytes. Based on https://github.com/gpg/libgcrypt/blob/master/cipher
sourcepub fn decrypt<'a>(
self,
key: &[u8],
ciphertext: &'a mut [u8]
) -> Result<&'a [u8], Error>
pub fn decrypt<'a>( self, key: &[u8], ciphertext: &'a mut [u8] ) -> Result<&'a [u8], Error>
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.
sourcepub fn decrypt_protected<'a>(
self,
key: &[u8],
ciphertext: &'a mut [u8]
) -> Result<&'a [u8], Error>
pub fn decrypt_protected<'a>( self, key: &[u8], ciphertext: &'a mut [u8] ) -> Result<&'a [u8], Error>
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.
sourcepub fn decrypt_with_iv<'a>(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &'a mut [u8],
resync: bool
) -> Result<(&'a [u8], &'a [u8]), Error>
pub fn decrypt_with_iv<'a>( self, key: &[u8], iv_vec: &[u8], ciphertext: &'a mut [u8], resync: bool ) -> Result<(&'a [u8], &'a [u8]), Error>
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.
sourcepub fn decrypt_with_iv_regular(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8]
) -> Result<(), Error>
pub fn decrypt_with_iv_regular( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8] ) -> Result<(), Error>
Decrypt the data using CFB mode, without padding. Overwrites the input. This is regular CFB, not OpenPgP CFB.
sourcepub fn encrypt_with_rng<R>(
self,
rng: &mut R,
key: &[u8],
plaintext: &[u8]
) -> Result<Vec<u8, Global>, Error>where
R: CryptoRng + Rng,
pub fn encrypt_with_rng<R>( self, rng: &mut R, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8, Global>, Error>where R: CryptoRng + Rng,
Encrypt the data using CFB mode, without padding. Overwrites the input. Uses an IV of all zeroes, as specified in the openpgp cfb mode.
sourcepub fn encrypt(
self,
key: &[u8],
plaintext: &[u8]
) -> Result<Vec<u8, Global>, Error>
pub fn encrypt( self, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8, Global>, Error>
Same as encrypt_with_rng
, but uses rand::thread_rng
for RNG.
pub fn encrypt_protected_with_rng<R>( self, rng: &mut R, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8, Global>, Error>where R: CryptoRng + Rng,
pub fn encrypt_protected( self, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8, Global>, Error>
sourcepub fn encrypt_with_iv(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8],
resync: bool
) -> Result<(), Error>
pub fn encrypt_with_iv( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8], resync: bool ) -> Result<(), Error>
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.
Trait Implementations§
source§impl Clone for SymmetricKeyAlgorithm
impl Clone for SymmetricKeyAlgorithm
source§fn clone(&self) -> SymmetricKeyAlgorithm
fn clone(&self) -> SymmetricKeyAlgorithm
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SymmetricKeyAlgorithm
impl Debug for SymmetricKeyAlgorithm
source§impl Default for SymmetricKeyAlgorithm
impl Default for SymmetricKeyAlgorithm
source§fn default() -> SymmetricKeyAlgorithm
fn default() -> SymmetricKeyAlgorithm
source§impl FromPrimitive for SymmetricKeyAlgorithm
impl FromPrimitive for SymmetricKeyAlgorithm
source§fn from_i64(n: i64) -> Option<SymmetricKeyAlgorithm>
fn from_i64(n: i64) -> Option<SymmetricKeyAlgorithm>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u64(n: u64) -> Option<SymmetricKeyAlgorithm>
fn from_u64(n: u64) -> Option<SymmetricKeyAlgorithm>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§impl PartialEq<SymmetricKeyAlgorithm> for SymmetricKeyAlgorithm
impl PartialEq<SymmetricKeyAlgorithm> for SymmetricKeyAlgorithm
source§fn eq(&self, other: &SymmetricKeyAlgorithm) -> bool
fn eq(&self, other: &SymmetricKeyAlgorithm) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for SymmetricKeyAlgorithm
impl DefaultIsZeroes for SymmetricKeyAlgorithm
impl Eq for SymmetricKeyAlgorithm
impl StructuralEq for SymmetricKeyAlgorithm
impl StructuralPartialEq for SymmetricKeyAlgorithm
Auto Trait Implementations§
impl RefUnwindSafe for SymmetricKeyAlgorithm
impl Send for SymmetricKeyAlgorithm
impl Sync for SymmetricKeyAlgorithm
impl Unpin for SymmetricKeyAlgorithm
impl UnwindSafe for SymmetricKeyAlgorithm
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
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.