#[non_exhaustive]pub enum S2K {
Argon2 {
salt: [u8; 16],
t: u8,
p: u8,
m: u8,
},
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 9580. This is used to encrypt messages with
a password (see SKESK), and to protect secret keys (see
key::Encrypted).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Argon2
Argon2 Memory-Hard Password Hashing Function.
Fields
Iterated
Repeatently hashes the password with a public salt value.
Fields
hash: HashAlgorithmHash used for key derivation.
hash_bytes: u32Number 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 S2Ks 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 smartphones.
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.