Enum pgp::crypto::sym::SymmetricKeyAlgorithm
source · #[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
Available symmetric key algorithms.
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
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]>
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.
sourcepub fn decrypt_protected<'a>(
self,
key: &[u8],
ciphertext: &'a mut [u8]
) -> Result<&'a [u8]>
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.
sourcepub fn decrypt_with_iv<'a>(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &'a mut [u8],
resync: bool
) -> Result<(&'a [u8], &'a [u8])>
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.
sourcepub fn decrypt_with_iv_regular(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8]
) -> Result<()>
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.
sourcepub fn encrypt_with_rng<R: CryptoRng + Rng>(
self,
rng: &mut R,
key: &[u8],
plaintext: &[u8]
) -> Result<Vec<u8>>
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.
sourcepub fn encrypt(self, key: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>
pub fn encrypt(self, key: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>
Same as encrypt_with_rng
, but uses rand::thread_rng
for RNG.
pub fn encrypt_protected_with_rng<R: CryptoRng + Rng>( self, rng: &mut R, key: &[u8], plaintext: &[u8] ) -> Result<Vec<u8>>
pub fn encrypt_protected(self, key: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>
sourcepub fn encrypt_with_iv(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8],
resync: bool
) -> Result<()>
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.
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§impl From<SymmetricKeyAlgorithm> for u8
impl From<SymmetricKeyAlgorithm> for u8
source§fn from(enum_value: SymmetricKeyAlgorithm) -> Self
fn from(enum_value: SymmetricKeyAlgorithm) -> Self
source§impl From<u8> for SymmetricKeyAlgorithm
impl From<u8> for SymmetricKeyAlgorithm
source§impl PartialEq for SymmetricKeyAlgorithm
impl PartialEq 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 ==
.