Enum sequoia_openpgp::crypto::S2K
source · #[non_exhaustive]pub enum S2K {
Iterated {
hash: HashAlgorithm,
salt: [u8; 8],
hash_bytes: u32,
},
Salted {
hash: HashAlgorithm,
salt: [u8; 8],
},
Simple {
hash: HashAlgorithm,
},
Implicit,
Private {
tag: u8,
parameters: Option<Box<[u8]>>,
},
Unknown {
tag: u8,
parameters: Option<Box<[u8]>>,
},
}
Expand description
String-to-Key (S2K) specifiers.
String-to-key (S2K) specifiers are used to convert password
strings into symmetric-key encryption/decryption keys. See
Section 3.7 of RFC 4880. This is used to encrypt messages with
a password (see SKESK
), and to protect secret keys (see
key::Encrypted
).
Note: This enum cannot be exhaustively matched to allow future extensions.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Iterated
Repeatently hashes the password with a public salt
value.
Fields
hash: HashAlgorithm
Hash used for key derivation.
hash_bytes: u32
Number of bytes to hash.
This parameter increases the workload for an attacker
doing a dictionary attack. Note that not all values are
representable. See S2K::new_iterated
.
Salted
S2K::Iterated
.Hashes the password with a public salt
value.
This mechanism does not use iteration to increase the time it takes to derive the key from the password. This makes dictionary attacks more feasible. Do not use this variant.
Fields
Simple
S2K::Iterated
.Simply hashes the password.
This mechanism uses neither iteration to increase the time it takes to derive the key from the password nor does it salt the password. This makes dictionary attacks more feasible.
This mechanism has been deprecated in RFC 4880. Do not use this variant.
Fields
Implicit
S2K::Iterated
.Simply hashes the password using MD5
This mechanism uses neither iteration to increase the time it takes to derive the key from the password nor does it salt the password, as well as using a very weak and fast hash algorithm. This makes dictionary attacks more feasible.
This mechanism has been deprecated in RFC 2440. Do not use this variant.
Private
Private S2K algorithm.
Fields
parameters: Option<Box<[u8]>>
The parameters for the private algorithm.
This is optional, because when we parse a packet
containing an unknown S2K algorithm, we do not know how
many octets to attribute to the S2K’s parameters. In this
case, parameters
is set to None
. Note that the
information is not lost, but stored in the packet. If the
packet is serialized again, it is written out.
Unknown
Unknown S2K algorithm.
Fields
parameters: Option<Box<[u8]>>
The parameters for the unknown algorithm.
This is optional, because when we parse a packet
containing an unknown S2K algorithm, we do not know how
many octets to attribute to the S2K’s parameters. In this
case, parameters
is set to None
. Note that the
information is not lost, but stored in the packet. If the
packet is serialized again, it is written out.
Implementations§
source§impl S2K
impl S2K
sourcepub fn new_iterated(hash: HashAlgorithm, approx_hash_bytes: u32) -> Result<Self>
pub fn new_iterated(hash: HashAlgorithm, approx_hash_bytes: u32) -> Result<Self>
Creates a new iterated S2K
object.
Usually, you should use S2K
s Default
implementation to
create S2K
objects with sane default parameters. The
parameters are chosen with contemporary machines in mind, and
should also be usable on lower-end devices like smart phones.
Using this method, you can tune the parameters for embedded devices. Note, however, that this also decreases the work factor for attackers doing dictionary attacks.
sourcepub fn derive_key(
&self,
password: &Password,
key_size: usize,
) -> Result<SessionKey>
pub fn derive_key( &self, password: &Password, key_size: usize, ) -> Result<SessionKey>
Derives a key of the given size from a password.
sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
Returns whether this S2K mechanism is supported.
Trait Implementations§
source§impl MarshalInto for S2K
impl MarshalInto for S2K
source§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
source§fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
source§impl<'a> Parse<'a, S2K> for S2K
impl<'a> Parse<'a, S2K> for S2K
source§fn from_buffered_reader<R>(reader: R) -> Result<Self>where
R: BufferedReader<Cookie> + 'a,
fn from_buffered_reader<R>(reader: R) -> Result<Self>where
R: BufferedReader<Cookie> + 'a,
source§fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>
fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>
impl Eq for S2K
impl StructuralPartialEq for S2K
Auto Trait Implementations§
impl Freeze for S2K
impl RefUnwindSafe for S2K
impl Send for S2K
impl Sync for S2K
impl Unpin for S2K
impl UnwindSafe for S2K
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)