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,
},
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
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
.
Repeatently hashes the password with a public salt
value.
Salted
Fields
Use 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.
Simple
Fields
Use 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.
Private
Fields
tag: u8
Tag identifying the private algorithm.
Tags 100 to 110 are reserved for private use.
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.
Private S2K algorithm.
Unknown
Fields
tag: u8
Tag identifying the unknown algorithm.
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.
Unknown S2K algorithm.
Implementations
sourceimpl 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
sourceimpl MarshalInto for S2K
impl MarshalInto for S2K
sourcefn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
Computes the maximal length of the serialized representation. Read more
sourcefn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
Serializes into the given buffer. Read more
sourceimpl<'a> Parse<'a, S2K> for S2K
impl<'a> Parse<'a, S2K> for S2K
impl Eq for S2K
impl StructuralEq for S2K
impl StructuralPartialEq for S2K
Auto Trait Implementations
impl RefUnwindSafe for S2K
impl Send for S2K
impl Sync for S2K
impl Unpin for S2K
impl UnwindSafe for S2K
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more