RFC 8018
PKCS #5: Password-Based Cryptography Specification Version 2.1
RFC 8018: PKCS #5 Password-Based Cryptography Specification Version 2.1 โจ
Okay bestie, this is RFC 8018 ๐ It's from the IETF (Internet Engineering Task Force) and was published in January 2017 ๐ It's Informational, which means it's published for info and isn't a Standards Track spec ๐ฆ The ISSN is 2070-1721.
The editor is K. Moriarty from Dell EMC ๐ The other authors are B. Kaliski from Verisign and A. Rusch from RSA ๐ซถ This one obsoletes RFC 2898, so RFC 2898 is officially replaced by this doc ๐ญ
Abstract
Okay, so this doc gives recommendations for doing password-based cryptography ๐ It covers key derivation functions, encryption schemes, message authentication schemes, and the ASN.1 syntax that names all these techniques ๐ธ
It's also a republication of PKCS #5 v2.1 from RSA Laboratories' Public-Key Cryptography Standards (PKCS) series ๐ง By publishing it as an RFC, change control moves over to the IETF, which is lowkey a whole main character moment ๐
This doc also obsoletes RFC 2898 ๐
Status of This Memo
Not gonna lie, this isn't an Internet Standards Track spec. It's published for informational purposes ๐
This doc is a product of the IETF ๐ It represents the consensus of the IETF community, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication โจ Not every IESG-approved doc is a candidate for any level of Internet Standard, so check Section 2 of RFC 7841 if you're curious ๐
For the current status, any errata, and how to send feedback, go to http://www.rfc-editor.org/info/rfc8018 ๐ฆ
Copyright Notice
Copyright (c) 2017 IETF Trust and the persons identified as the document authors. All rights reserved. ๐
This doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as they were in effect on the publication date. Please read these carefully, bestie, because they explain your rights and restrictions for this doc ๐ Code Components pulled out of this doc must include the Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come without warranty, as the Simplified BSD License describes ๐
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4
2. Notation . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4. Salt and Iteration Count . . . . . . . . . . . . . . . . . . 7
4.1. Salt . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2. Iteration Count . . . . . . . . . . . . . . . . . . . . . 9
5. Key Derivation Functions . . . . . . . . . . . . . . . . . . 9
5.1. PBKDF1 . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.2. PBKDF2 . . . . . . . . . . . . . . . . . . . . . . . . . 11
6. Encryption Schemes . . . . . . . . . . . . . . . . . . . . . 13
6.1. PBES1 . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.1.1. PBES1 Encryption Operation . . . . . . . . . . . . . 13
6.1.2. PBES1 Decryption Operation . . . . . . . . . . . . . 15
6.2. PBES2 . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.2.1. PBES2 Encryption Operation . . . . . . . . . . . . . 16
6.2.2. PBES2 Decryption Operation . . . . . . . . . . . . . 16
7. Message Authentication Schemes . . . . . . . . . . . . . . . 17
7.1. PBMAC1 . . . . . . . . . . . . . . . . . . . . . . . . . 17
7.1.1. PBMAC1 Generation Operation . . . . . . . . . . . . . 17
7.1.2. PBMAC1 Verification Operation . . . . . . . . . . . . 18
8. Security Considerations . . . . . . . . . . . . . . . . . . . 18
9. Normative References . . . . . . . . . . . . . . . . . . . . 19
Appendix A. ASN.1 Syntax . . . . . . . . . . . . . . . . . . . . 23
A.1. PBKDF1 . . . . . . . . . . . . . . . . . . . . . . . . . 23
A.2. PBKDF2 . . . . . . . . . . . . . . . . . . . . . . . . . 23
A.3. PBES1 . . . . . . . . . . . . . . . . . . . . . . . . . . 25
A.4. PBES2 . . . . . . . . . . . . . . . . . . . . . . . . . . 26
A.5. PBMAC1 . . . . . . . . . . . . . . . . . . . . . . . . . 26
Appendix B. Supporting Techniques . . . . . . . . . . . . . . . 27
B.1. Pseudorandom Functions . . . . . . . . . . . . . . . . . 28
B.1.1. HMAC-SHA-1 . . . . . . . . . . . . . . . . . . . . . 28
B.1.2. HMAC-SHA-2 . . . . . . . . . . . . . . . . . . . . . 29
B.2. Encryption Schemes . . . . . . . . . . . . . . . . . . . 29
B.2.1. DES-CBC-Pad . . . . . . . . . . . . . . . . . . . . . 30
B.2.2. DES-EDE3-CBC-Pad . . . . . . . . . . . . . . . . . . 30
B.2.3. RC2-CBC-Pad . . . . . . . . . . . . . . . . . . . . . 30
B.2.4. RC5-CBC-Pad . . . . . . . . . . . . . . . . . . . . . 31
B.2.5. AES-CBC-Pad . . . . . . . . . . . . . . . . . . . . . 32
B.3. Message Authentication Schemes . . . . . . . . . . . . . 33
B.3.1. HMAC-SHA-1 . . . . . . . . . . . . . . . . . . . . . 33
B.3.2. HMAC-SHA-2 . . . . . . . . . . . . . . . . . . . . . 33
Appendix C. ASN.1 Module . . . . . . . . . . . . . . . . . . . . 34
Appendix D. Revision History of PKCS #5 . . . . . . . . . . . . 38
Appendix E. About PKCS . . . . . . . . . . . . . . . . . . . . . 39
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 40
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 40
1. Introduction ๐ธ
Okay so this doc gives recommendations for implementing password-based cryptography, and it covers these four things:
- key derivation functions
- encryption schemes
- message authentication schemes
- ASN.1 syntax identifying the techniques
The recommendations are meant for general use across computer and communications systems, so they're pretty flexible ๐ฆ They're especially made for protecting sensitive stuff like private keys, as in PKCS #8 [PKCS8] [RFC5958] ๐ Application standards and implementation profiles built on these specs might add extra constraints, and that's expected โจ
Other password-based techniques, like password-based key entity authentication and key establishment protocols [BELLOV] [JABLON] [WU], are outside the scope of this doc ๐ Guidelines for picking passwords are also out of scope, so don't come here for that ๐ This doc supersedes PKCS #5 version 2.0 [RFC2898] but still includes compatible techniques ๐
This doc is a republication of PKCS #5 v2.1 [PKCS5_21] from RSA Laboratories' Public-Key Cryptography Standards (PKCS) series ๐ง
2. Notation ๐
Here's the notation list, bestie. These are the symbols the rest of the doc uses, so keep it handy ๐
C ciphertext, an octet string
c iteration count, a positive integer
DK derived key, an octet string
dkLen length in octets of derived key, a positive integer
EM encoded message, an octet string
Hash underlying hash function
hLen length in octets of pseudorandom function output, a positive
integer
l length in blocks of derived key, a positive integer
IV initialization vector, an octet string
K encryption key, an octet string
KDF key derivation function
M message, an octet string
P password, an octet string
PRF underlying pseudorandom function
PS padding string, an octet string
psLen length in octets of padding string, a positive integer
S salt, an octet string
T message authentication code, an octet string
T_1, ..., T_l, U_1, ..., U_c
intermediate values, octet strings
01, 02, ..., 08
octets with value 1, 2, ..., 8
\xor bit-wise exclusive-or of two octet strings
|| || octet length operator
|| concatenation operator
<i..j> substring extraction operator: extracts octets i through j,
0 <= i <= j
3. Overview โจ
Okay so, in a lot of public-key crypto, user security ends up depending on one or more secret text values, aka passwords ๐. The catch is that a password can't just be used directly as a key for a conventional cryptosystem, so it needs some processing before any crypto happens. And since passwords often come from a pretty small space, that processing has to be extra careful to defend against search attacks ๐.
A general approach, described by Morris and Thompson [MORRIS] for protecting password tables, is to combine a password with a salt to produce a key ๐ง. The salt can be seen as an index into a big set of keys derived from the password, and it doesn't need to be kept secret. Yes, an opponent might build a table of possible passwords (a so-called "dictionary attack"), but building a table of possible keys is way harder, since there are tons of possible keys for each password ๐ . So an opponent is stuck searching through passwords separately for each salt. Iconic, honestly ๐.
Another approach is to make key derivation techniques relatively expensive, which raises the cost of exhaustive search ๐ธ. One way to do that is to include an iteration count, which says how many times to run some underlying function that the keys get derived from. A modest number (say, 1000) isn't really a burden for legit parties computing a key, but it's a significant burden for opponents ๐ซ .
Salt and iteration count were the basis for password-based encryption in PKCS #5 v2.0, and they're adopted here for the various cryptographic operations too ๐. So password-based key derivation as defined here is a function of a password, a salt, and an iteration count, where the salt and iteration count don't need to be kept secret.
From a password-based key derivation function, it's pretty straightforward to define password-based encryption and message authentication schemes ๐ฆ. Just like in PKCS #5 v2.0, the password-based encryption schemes here are built on an underlying conventional encryption scheme, where the key for that scheme is derived from the password. The password-based message authentication scheme is similarly based on an underlying conventional scheme. This two-layered setup keeps the password-based techniques modular, since they can be based on different underlying techniques ๐งฉ.
Password-based key derivation functions may also find uses beyond the encryption and message authentication schemes defined here โจ. For example, you could derive a set of keys with a single application of a key derivation function, instead of running the function separately for each key. The keys in the set would be obtained as substrings of the output of that function. This approach might be used as part of key establishment in a session-oriented protocol. Another use is password checking, where the output of the key derivation function is stored (along with the salt and iteration count) so a password can be verified later ๐.
Throughout this document, a password is treated as an octet string of arbitrary length, and how it's interpreted as a text string is unspecified ๐คทโโ๏ธ. For interoperability, though, it's recommended that applications follow some common text encoding rules. ASCII and UTF-8 [RFC3629] are two possibilities. (ASCII is a subset of UTF-8, so yes, it's all connected ๐.)
Selecting passwords is outside the scope of this document, but there are guidelines published [NISTSP63] that may well be taken into account ๐.
4. Salt and Iteration Count ๐งโฑ๏ธ
Salt and iteration count are central to the techniques defined in this document, so they deserve some extra discussion ๐ธ.
4.1. Salt
In password-based cryptography, a salt has traditionally been used to produce a large set of keys corresponding to a given password, with one of them selected at random according to the salt ๐ฒ. An individual key in the set is selected by applying a key derivation function KDF, like this:
DK = KDF (P, S)
where DK is the derived key, P is the password, and S is the salt. This gives two benefits ๐ซถ:
- It's difficult for an opponent to precompute all the keys, or even the most likely keys, corresponding to a dictionary of passwords. If the salt is 64 bits long, for instance, there will be as many as 2^64 keys for each password. An opponent is therefore limited to searching for passwords after a password-based operation has been performed and the salt is known ๐.
- It's unlikely that the same key will be selected twice. Again, if the salt is 64 bits long, the chance of "collision" between keys doesn't become significant until about 2^32 keys have been produced, according to the Birthday Paradox. The fact that collisions are unlikely addresses some concerns about interactions between multiple uses of the same key that may come up when using some encryption and authentication techniques ๐ .
In password-based encryption, the party encrypting a message can be sure these benefits are realized just by selecting a large and sufficiently random salt when deriving an encryption key from a password ๐. A party generating a message authentication code can get that same assurance in a similar way โจ.
Now, the party decrypting a message or verifying a message authentication code can't be sure that a salt supplied by another party was actually generated at random ๐ฌ. It's possible, for instance, that the salt was copied from another password-based operation, in an attempt to exploit interactions between multiple uses of the same key. Here's a spicy example ๐ถ๏ธ: suppose two legit parties exchange an encrypted message, where the encryption key is an 80-bit key derived from a shared password with some salt. An opponent could take the salt from that encryption and hand it to one of the parties as though it were for a 40-bit key. If that party reveals the result of decryption with the 40-bit key, the opponent may be able to solve for the 40-bit key. And if that 40-bit key is the first half of the 80-bit key, the opponent can then readily solve for the remaining 40 bits of the 80-bit key ๐ญ.
To defend against attacks like this, either the interaction between multiple uses of the same key has to be carefully analyzed, or the salt should contain data that explicitly distinguishes between different operations. For instance, the salt might have an additional, non-random octet that specifies whether the derived key is for encryption, for message authentication, or for some other operation ๐ก๏ธ.
Based on all this, the following is recommended for salt selection ๐:
- If there's no concern about interactions between multiple uses of the same key (or a prefix of that key) with the password-based encryption and authentication techniques supported for a given password, then the salt may be generated at random and doesn't need to be checked for a particular format by the party receiving the salt. It should be at least eight octets (64 bits) long ๐.
- Otherwise, the salt should contain data that explicitly distinguishes between different operations and different key lengths, in addition to a random part that is at least eight octets long. This data should be checked or regenerated by the party receiving the salt. For instance, the salt could have an additional non-random octet that specifies the purpose of the derived key. Alternatively, it could be the encoding of a structure that specifies detailed information about the derived key, such as the encryption or authentication technique and a sequence number among the different keys derived from the password. The particular format of the additional data is left to the application ๐ง.
Note: If a random number generator or pseudorandom generator isn't available, a deterministic alternative for generating the salt (or the random part of it) is to apply a password-based key derivation function to the password and the message M to be processed. For instance, the salt could be computed with a key derivation function as S = KDF (P, M). This approach is not recommended if the message M is known to belong to a small message space (e.g., "Yes" or "No"), however, since then there will only be a small number of possible salts ๐.
4.2. Iteration Count
An iteration count has traditionally been used to increase the cost of producing keys from a password, which also increases the difficulty of attack ๐๏ธโโ๏ธ. Mathematically, an iteration count of c will increase the security strength of a password by log2(c) bits against trial-based attacks like brute force or dictionary attacks ๐.
Choosing a reasonable value for the iteration count depends on the environment and circumstances, and it varies from application to application ๐. This document follows the recommendations made in FIPS Special Publication 800-132 [NISTSP132], which says:
The iteration count shall be selected as large as possible, as long as the time required to generate the key using the entered password is acceptable for the users. [...] A minimum iteration count of 1,000 is recommended. For especially critical keys, or for very powerful systems or systems where user-perceived performance is not critical, an iteration count of 10,000,000 may be appropriate.
5. Key Derivation Functions ๐
A key derivation function produces a derived key from a base key and other parameters ๐งช. In a password-based key derivation function, the base key is a password, and the other parameters are a salt value and an iteration count, as outlined in Section 3.
The primary application of the password-based key derivation functions defined here is in the encryption schemes in Section 6 and the message authentication scheme in Section 7. Other applications are certainly possible, which is why these functions are defined independently ๐.
Two functions are specified in this section: PBKDF1 and PBKDF2. PBKDF2 is recommended for new applications. PBKDF1 is included only for compatibility with existing applications and is not recommended for new applications ๐ซ .
A typical application of the key derivation functions defined here might include the following steps ๐:
- Select a salt S and an iteration count c, as outlined in Section 4.
- Select a length in octets for the derived key, dkLen.
- Apply the key derivation function to the password, the salt, the iteration count and the key length to produce a derived key.
- Output the derived key.
Any number of keys may be derived from a password by varying the salt, as described in Section 3 ๐.
5.1. PBKDF1 โจ
okay so PBKDF1 is the OG password key-derivation vibe ๐ It applies a hash function, and that hash SHALL be MD2 [RFC1319], MD5 [RFC1321], or SHA-1 [NIST180] ๐ The derived key length is capped by the hash output size: 16 octets for MD2 and MD5, and 20 octets for SHA-1. PBKDF1 is compatible with the key derivation in PKCS #5 v1.5 [PKCS5_15] ๐
PBKDF1 is RECOMMENDED only for compatibility with existing applications, bestie, since the keys it spits out may not be large enough for some applications ๐ฅบ
PBKDF1 (P, S, c, dkLen)
Options: Hash underlying hash function
Input: P password, an octet string
S salt, an octet string
c iteration count, a positive integer
dkLen intended length in octets of derived key,
a positive integer, at most 16 for MD2 or
MD5 and 20 for SHA-1
Output: DK derived key, a dkLen-octet string
Steps:
- If dkLen > 16 for MD2 and MD5, or dkLen > 20 for SHA-1, output "derived key too long" and stop. ๐ซ
- Apply the underlying hash function Hash for c iterations to the concatenation of the password P and the salt S, then extract the first dkLen octets to produce a derived key DK. It's giving chain reaction โ๏ธ
T_1 = Hash (P || S) ,
T_2 = Hash (T_1) ,
...
T_c = Hash (T_{c-1}) ,
DK = T_c<0..dkLen-1>
- Output the derived key DK. โจ
5.2. PBKDF2 ๐ธ
PBKDF2 applies a pseudorandom function (see Appendix B.1 for an example) to derive keys. The derived key length is essentially unbounded ๐คฏ (However, the maximum effective search space for the derived key may be limited by the structure of the underlying pseudorandom function. See Appendix B.1 for further discussion.) PBKDF2 is RECOMMENDED for new applications ๐
PBKDF2 (P, S, c, dkLen)
Options: PRF underlying pseudorandom function (hLen
denotes the length in octets of the
pseudorandom function output)
Input: P password, an octet string
S salt, an octet string
c iteration count, a positive integer
dkLen intended length in octets of the derived
key, a positive integer, at most
(2^32 - 1) * hLen
Output: DK derived key, a dkLen-octet string
Steps:
- If dkLen > (2^32 - 1) * hLen, output "derived key too long" and stop. ๐ โโ๏ธ
- Let l be the number of hLen-octet blocks in the derived key, rounding up, and let r be the number of octets in the last block:
l = CEIL (dkLen / hLen)
r = dkLen - (l - 1) * hLen
Here, CEIL (x) is the "ceiling" function, i.e., the smallest integer greater than, or equal to, x. ๐
- For each block of the derived key, apply the function F defined below to the password P, the salt S, the iteration count c, and the block index to compute the block:
T_1 = F (P, S, c, 1) ,
T_2 = F (P, S, c, 2) ,
...
T_l = F (P, S, c, l) ,
where the function F is defined as the exclusive-or sum of the first c iterates of the underlying pseudorandom function PRF applied to the password P and the concatenation of the salt S and the block index i:
F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
where
U_1 = PRF (P, S || INT (i)) ,
U_2 = PRF (P, U_1) ,
...
U_c = PRF (P, U_{c-1}) .
Here, INT (i) is a four-octet encoding of the integer i, most significant octet first. ๐ง
- Concatenate the blocks and extract the first dkLen octets to produce a derived key DK:
DK = T_1 || T_2 || ... || T_l<0..r-1>
- Output the derived key DK. ๐
Note: The construction of the function F follows a "belt-and-suspenders" approach. ๐ฉณ The iterates U_i are computed recursively to remove a degree of parallelism from an opponent; they are exclusive-ored together to reduce concerns about the recursion degenerating into a small set of values. It's a whole double-layer plan and I'm obsessed ๐ญ
6. Encryption Schemes ๐ฆ
An encryption scheme, in the symmetric setting, consists of an encryption operation and a decryption operation. The encryption operation produces a ciphertext from a message under a key, and the decryption operation recovers the message from the ciphertext under the same key. In a password-based encryption scheme, the key is a password ๐
A typical application of a password-based encryption scheme is a private-key protection method, where the message contains private-key information, as in PKCS #8. The encryption schemes defined here would be suitable encryption algorithms in that context ๐
Two schemes are specified in this section: PBES1 and PBES2. PBES2 is RECOMMENDED for new applications. PBES1 is included only for compatibility with existing applications and is NOT RECOMMENDED for new applications ๐
6.1. PBES1 ๐
PBES1 combines the PBKDF1 function (Section 5.1) with an underlying block cipher, which SHALL be either DES [NIST46] or RC2 [RFC2268] in cipher block chaining (CBC) mode [NIST81]. PBES1 is compatible with the encryption scheme in PKCS #5 v1.5 [PKCS5_15] ๐
PBES1 is RECOMMENDED only for compatibility with existing applications, since it supports only two underlying encryption schemes. Each of those has a key size (56 or 64 bits) that may not be large enough for some applications ๐ฅ
6.1.1. PBES1 Encryption Operation ๐
The encryption operation for PBES1 consists of the following steps, which encrypt a message M under a password P to produce a ciphertext C:
- Select an eight-octet salt S and an iteration count c, as outlined in Section 4. ๐ง
- Apply the PBKDF1 key derivation function (Section 5.1) to the password P, the salt S, and the iteration count c to produce a derived key DK of length 16 octets:
DK = PBKDF1 (P, S, c, 16)
- Separate the derived key DK into an encryption key K consisting of the first eight octets of DK and an initialization vector IV consisting of the next eight octets:
K = DK<0..7>
IV = DK<8..15>
- Concatenate M and a padding string PS to form an encoded message EM:
EM = M || PS
where the padding string PS consists of 8-(||M|| mod 8) octets, each with value 8-(||M|| mod 8). The padding string PS will satisfy one of the following statements:
PS = 01, if ||M|| mod 8 = 7 ;
PS = 02 02, if ||M|| mod 8 = 6 ;
...
PS = 08 08 08 08 08 08 08 08, if ||M|| mod 8 = 0.
The length in octets of the encoded message will be a multiple of eight, and it will be possible to recover the message M unambiguously from the encoded message. (This padding rule is taken from RFC 1423 [RFC1423].) ๐งฉ
- Encrypt the encoded message EM with the underlying block cipher (DES or RC2) in CBC mode under the encryption key K with initialization vector IV to produce the ciphertext C. For DES, the key K SHALL be considered as a 64-bit encoding of a 56-bit DES key with parity bits ignored (see [NIST46]). For RC2, the "effective key bits" SHALL be 64 bits. ๐โจ
- Output the ciphertext C. ๐
The salt S and the iteration count c MAY be conveyed to the party performing decryption in an AlgorithmIdentifier value (see Appendix A.3). ๐
6.1.2. PBES1 Decryption Operation ๐
The decryption operation for PBES1 consists of the following steps, which decrypt a ciphertext C under a password P to recover a message M:
- Obtain the eight-octet salt S and the iteration count c. ๐ฅ
- Apply the PBKDF1 key derivation function (Section 5.1) to the password P, the salt S, and the iteration count c to produce a derived key DK of length 16 octets:
DK = PBKDF1 (P, S, c, 16)
- Separate the derived key DK into an encryption key K consisting of the first eight octets of DK and an initialization vector IV consisting of the next eight octets:
K = DK<0..7>
IV = DK<8..15>
- Decrypt the ciphertext C with the underlying block cipher (DES or RC2) in CBC mode under the encryption key K with initialization vector IV to recover an encoded message EM. If the length in octets of the ciphertext C is not a multiple of eight, output "decryption error" and stop. ๐จ
- Separate the encoded message EM into a message M and a padding string PS:
EM = M || PS
where the padding string PS consists of some number psLen octets, each with value psLen, where psLen is between 1 and 8. If it is not possible to separate the encoded message EM in this manner, output "decryption error" and stop. ๐ โโ๏ธ
- Output the recovered message M. ๐
6.2. PBES2 ๐
PBES2 combines a password-based key derivation function, which SHALL be PBKDF2 (Section 5.2) for this version of PKCS #5, with an underlying encryption scheme (see Appendix B.2 for examples). The key length and any other parameters for the underlying encryption scheme depend on the scheme. PBES2 is RECOMMENDED for new applications ๐
6.2.1. PBES2 Encryption Operation ๐ง
The encryption operation for PBES2 consists of the following steps, which encrypt a message M under a password P to produce a ciphertext C, applying a selected key derivation function KDF and a selected underlying encryption scheme:
- Select a salt S and an iteration count c, as outlined in Section 4. ๐ง
- Select the length in octets, dkLen, for the derived key for the underlying encryption scheme. ๐
- Apply the selected key derivation function to the password P, the salt S, and the iteration count c to produce a derived key DK of length dkLen octets:
DK = KDF (P, S, c, dkLen)
- Encrypt the message M with the underlying encryption scheme under the derived key DK to produce a ciphertext C. (This step MAY involve selection of parameters such as an initialization vector and padding, depending on the underlying scheme.) ๐ช
- Output the ciphertext C. ๐
The salt S, the iteration count c, the key length dkLen, and identifiers for the key derivation function and the underlying encryption scheme MAY be conveyed to the party performing decryption in an AlgorithmIdentifier value (see Appendix A.4). ๐ซถ
6.2.2. PBES2 Decryption Operation ๐
okay so this is the mirror image of encryption, bestie ๐ชโจ we start from the ciphertext C and the password P and work backwards to get the message M back ๐ฆ
The decryption operation for PBES2 has these steps, and they decrypt a ciphertext C under a password P to recover a message M:
- Obtain the salt S for the operation. ๐ง
- Obtain the iteration count c for the key derivation function. ๐
- Obtain the key length in octets, dkLen, for the derived key for the underlying encryption scheme. ๐
- Apply the selected key derivation function to the password P, the salt S, and the iteration count c to produce a derived key DK of length dkLen octets:
DK = KDF (P, S, c, dkLen)
- Decrypt the ciphertext C with the underlying encryption scheme under the derived key DK to recover a message M. If the decryption function outputs "decryption error", then output "decryption error" and stop. ๐
- Output the recovered message M. ๐
7. Message Authentication Schemes ๐
okay the vibe shifts a little here ๐ instead of encrypting and decrypting, we're making a message authentication code (MAC) ๐งพ a message authentication scheme has a MAC generation operation and a MAC verification operation. the generation operation takes a message under a key and produces a MAC, and the verification operation checks that MAC against the same key ๐ and in a password-based scheme, the key is a password ๐
One scheme is specified in this section: PBMAC1 ๐ธ
7.1. PBMAC1 ๐
PBMAC1 combines a password-based key derivation function, which shall be PBKDF2 (Section 5.2) for this version of PKCS #5, with an underlying message authentication scheme (see Appendix B.3 for an example) โจ the key length and any other parameters for the underlying message authentication scheme depend on that scheme ๐งฉ
7.1.1. PBMAC1 Generation Operation ๐ญ
The MAC generation operation for PBMAC1 has these steps. They process a message M under a password P to generate a message authentication code T, using a selected key derivation function KDF and a selected underlying message authentication scheme ๐ฆ
- Select a salt S and an iteration count c, as outlined in Section 4. ๐ง๐
- Select a key length in octets, dkLen, for the derived key for the underlying message authentication function. ๐
- Apply the selected key derivation function to the password P, the salt S, and the iteration count c to produce a derived key DK of length dkLen octets:
DK = KDF (P, S, c, dkLen)
- Process the message M with the underlying message authentication scheme under the derived key DK to generate a message authentication code T. ๐ ๏ธ
- Output the message authentication code T. ๐
The salt S, the iteration count c, the key length dkLen, and identifiers for the key derivation function and underlying message authentication scheme may be conveyed to the party performing verification in an AlgorithmIdentifier value (see Appendix A.5). ๐จ so the verifier gets all the settings it needs, iykyk ๐ซถ
7.1.2. PBMAC1 Verification Operation ๐ต๏ธโโ๏ธ
The MAC verification operation for PBMAC1 has these steps. They process a message M under a password P to verify a message authentication code T ๐
- Obtain the salt S and the iteration count c. ๐ง๐
- Obtain the key length in octets, dkLen, for the derived key for the underlying message authentication scheme. ๐
- Apply the selected key derivation function to the password P, the salt S, and the iteration count c to produce a derived key DK of length dkLen octets:
DK = KDF (P, S, c, dkLen)
- Process the message M with the underlying message authentication scheme under the derived key DK to verify the message authentication code T. ๐
- If the message authentication code verifies, output "correct"; else output "incorrect". โ โ
8. Security Considerations ๐จ
okay bestie, this part is SERIOUS ๐ญ password-based crypto can only do so much for security, especially with methods like the ones in this document, where offline password search is possible ๐ salt and iteration count make the attack harder (see Section 4 for recommendations), but it is absolutely essential that passwords are chosen well, and relevant guidelines (e.g., [NISTSP63]) should be taken into account ๐ passwords also need to be protected well if they get stored ๐
In general, different keys should be derived from a password for different uses, so unintended interactions are less likely ๐งฟ for password-based encryption with a single algorithm, a random salt is enough to make sure different keys come out ๐ฒ but in certain other situations, as outlined in Section 4, a structured salt is necessary ๐งฑ so the recommendations in Section 4 should be taken into account when you pick the salt value ๐
For information on security considerations for MD2 [RFC1319], see [RFC6149]; for MD5 [RFC1321], see [RFC6151]; and for SHA-1 [NIST180], see [RFC6194]. ๐
9. Normative References ๐
bestie, these are the sources the spec leans on, and every single one is in here ๐ Full details, no cuts.
- [ANSIX952] ANSI, "Triple Data Encryption Algorithm Modes of Operation", Accredited Standards Committee X9, X9.52-1998, July 1998.
- [BELLOV] Bellovin, S. and M. Merritt, "Encrypted Key Exchange: Password-based Protocols Secure against Dictionary Attacks", Proceedings of the IEEE Symposium on Research in Security and Privacy, pages 72-84, IEEE Computer Society, DOI 10.1109/RISP.1992.213269, 1992.
- [COCHRAN] Cochran, M., "Notes on the Wang et al. 2^63 SHA-1 Differential Path", Cryptology ePrint Archive: Report 2007/474, August 2008,
<http://eprint.iacr.org/2007/474>. - [ISO8824-1] International Organization for Standardization, "Information technology - Abstract Syntax Notation One (ASN.1) - Specification of basic notation", ISO/IEC 8824-1:2008, 2008.
- [ISO8824-2] International Organization for Standardization, "Information technology - Abstract Syntax Notation One (ASN.1) - Information object specification", ISO/IEC 8824-2:2008, 2008.
- [ISO8824-3] International Organization for Standardization, "Information technology - Abstract Syntax Notation One (ASN.1) - Constraint specification", ISO/IEC 8824-3:2008, 2008.
- [ISO8824-4] International Organization for Standardization, "Information technology - Abstract Syntax Notation One (ASN.1) - Parameterization of ASN.1 specifications", ISO/IEC 8824-4:2008, 2008.
- [JABLON] Jablon, D., "Strong Password-Only Authenticated Key Exchange", ACM SIGCOMM Computer Communication Review, Volume 26, Issue 5, DOI 10.1145/242896.242897, October 1996.
- [MORRIS] Morris, R. and K. Thompson, "Password security: A case history", Communications of the ACM, Vol. 22, Issue 11, pages 594-597, DOI 10.1145/359168.359172, November 1979.
- [NIST46] National Institute of Standards and Technology (NIST), "Data Encryption Standard", FIPS PUB 46-3, October 1999.
- [NIST81] National Institute of Standards and Technology (NIST), "DES Modes of Operation", FIPS PUB 81, December 2, 1980.
- [NIST180] National Institute of Standards and Technology, "Secure Hash Standard (SHS)", FIPS PUB 180-4, DOI 10.6028/NIST.FIPS.180-4, August 2015.
- [NIST197] National Institute of Standards and Technology (NIST), "Advance Encryption Standard (AES)", FIPS PUB 197, November 2001.
- [NIST198] National Institute of Standards and Technology (NIST), "The Keyed - Hash Message Authentication Code (HMAC)", FIPS PUB 198-1, July 2008.
- [NISTSP63] National Institute of Standards and Technology (NIST), "Electronic Authentication Guideline", NIST Special Publication 800-63-2, DOI 10.6028/NIST.SP.800-63-2, August 2013.
- [NISTSP132] National Institute of Standards and Technology (NIST), "Recommendation for Password-Based Key Derivation, Part 1: Storage Applications", NIST Special Publication 800-132, DOI 10.6028/NIST.SP.800-132, December 2010.
- [PKCS5_15] RSA Laboratories, "PKCS #5: Password-Based Encryption Standard Version 1.5", November 1993.
- [PKCS5_21] RSA Laboratories, "PKCS #5: Password-Based Encryption Standard Version 2.1", October 2012.
- [PKCS8] Kaliski, B., "Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification Version 1.2", RFC 5208, DOI 10.17487/RFC5208, May 2008,
<http://www.rfc-editor.org/info/rfc5208>. - [RC5] Rivest, R.L., "The RC5 encryption algorithm", In Proceedings of the Second International Workshop on Fast Software Encryption, pages 86-96, Springer-Verlag, DOI 10.1007/3-540-60590-8_7, 1994.
- [RFC1319] Kaliski, B., "The MD2 Message-Digest Algorithm", RFC 1319, DOI 10.17487/RFC1319, April 1992,
<http://www.rfc-editor.org/info/rfc1319>. - [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, DOI 10.17487/RFC1321, April 1992,
<http://www.rfc-editor.org/info/rfc1321>. - [RFC1423] Balenson, D., "Privacy Enhancement for Internet Electronic Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, DOI 10.17487/RFC1423, February 1993,
<http://www.rfc-editor.org/info/rfc1423>. - [RFC2040] Baldwin, R. and R. Rivest, "The RC5, RC5-CBC, RC5-CBC-Pad, and RC5-CTS Algorithms", RFC 2040, DOI 10.17487/RFC2040, October 1996,
<http://www.rfc-editor.org/info/rfc2040>. - [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, DOI 10.17487/RFC2104, February 1997,
<http://www.rfc-editor.org/info/rfc2104>. - [RFC2268] Rivest, R., "A Description of the RC2(r) Encryption Algorithm", RFC 2268, DOI 10.17487/RFC2268, March 1998,
<http://www.rfc-editor.org/info/rfc2268>. - [RFC2898] Kaliski, B., "PKCS #5: Password-Based Cryptography Specification Version 2.0", RFC 2898, DOI 10.17487/RFC2898, September 2000,
<http://www.rfc-editor.org/info/rfc2898>. - [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2003,
<http://www.rfc-editor.org/info/rfc3629>. - [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, RFC 5652, DOI 10.17487/RFC5652, September 2009,
<http://www.rfc-editor.org/info/rfc5652>. - [RFC5958] Turner, S., "Asymmetric Key Packages", RFC 5958, DOI 10.17487/RFC5958, August 2010,
<http://www.rfc-editor.org/info/rfc5958>. - [RFC6149] Turner, S. and L. Chen, "MD2 to Historic Status", RFC 6149, DOI 10.17487/RFC6149, March 2011,
<http://www.rfc-editor.org/info/rfc6149>. - [RFC6151] Turner, S. and L. Chen, "Updated Security Considerations for the MD5 Message-Digest and the HMAC-MD5 Algorithms", RFC 6151, DOI 10.17487/RFC6151, March 2011,
<http://www.rfc-editor.org/info/rfc6151>. - [RFC6194] Polk, T., Chen, L., Turner, S., and P. Hoffman, "Security Considerations for the SHA-0 and SHA-1 Message-Digest Algorithms", RFC 6194, DOI 10.17487/RFC6194, March 2011,
<http://www.rfc-editor.org/info/rfc6194>. - [WANG] Wang, X., Yao, A.C., and F. Yao, "Cryptanalysis on SHA-1", presented by Adi Shamir at the rump session of CRYPTO 2005,
<http://csrc.nist.gov/groups/ST/hash/documents/Wang_SHA1-New-Result.pdf>. - [WU] Wu, T., "The Secure Remote Password protocol", In Proceedings of the 1998 Internet Society Network and Distributed System Security Symposium, pages 97-111, Internet Society, 1998,
<https://www.isoc.org/isoc/conferences/ndss/98/wu.pdf>.
Appendix A. ASN.1 Syntax ๐ง
this part is the ASN.1 toolkit ๐ฅ It defines the syntax for the key derivation functions, the encryption schemes, the message authentication scheme, and some supporting bits. The plan is for it to plug into PKCS #8 and other key management, encrypted data, and integrity-protected data stuff. ASN.1 has its own ISO/IEC standards too ([ISO8824-1] [ISO8824-2] [ISO8824-3] [ISO8824-4]) ๐ค
The object identifier pkcs-5 is the root of the OID tree where all the PKCS #5 OIDs in this section come from:
rsadsi OBJECT IDENTIFIER ::= {iso(1) member-body(2) us(840) 113549}
pkcs OBJECT IDENTIFIER ::= {rsadsi 1}
pkcs-5 OBJECT IDENTIFIER ::= {pkcs 5}
A.1. PBKDF1
no OID is given for PBKDF1 ๐ The PBES1 OIDs already cover existing apps, and PBKDF2 is RECOMMENDED for new applications. Main character move ๐
A.2. PBKDF2
the OID id-PBKDF2 points at the PBKDF2 key derivation function (Section 5.2) ๐ธ
id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12}
the parameters field attached to this OID in an AlgorithmIdentifier SHALL have type PBKDF2-params ๐
PBKDF2-params ::= SEQUENCE {
salt CHOICE {
specified OCTET STRING,
otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
},
iterationCount INTEGER (1..MAX),
keyLength INTEGER (1..MAX) OPTIONAL,
prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
algid-hmacWithSHA1 }
okay so here's what each field means ๐ซถ
- salt is the salt value, or where the salt value comes from. It SHALL either be an octet string or an algorithm ID with an OID in the set PBKDF2-SaltSources, which is reserved for future versions of PKCS #5 โจ
The salt-source approach is there to show how the salt gets generated from the algorithm ID parameters, the application data, or both. For example, it may point at a structure that describes the derived key in detail, like Section 4.1 suggests. Some of that info might live somewhere else, like the encryption algorithm ID, but those features got pushed to a future version of PKCS #5 ๐
In this version, an application can get the Section 4.1 perks by picking a particular meaning for the salt in the specified alternative ๐
PBKDF2-SaltSources ALGORITHM-IDENTIFIER ::= { ... }
- iterationCount is the iteration count. The maximum allowed depends on the implementation, and implementation profiles may tighten those bounds more ๐ฅ
- keyLength is optional, and it's the length in octets of the derived key. The max depends on the implementation, and profiles may narrow it further. This field is just for convenience, and the key length isn't cryptographically protected ๐ If there's worry about operations with different key lengths sharing one salt (see Section 4.1), the salt SHOULD tell those key lengths apart ๐ง
- prf names the underlying pseudorandom function. It SHALL be an algorithm ID with an OID in the set PBKDF2-PRFs, and for this version of PKCS #5 that set SHALL consist of id-hmacWithSHA1 (see Appendix B.1.1) plus any other OIDs the application defines ๐ฆ
PBKDF2-PRFs ALGORITHM-IDENTIFIER ::= {
{NULL IDENTIFIED BY id-hmacWithSHA1},
{NULL IDENTIFIED BY id-hmacWithSHA224},
{NULL IDENTIFIED BY id-hmacWithSHA256},
{NULL IDENTIFIED BY id-hmacWithSHA384},
{NULL IDENTIFIED BY id-hmacWithSHA512},
{NULL IDENTIFIED BY id-hmacWithSHA512-224},
{NULL IDENTIFIED BY id-hmacWithSHA512-256},
...
}
the default pseudorandom function is HMAC-SHA-1 ๐
algid-hmacWithSHA1 AlgorithmIdentifier {{PBKDF2-PRFs}} ::=
{algorithm id-hmacWithSHA1, parameters NULL : NULL}
A.3. PBES1 ๐
okay so the PBES1 encryption scheme (Section 6.1) gets a different OID depending on which hash function is in the key derivation function and which block cipher is in use ๐. here's the lineup:
Hash Function Block Cipher OID
MD2 DES pkcs-5.1
MD2 RC2 pkcs-5.4
MD5 DES pkcs-5.3
MD5 RC2 pkcs-5.6
SHA-1 DES pkcs-5.10
SHA-1 RC2 pkcs-5.11
each of these gets its own named OID, which is pretty iconic of them ๐
pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1}
pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4}
pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3}
pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6}
pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10}
pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11}
for each OID, the parameters field in an AlgorithmIdentifier shall have type PBEParameter ๐ง
PBEParameter ::= SEQUENCE {
salt OCTET STRING (SIZE(8)),
iterationCount INTEGER }
the fields of PBEParameter are pretty straightforward, bestie ๐ธ
- salt is the salt value, an eight-octet string ๐ง
- iterationCount is the iteration count ๐
A.4. PBES2 ๐
the object identifier id-PBES2 identifies the PBES2 encryption scheme (Section 6.2) โจ
id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13}
the parameters field for this OID in an AlgorithmIdentifier shall have type PBES2-params ๐
PBES2-params ::= SEQUENCE {
keyDerivationFunc AlgorithmIdentifier {{PBES2-KDFs}},
encryptionScheme AlgorithmIdentifier {{PBES2-Encs}} }
the fields of PBES2-params, periodt ๐
- keyDerivationFunc tells you which underlying key derivation function is being used. it shall be an algorithm ID with an OID in the set PBES2-KDFs, which for this version of PKCS #5 shall consist of id-PBKDF2 (Appendix A.2) ๐
PBES2-KDFs ALGORITHM-IDENTIFIER ::=
{ {PBKDF2-params IDENTIFIED BY id-PBKDF2}, ... }
- encryptionScheme tells you which underlying encryption scheme is in play. it shall be an algorithm ID with an OID in the set PBES2-Encs, and the definition of that set is left to the application ๐ซถ examples of underlying encryption schemes are given in Appendix B.2 ๐
PBES2-Encs ALGORITHM-IDENTIFIER ::= { ... }
A.5. PBMAC1 ๐ฆ
the object identifier id-PBMAC1 identifies the PBMAC1 message authentication scheme (Section 7.1) ๐
id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14}
the parameters field for this OID in an AlgorithmIdentifier shall have type PBMAC1-params ๐
PBMAC1-params ::= SEQUENCE {
keyDerivationFunc AlgorithmIdentifier {{PBMAC1-KDFs}},
messageAuthScheme AlgorithmIdentifier {{PBMAC1-MACs}} }
the keyDerivationFunc field means the same thing as the matching field in PBES2-params (Appendix A.4), except that the set of OIDs is PBMAC1-KDFs, which is giving consistency ๐ฅน
PBMAC1-KDFs ALGORITHM-IDENTIFIER ::=
{ {PBKDF2-params IDENTIFIED BY id-PBKDF2}, ... }
the messageAuthScheme field identifies the underlying message authentication scheme. it shall be an algorithm ID with an OID in the set PBMAC1-MACs, and the definition of that set is left to the application ๐ examples of underlying encryption schemes are given in Appendix B.3 โจ
PBMAC1-MACs ALGORITHM-IDENTIFIER ::= { ... }
Appendix B. Supporting Techniques ๐
this section gives several examples of underlying functions and schemes that support the password-based schemes in Sections 5, 6, and 7 ๐ธ
while these supporting techniques are appropriate for applications to implement, none of them is required to be implemented. it is expected, however, that profiles for PKCS #5 will be developed that specify particular supporting techniques ๐ฅ
this section also gives object identifiers for the supporting techniques. the object identifiers digestAlgorithm and encryptionAlgorithm identify the arcs that certain algorithm OIDs referenced in this section are derived from ๐ง
digestAlgorithm OBJECT IDENTIFIER ::= {rsadsi 2} encryptionAlgorithm
OBJECT IDENTIFIER ::= {rsadsi 3}
B.1. Pseudorandom Functions ๐
examples of pseudorandom functions for PBKDF2 (Section 5.2) include HMAC with SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. applications may employ other schemes as well ๐
B.1.1. HMAC-SHA-1 ๐ฆ
HMAC-SHA-1 is the pseudorandom function that matches the HMAC message authentication code [RFC2104] based on the SHA-1 hash function [NIST180]. the pseudorandom function is the same function that computes the message authentication code, with a full-length output. (the first argument to the pseudorandom function PRF serves as HMAC's "key", and the second serves as HMAC's "text". in the case of PBKDF2, the "key" is the password and the "text" is the salt.) HMAC-SHA-1 has a variable key length and a 20-octet (160-bit) output value ๐
although the length of the key to HMAC-SHA-1 is essentially unbounded, the effective search space for pseudorandom function outputs may be limited by the structure of the function. in particular, when the key is longer than 512 bits, HMAC-SHA-1 will first hash it to 160 bits. so, even if a long derived key made of several pseudorandom function outputs is produced from a key, the effective search space for the derived key will be at most 160 bits ๐ญ although the specific limitation for other key sizes depends on the details of the HMAC construction, one should assume, to be conservative, that the effective search space is limited to 160 bits for other key sizes as well ๐
(the 160-bit limitation should not generally pose a practical limitation in the case of password-based cryptography, since the search space for a password is unlikely to be greater than 160 bits ๐)
the object identifier id-hmacWithSHA1 identifies the HMAC-SHA-1 pseudorandom function ๐
id-hmacWithSHA1 OBJECT IDENTIFIER ::= {digestAlgorithm 7}
the parameters field for this OID in an AlgorithmIdentifier shall have type NULL. this object identifier is used in the object set PBKDF2-PRFs (Appendix A.2) ๐
Note: although HMAC-SHA-1 was designed as a message authentication code, its proof of security is readily modified to meet the requirements for a pseudorandom function, under stronger assumptions. a hash function may also meet the requirements of a pseudorandom function under certain assumptions. for instance, applying a hash function directly to the concatenation of the "key" and the "text" may be appropriate, provided that "text" has appropriate structure to prevent certain attacks. HMAC-SHA-1 is preferable, however, because it treats "key" and "text" as separate arguments and does not require "text" to have any structure ๐ง
during 2004 and 2005, there were a number of attacks on SHA-1 that reduced its perceived effective strength against collision attacks to 62 bits instead of the expected 80 bits (e.g., Wang et al. [WANG], confirmed by M. Cochran [COCHRAN]). however, since these attacks centered on finding collisions between values, they are not a direct security consideration here, because the collision-resistant property is not required by the HMAC authentication scheme ๐ณ
B.1.2. HMAC-SHA-2 โจ
HMAC-SHA-2 refers to the set of pseudorandom functions that match the HMAC message authentication code (now a FIPS standard [NIST198]) based on the new SHA-2 functions (FIPS 180-4 [NIST180]). HMAC-SHA-2 has a variable key length and a variable output value, depending on the hash function chosen (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, or SHA-512/256). that means 28, 32, 48, or 64 octets ๐
using the new hash functions extends the search space for the produced keys. where SHA-1 limits the search space to 20 octets, SHA-2 sets new limits of 28, 32, 48, and 64 octets ๐
object identifiers for HMAC are defined as follows:
id-hmacWithSHA224 OBJECT IDENTIFIER ::= {digestAlgorithm 8}
id-hmacWithSHA256 OBJECT IDENTIFIER ::= {digestAlgorithm 9}
id-hmacWithSHA384 OBJECT IDENTIFIER ::= {digestAlgorithm 10}
id-hmacWithSHA512 OBJECT IDENTIFIER ::= {digestAlgorithm 11}
id-hmacWithSHA512-224 OBJECT IDENTIFIER ::= {digestAlgorithm 12}
id-hmacWithSHA512-256 OBJECT IDENTIFIER ::= {digestAlgorithm 13}
B.2. Encryption Schemes ๐
an example encryption scheme for PBES2 (Section 6.2) is AES-CBC-Pad ๐ง the schemes defined in PKCS #5 v2.0 [RFC2898], which are DES-CBC-Pad, DES-EDE3-CBC-Pad, RC2-CBC-Pad, and RC5-CBC-Pad, are still supported. but DES-CBC-Pad, DES-EDE3-CBC-Pad, and RC2-CBC-Pad are now considered legacy and should only be used for backwards compatibility reasons ๐ฐ๏ธ
the object identifiers in this section are meant to be used in the object set PBES2-Encs (Appendix A.4) ๐
B.2.1. DES-CBC-Pad ๐ธ
DES-CBC-Pad is single-key DES [NIST46] in CBC mode [NIST81] with the padding operation specified in RFC 1423 [RFC1423] (see Section 6.1.1 of this document). DES-CBC-Pad has an eight-octet encryption key and an eight-octet initialization vector. the key is considered as a 64-bit encoding of a 56-bit DES key with parity bits ignored ๐
the object identifier desCBC (defined in the NIST/OSI Implementors' Workshop agreements) identifies the DES-CBC-Pad encryption scheme ๐ฆ
desCBC OBJECT IDENTIFIER ::=
{iso(1) identified-organization(3) oiw(14) secsig(3)
algorithms(2) 7}
the parameters field for this OID in an AlgorithmIdentifier shall have type OCTET STRING (SIZE(8)), specifying the initialization vector for CBC mode ๐
B.2.2. DES-EDE3-CBC-Pad ๐ง
DES-EDE3-CBC-Pad is three-key triple-DES in CBC mode [ANSIX952] with the padding operation specified in RFC 1423 [RFC1423]. DES-EDE3-CBC-Pad has a 24-octet encryption key and an eight-octet initialization vector. the key is considered as the concatenation of three eight-octet keys, each of which is a 64-bit encoding of a 56-bit DES key with parity bits ignored ๐
the object identifier des-EDE3-CBC identifies the DES-EDE3-CBC-Pad encryption scheme ๐
des-EDE3-CBC OBJECT IDENTIFIER ::= {encryptionAlgorithm 7}
the parameters field for this OID in an AlgorithmIdentifier shall have type OCTET STRING (SIZE(8)), specifying the initialization vector for CBC mode โจ
Note: an OID for DES-EDE3-CBC without padding is given in ANSI X9.52 [ANSIX952]. the one given here is preferred since it specifies padding ๐ซถ
B.2.3. RC2-CBC-Pad ๐
okay so RC2-CBC-Pad is the RC2 encryption algorithm [RFC2268] running in CBC mode, with the padding from RFC 1423 [RFC1423] ๐ its key can be anywhere from one to 128 octets, and it has a separate "effective key bits" knob from one to 1024 bits. That knob limits the effective search space no matter how long the key is ๐ฅ It also has an eight-octet initialization vector ๐ง
The object identifier rc2CBC is how you name this encryption scheme โจ
rc2CBC OBJECT IDENTIFIER ::= {encryptionAlgorithm 2}
The parameters field attached to this OID in an AlgorithmIdentifier shall have type RC2-CBC-Parameter ๐
RC2-CBC-Parameter ::= SEQUENCE {
rc2ParameterVersion INTEGER OPTIONAL,
iv OCTET STRING (SIZE(8)) }
Here's what the fields of type RC2-CBCParameter mean ๐ธ
- rc2ParameterVersion is a proprietary RSA Security Inc. encoding of the "effective key bits" for RC2. These encodings are defined:
Effective Key Bits Encoding
40 160
64 120
128 58
b >= 256 b
- iv is the eight-octet initialization vector. ๐ฆ
If the rc2ParameterVersion field is left out, the "effective key bits" defaults to 32. (This exists for backward compatibility with certain very old implementations ๐)
B.2.4. RC5-CBC-Pad ๐
RC5-CBC-Pad is the RC5 encryption algorithm [RC5] in CBC mode, using the padding operation from RFC 5652 [RFC5652]. That padding is a generalization of the one in RFC 1423 [RFC1423] ๐ซถ The scheme is fully specified in [RFC2040]. RC5-CBC-Pad has a variable key length from 0 to 256 octets, and it supports both a 64-bit block size and a 128-bit block size. The 64-bit version has an eight-octet initialization vector, and the 128-bit version has a 16-octet initialization vector. RC5-CBC-Pad also has a variable number of "rounds" in the encryption operation, from 8 to 127 ๐ฅ
Note: For RC5 with a 64-bit block size, the padding string is as defined in RFC 1423 [RFC1423]. For RC5 with a 128-bit block size, the padding string consists of16-(||M|| mod 16)octets, each with value16-(||M|| mod 16).
The object identifier rc5-CBC-PAD [RFC2040] identifies the RC5-CBC-Pad encryption scheme ๐
rc5-CBC-PAD OBJECT IDENTIFIER ::= {encryptionAlgorithm 9}
The parameters field attached to this OID in an AlgorithmIdentifier shall have type RC5-CBC-Parameters ๐
RC5-CBC-Parameters ::= SEQUENCE {
version INTEGER {v1-0(16)} (v1-0),
rounds INTEGER (8..127),
blockSizeInBits INTEGER (64 | 128),
iv OCTET STRING OPTIONAL }
Here's what the fields of type RC5-CBC-Parameters mean ๐
- version is the version of the algorithm, which shall be v1-0.
- rounds is the number of rounds in the encryption operation, which shall be between 8 and 127.
- blockSizeInBits is the block size in bits, which shall be 64 or 128.
- iv is the initialization vector: an eight-octet string for 64-bit RC5 and a 16-octet string for 128-bit RC5. The default is a string of the appropriate length consisting of zero octets. ๐ซง
B.2.5. AES-CBC-Pad ๐
AES-CBC-Pad is the AES encryption algorithm [NIST197] in CBC mode, using the padding operation from RFC 5652 [RFC5652]. It has a variable key length of 16, 24, or 32 octets, a 16-octet block size, and a 16-octet initialization vector โจ
Note: For AES, the padding string consists of16-(||M|| mod 16)octets, each with value16-(||M|| mod 16).
For AES, object identifiers are defined depending on key size and operation mode. For example, the 16-octet (128-bit) key AES encryption scheme in CBC mode would be aes128-CBC-Pad, which identifies the AES-CBC-PAD encryption scheme using a 16-octet key ๐ฆ
aes128-CBC-PAD OBJECT IDENTIFIER ::= {aes 2}
The AES object identifier is defined in Appendix C. ๐ง
The parameters field attached to this OID in an AlgorithmIdentifier shall have type OCTET STRING (SIZE(16)), which specifies the initialization vector for CBC mode ๐
B.3. Message Authentication Schemes ๐
An example message authentication scheme for PBMAC1 (Section 7.1) is HMAC-SHA-1 ๐
B.3.1. HMAC-SHA-1 ๐ธ
HMAC-SHA-1 is the HMAC message authentication scheme [RFC2104] based on the SHA-1 hash function [NIST180]. It has a variable key length and a 20-octet (160-bit) message authentication code ๐ซถ
The object identifier id-hmacWithSHA1 (see Appendix B.1.1) identifies the HMAC-SHA-1 message authentication scheme. (The object identifier is the same for both the pseudorandom function and the message authentication scheme. The distinction is to be understood by context ๐) This object identifier is intended to be employed in the object set PBMAC1-Macs (Appendix A.5). ๐ฅ
B.3.2. HMAC-SHA-2 ๐
HMAC-SHA-2 refers to the set of HMAC message authentication schemes [NIST198] based on the SHA-2 functions [NIST180]. HMAC-SHA-2 has a variable key length, and its message authentication code length depends on the hash function chosen (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, or SHA-512/256). That's 28, 32, 48, or 64 octets ๐
The object identifiers id-hmacWithSHA224, id-hmacWithSHA256, id-hmacWithSHA384, id-hmacWithSHA512, id-hmacWithSHA512-224, and id-hmacWithSHA512-256 (see Appendix B.1.2) identify the HMAC-SHA-2 schemes. The object identifiers are the same for both the pseudorandom functions and the message authentication schemes. The distinction is to be understood by context ๐ These object identifiers are intended to be employed in the object set PBMAC1-Macs (Appendix A.5). ๐
Appendix C. ASN.1 Module โจ
okay so bestie, all the ASN.1 syntax from the earlier sections has been gathered into one single module so you can look at it all together ๐ it's the reference version, no cap ๐
-- PKCS #5 v2.1 ASN.1 Module
-- Revised October 27, 2012
-- This module has been checked for conformance with the
-- ASN.1 standard by the OSS ASN.1 Tools
PKCS5v2-1 {
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-5(5)
modules(16) pkcs5v2-1(2)
}
DEFINITIONS EXPLICIT TAGS ::=
BEGIN
-- ========================
-- Basic object identifiers
-- ========================
nistAlgorithms OBJECT IDENTIFIER ::= {joint-iso-itu-t(2) country(16)
us(840) organization(1)
gov(101) csor(3) 4}
oiw OBJECT IDENTIFIER ::= {iso(1) identified-organization(3) 14}
rsadsi OBJECT IDENTIFIER ::= {iso(1) member-body(2) us(840) 113549}
pkcs OBJECT IDENTIFIER ::= {rsadsi 1}
pkcs-5 OBJECT IDENTIFIER ::= {pkcs 5}
-- =======================
-- Basic types and classes
-- =======================
AlgorithmIdentifier { ALGORITHM-IDENTIFIER:InfoObjectSet } ::=
SEQUENCE {
algorithm ALGORITHM-IDENTIFIER.&id({InfoObjectSet}),
parameters ALGORITHM-IDENTIFIER.&Type({InfoObjectSet}
{@algorithm}) OPTIONAL
}
ALGORITHM-IDENTIFIER ::= TYPE-IDENTIFIER
-- ======
-- PBKDF2
-- ======
PBKDF2Algorithms ALGORITHM-IDENTIFIER ::= {
{PBKDF2-params IDENTIFIED BY id-PBKDF2},
...
}
id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12}
algid-hmacWithSHA1 AlgorithmIdentifier {{PBKDF2-PRFs}} ::=
{algorithm id-hmacWithSHA1, parameters NULL : NULL}
PBKDF2-params ::= SEQUENCE {
salt CHOICE {
specified OCTET STRING,
otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
},
iterationCount INTEGER (1..MAX),
keyLength INTEGER (1..MAX) OPTIONAL,
prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
algid-hmacWithSHA1
}
PBKDF2-SaltSources ALGORITHM-IDENTIFIER ::= { ... }
PBKDF2-PRFs ALGORITHM-IDENTIFIER ::= {
{NULL IDENTIFIED BY id-hmacWithSHA1},
{NULL IDENTIFIED BY id-hmacWithSHA224},
{NULL IDENTIFIED BY id-hmacWithSHA256},
{NULL IDENTIFIED BY id-hmacWithSHA384},
{NULL IDENTIFIED BY id-hmacWithSHA512},
{NULL IDENTIFIED BY id-hmacWithSHA512-224},
{NULL IDENTIFIED BY id-hmacWithSHA512-256},
...
}
-- =====
-- PBES1
-- =====
PBES1Algorithms ALGORITHM-IDENTIFIER ::= {
{PBEParameter IDENTIFIED BY pbeWithMD2AndDES-CBC} |
{PBEParameter IDENTIFIED BY pbeWithMD2AndRC2-CBC} |
{PBEParameter IDENTIFIED BY pbeWithMD5AndDES-CBC} |
{PBEParameter IDENTIFIED BY pbeWithMD5AndRC2-CBC} |
{PBEParameter IDENTIFIED BY pbeWithSHA1AndDES-CBC} |
{PBEParameter IDENTIFIED BY pbeWithSHA1AndRC2-CBC},
...
}
pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1}
pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4}
pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3}
pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6}
pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10}
pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11}
PBEParameter ::= SEQUENCE {
salt OCTET STRING (SIZE(8)),
iterationCount INTEGER
}
-- =====
-- PBES2
-- =====
PBES2Algorithms ALGORITHM-IDENTIFIER ::= {
{PBES2-params IDENTIFIED BY id-PBES2},
...
}
id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13}
PBES2-params ::= SEQUENCE {
keyDerivationFunc AlgorithmIdentifier {{PBES2-KDFs}},
encryptionScheme AlgorithmIdentifier {{PBES2-Encs}}
}
PBES2-KDFs ALGORITHM-IDENTIFIER ::= {
{PBKDF2-params IDENTIFIED BY id-PBKDF2},
...
}
PBES2-Encs ALGORITHM-IDENTIFIER ::= { ... }
-- ======
-- PBMAC1
-- ======
PBMAC1Algorithms ALGORITHM-IDENTIFIER ::= {
{PBMAC1-params IDENTIFIED BY id-PBMAC1},
...
}
id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14}
PBMAC1-params ::= SEQUENCE {
keyDerivationFunc AlgorithmIdentifier {{PBMAC1-KDFs}},
messageAuthScheme AlgorithmIdentifier {{PBMAC1-MACs}}
}
PBMAC1-KDFs ALGORITHM-IDENTIFIER ::= {
{PBKDF2-params IDENTIFIED BY id-PBKDF2},
...
}
PBMAC1-MACs ALGORITHM-IDENTIFIER ::= { ... }
-- =====================
-- Supporting techniques
-- =====================
digestAlgorithm OBJECT IDENTIFIER ::= {rsadsi 2}
encryptionAlgorithm OBJECT IDENTIFIER ::= {rsadsi 3}
SupportingAlgorithms ALGORITHM-IDENTIFIER ::= {
{NULL IDENTIFIED BY id-hmacWithSHA1} |
{OCTET STRING (SIZE(8)) IDENTIFIED BY desCBC} |
{OCTET STRING (SIZE(8)) IDENTIFIED BY des-EDE3-CBC} |
{RC2-CBC-Parameter IDENTIFIED BY rc2CBC} |
{RC5-CBC-Parameters IDENTIFIED BY rc5-CBC-PAD}, |
{OCTET STRING (SIZE(16)) IDENTIFIED BY aes128-CBC-PAD} |
{OCTET STRING (SIZE(16)) IDENTIFIED BY aes192-CBC-PAD} |
{OCTET STRING (SIZE(16)) IDENTIFIED BY aes256-CBC-PAD},
...
}
id-hmacWithSHA1 OBJECT IDENTIFIER ::= {digestAlgorithm 7}
id-hmacWithSHA224 OBJECT IDENTIFIER ::= {digestAlgorithm 8}
id-hmacWithSHA256 OBJECT IDENTIFIER ::= {digestAlgorithm 9}
id-hmacWithSHA384 OBJECT IDENTIFIER ::= {digestAlgorithm 10}
id-hmacWithSHA512 OBJECT IDENTIFIER ::= {digestAlgorithm 11}
id-hmacWithSHA512-224 OBJECT IDENTIFIER ::= {digestAlgorithm 12}
id-hmacWithSHA512-256 OBJECT IDENTIFIER ::= {digestAlgorithm 13}
desCBC OBJECT IDENTIFIER ::= {oiw secsig(3) algorithms(2) 7}
des-EDE3-CBC OBJECT IDENTIFIER ::= {encryptionAlgorithm 7}
rc2CBC OBJECT IDENTIFIER ::= {encryptionAlgorithm 2}
RC2-CBC-Parameter ::= SEQUENCE {
rc2ParameterVersion INTEGER OPTIONAL,
iv OCTET STRING (SIZE(8))
}
rc5-CBC-PAD OBJECT IDENTIFIER ::= {encryptionAlgorithm 9}
RC5-CBC-Parameters ::= SEQUENCE {
version INTEGER {v1-0(16)} (v1-0),
rounds INTEGER (8..127),
blockSizeInBits INTEGER (64 | 128),
iv OCTET STRING OPTIONAL
}
aes OBJECT IDENTIFIER ::= { nistAlgorithms 1 }
aes128-CBC-PAD OBJECT IDENTIFIER ::= { aes 2 }
aes192-CBC-PAD OBJECT IDENTIFIER ::= { aes 22 }
aes256-CBC-PAD OBJECT IDENTIFIER ::= { aes 42 }
END
Appendix D. Revision History of PKCS #5 ๐
Versions 1.0 - 1.3 ๐ธ
Versions 1.0 - 1.3 went out to the people at RSA Data Security Inc.'s Public-Key Cryptography Standards meetings back in February and March 1991. Iconic early days ๐ง
Version 1.4 ๐
Version 1.4 was part of the June 3, 1991 first public release of PKCS. It also got published as NIST/OSI Implementors' Workshop document SEC-SIG-91-20. So official โจ
Version 1.5 ๐ฆ
Version 1.5 got several editorial changes, like updated references and a brand new revision history section. Tidy era ๐
Version 2.0 ๐
Version 2.0 had major editorial changes to the document structure, and it introduced the PBES2 encryption scheme, the PBMAC1 message authentication scheme, and independent password-based key derivation functions. It still keeps supporting the encryption process from version 1.5, so nobody gets left behind ๐ซถ
Version 2.1 ๐
This document moved PKCS #5 into the IETF, and it includes some minor changes from the authors for this submission. Main character glow-up ๐
- Introduces AES/CBC as an encryption scheme for PBES2, and HMAC with the hash functions SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 as pseudorandom functions for PBKDF2 and message authentication schemes for PBMAC1. โจ
- Changes the references for PKCS #5 to RFC 2898, and for PKCS #8 to RFCs 5208 and 5898. ๐
- Incorporates corrections of two editorial errata reported on PKCS #5 [RFC2898]. ๐ง
- Added security considerations for MD2, MD5, and SHA-1. ๐
Security note, bestie: the security considerations for MD2, MD5, and SHA-1 were added in this version, so read them seriously ๐
Appendix E. About PKCS ๐
The Public-Key Cryptography Standards are specifications produced by RSA Laboratories in cooperation with secure systems developers worldwide. Their whole goal is accelerating the deployment of public-key cryptography, and they're honestly so impressive ๐ญ The PKCS series was first published in 1991 after meetings with a small group of early adopters of public-key technology, and the documents have become widely referenced and implemented ever since. Contributions from the PKCS series have become part of many formal and de facto standards, including ANSI X9 documents, PKIX, Secure Electronic Transaction (SET), S/MIME, and SSL. Iykyk, and now you know ๐ซถ
Further development of most PKCS documents happens through the IETF. Suggestions for improvement are welcome, so speak up if you have ideas ๐
Acknowledgements ๐
This document is based on a contribution of RSA Laboratories, the research center of RSA Security Inc. Huge thanks to them ๐ท
RC2 and RC5 are trademarks of EMC Corporation. Trademark tea, noted ๐
Authors' Addresses ๐ฎ
Kathleen M. Moriarty (editor)
Dell EMC
176 South Street
Hopkinton, MA 01748
United States of America
Email: Kathleen.Moriarty@Dell.com
Burt Kaliski
Verisign
12061 Bluemont Way
Reston, VA 20190
United States of America
Email: bkaliski@verisign.com
URI: http://verisignlabs.com
Andreas Rusch
RSA
345 Queen Street
Brisbane, QLD 4000
Australia
Email: andreas.rusch@rsa.com
๐ฆ where this page comes from
- ietf: rfc8018 2017-01
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms