#[non_exhaustive]#[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. Ref: https://www.rfc-editor.org/rfc/rfc9580.html#name-symmetric-key-algorithms
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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 const fn key_size(self) -> usize
pub const 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(
self,
key: &[u8],
prefix: &mut [u8],
ciphertext: &mut [u8],
) -> Result<()>
pub fn decrypt( self, key: &[u8], prefix: &mut [u8], ciphertext: &mut [u8], ) -> Result<()>
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(
self,
key: &[u8],
prefix: &mut [u8],
ciphertext: &mut Vec<u8>,
) -> Result<()>
pub fn decrypt_protected( self, key: &[u8], prefix: &mut [u8], ciphertext: &mut Vec<u8>, ) -> Result<()>
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.
The result will be in ciphertext.
Sourcepub fn decrypt_with_iv(
self,
key: &[u8],
iv_vec: &[u8],
encrypted_prefix: &mut [u8],
encrypted_data: &mut [u8],
) -> Result<()>
pub fn decrypt_with_iv( self, key: &[u8], iv_vec: &[u8], encrypted_prefix: &mut [u8], encrypted_data: &mut [u8], ) -> Result<()>
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_resync(
self,
key: &[u8],
iv_vec: &[u8],
encrypted_prefix: &mut [u8],
encrypted_data: &mut [u8],
) -> Result<()>
pub fn decrypt_with_iv_resync( self, key: &[u8], iv_vec: &[u8], encrypted_prefix: &mut [u8], encrypted_data: &mut [u8], ) -> Result<()>
Applies the legacy resyncing
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<R: CryptoRng + Rng>(
self,
rng: R,
key: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt<R: CryptoRng + Rng>( self, rng: 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.
pub fn encrypt_protected<R: CryptoRng + Rng>( self, rng: R, key: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>>
pub fn encrypted_protected_len(&self, plaintext_len: usize) -> usize
pub fn encrypted_protected_overhead(&self) -> usize
pub fn stream_encryptor<R, I>( self, rng: R, key: &[u8], plaintext: I, ) -> Result<StreamEncryptor<I>>
Sourcepub fn stream_decryptor_protected<R>(
self,
key: &[u8],
ciphertext: R,
) -> Result<StreamDecryptor<R>>where
R: BufRead,
pub fn stream_decryptor_protected<R>(
self,
key: &[u8],
ciphertext: R,
) -> Result<StreamDecryptor<R>>where
R: BufRead,
Protected decryption stream
Sourcepub fn stream_decryptor_unprotected<R>(
self,
key: &[u8],
ciphertext: R,
) -> Result<StreamDecryptor<R>>where
R: BufRead,
pub fn stream_decryptor_unprotected<R>(
self,
key: &[u8],
ciphertext: R,
) -> Result<StreamDecryptor<R>>where
R: BufRead,
Unprotected decryption stream
Sourcepub fn encrypt_with_iv(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8],
) -> Result<()>
pub fn encrypt_with_iv( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8], ) -> 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.
Sourcepub fn encrypt_with_iv_resync(
self,
key: &[u8],
iv_vec: &[u8],
ciphertext: &mut [u8],
) -> Result<()>
pub fn encrypt_with_iv_resync( self, key: &[u8], iv_vec: &[u8], ciphertext: &mut [u8], ) -> Result<()>
Uses legacy resycing
Sourcepub fn encrypt_with_iv_regular(
self,
key: &[u8],
iv_vec: &[u8],
plaintext: &mut [u8],
) -> Result<()>
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.
Sourcepub fn new_session_key<R: Rng + CryptoRng>(self, rng: R) -> RawSessionKey
pub fn new_session_key<R: Rng + CryptoRng>(self, rng: R) -> RawSessionKey
Generate a new session key.
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
impl Copy for SymmetricKeyAlgorithm
impl DefaultIsZeroes for SymmetricKeyAlgorithm
impl Eq for SymmetricKeyAlgorithm
impl StructuralPartialEq for SymmetricKeyAlgorithm
Auto Trait Implementations§
impl Freeze for SymmetricKeyAlgorithm
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.