tech-invite   World Map
3GPP     Specs     Glossaries     Architecture     IMS     UICC       IETF     RFCs     Groups     SIP     ABNFs       Search     Home

RFC 8018

Informational
Pages: 40
Top     in Index     Prev     Next
in Group Index     Prev in Group     No Next: Highest Number in Group     Group: ~sec-pkcs

PKCS #5: Password-Based Cryptography Specification Version 2.1

Part 1 of 2, p. 1 to 19
None       Next Section

Obsoletes:    2898


Top       ToC       Page 1 
Internet Engineering Task Force (IETF)                  K. Moriarty, Ed.
Request for Comments: 8018                                      Dell EMC
Obsoletes: 2898                                               B. Kaliski
Category: Informational                                         Verisign
ISSN: 2070-1721                                                 A. Rusch
                                                                     RSA
                                                            January 2017


           PKCS #5: Password-Based Cryptography Specification
                              Version 2.1

Abstract

   This document provides recommendations for the implementation of
   password-based cryptography, covering key derivation functions,
   encryption schemes, message authentication schemes, and ASN.1 syntax
   identifying the techniques.

   This document represents a republication of PKCS #5 v2.1 from RSA
   Laboratories' Public-Key Cryptography Standards (PKCS) series.  By
   publishing this RFC, change control is transferred to the IETF.

   This document also obsoletes RFC 2898.

Status of This Memo

   This document is not an Internet Standards Track specification; it is
   published for informational purposes.

   This document is a product of the Internet Engineering Task Force
   (IETF).  It represents the consensus of the IETF community.  It has
   received public review and has been approved for publication by the
   Internet Engineering Steering Group (IESG).  Not all documents
   approved by the IESG are a candidate for any level of Internet
   Standard; see Section 2 of RFC 7841.

   Information about the current status of this document, any errata,
   and how to provide feedback on it may be obtained at
   http://www.rfc-editor.org/info/rfc8018.

Top      ToC       Page 2 
Copyright Notice

   Copyright (c) 2017 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (http://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

Top       Page 3 
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

Top      ToC       Page 4 
1. Introduction

   This document provides recommendations for the implementation of
   password-based cryptography, covering the following aspects:

   -  key derivation functions
   -  encryption schemes
   -  message authentication schemes
   -  ASN.1 syntax identifying the techniques

   The recommendations are intended for general application within
   computer and communications systems and, as such, include a fair
   amount of flexibility.  They are particularly intended for the
   protection of sensitive information such as private keys as in
   PKCS #8 [PKCS8] [RFC5958].  It is expected that application standards
   and implementation profiles based on these specifications may include
   additional constraints.

   Other cryptographic techniques based on passwords, such as password-
   based key entity authentication and key establishment protocols
   [BELLOV] [JABLON] [WU] are outside the scope of this document.
   Guidelines for the selection of passwords are also outside the scope.
   This document supersedes PKCS #5 version 2.0 [RFC2898] but includes
   compatible techniques.

   This document represents a republication of PKCS #5 v2.1 [PKCS5_21]
   from RSA Laboratories' Public-Key Cryptography Standards (PKCS)
   series.

2.  Notation

   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

Top      ToC       Page 5 
   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

   In many applications of public-key cryptography, user security is
   ultimately dependent on one or more secret text values or passwords.
   Since a password is not directly applicable as a key to any
   conventional cryptosystem, however, some processing of the password
   is required to perform cryptographic operations with it.  Moreover,
   as passwords are often chosen from a relatively small space, special
   care is required in that processing to defend against search attacks.

   A general approach to password-based cryptography, as described by
   Morris and Thompson [MORRIS] for the protection of password tables,
   is to combine a password with a salt to produce a key.  The salt can

Top      ToC       Page 6 
   be viewed as an index into a large set of keys derived from the
   password and need not be kept secret.  Although it may be possible
   for an opponent to construct a table of possible passwords (a so-
   called "dictionary attack"), constructing a table of possible keys
   will be difficult, since there will be many possible keys for each
   password.  An opponent will thus be limited to searching through
   passwords separately for each salt.

   Another approach to password-based cryptography is to construct key
   derivation techniques that are relatively expensive, thereby
   increasing the cost of exhaustive search.  One way to do this is to
   include an iteration count in the key derivation technique,
   indicating how many times to iterate some underlying function by
   which keys are derived.  A modest number of iterations (say, 1000) is
   not likely to be a burden for legitimate parties when computing a
   key, but will be a significant burden for opponents.

   Salt and iteration count formed the basis for password-based
   encryption in PKCS #5 v2.0, and are adopted here as well for the
   various cryptographic operations.  Thus, password-based key
   derivation as defined here is a function of a password, a salt, and
   an iteration count, where the latter two quantities need not be kept
   secret.

   From a password-based key derivation function, it is straightforward
   to define password-based encryption and message authentication
   schemes.  As in PKCS #5 v2.0, the password-based encryption schemes
   here are based on an underlying, conventional encryption scheme,
   where the key for the conventional scheme is derived from the
   password.  Similarly, the password-based message authentication
   scheme is based on an underlying conventional scheme.  This
   two-layered approach makes the password-based techniques modular in
   terms of the underlying techniques they can be based on.

   It is expected that the password-based key derivation functions may
   find other applications than just the encryption and message
   authentication schemes defined here.  For instance, one might derive
   a set of keys with a single application of a key derivation function,
   rather than derive each key with a separate application of the
   function.  The keys in the set would be obtained as substrings of the
   output of the key derivation function.  This approach might be
   employed as part of key establishment in a session-oriented protocol.
   Another application is password checking, where the output of the key
   derivation function is stored (along with the salt and iteration
   count) for the purposes of subsequent verification of a password.

   Throughout this document, a password is considered to be an octet
   string of arbitrary length whose interpretation as a text string is

Top      ToC       Page 7 
   unspecified.  In the interest of interoperability, however, it is
   recommended that applications follow some common text encoding rules.
   ASCII and UTF-8 [RFC3629] are two possibilities.  (ASCII is a subset
   of UTF-8.)

   Although the selection of passwords is outside the scope of this
   document, guidelines have been published [NISTSP63] that may well be
   taken into account.

4.  Salt and Iteration Count

   Inasmuch as salt and iteration count are central to the techniques
   defined in this document, some further discussion is warranted.

4.1.  Salt

   A salt in password-based cryptography has traditionally served the
   purpose of producing a large set of keys corresponding to a given
   password, one of which is selected at random according to the salt.
   An individual key in the set is selected by applying a key derivation
   function KDF, as

                              DK = KDF (P, S)

   where DK is the derived key, P is the password, and S is the salt.
   This has two benefits:

      1.  It is 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 thus limited to searching for passwords after a password-
          based operation has been performed and the salt is known.

      2.  It is unlikely that the same key will be selected twice.
          Again, if the salt is 64 bits long, the chance of "collision"
          between keys does not 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 arise when using some encryption and authentication
          techniques.

   In password-based encryption, the party encrypting a message can gain
   assurance that these benefits are realized simply by selecting a
   large and sufficiently random salt when deriving an encryption key
   from a password.  A party generating a message authentication code
   can gain such assurance in a similar fashion.

Top      ToC       Page 8 
   The party decrypting a message or verifying a message authentication
   code, however, cannot be sure that a salt supplied by another party
   has actually been generated at random.  It is possible, for instance,
   that the salt may have been copied from another password-based
   operation in an attempt to exploit interactions between multiple uses
   of the same key.  For instance, suppose two legitimate 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 provide it to one of the
   parties as though it were for a 40-bit key.  If the party reveals the
   result of decryption with the 40-bit key, the opponent may be able to
   solve for the 40-bit key.  In the case 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 such attacks, either the interaction between
   multiple uses of the same key should 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 this, the following is recommended for salt selection:

      1.  If there is 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 need not be checked for a particular format by
          the party receiving the salt.  It should be at least eight
          octets (64 bits) long.

      2.  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, and 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.

Top      ToC       Page 9 
   Note: If a random number generator or pseudorandom generator is not
   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 served the purpose of increasing
   the cost of producing keys from a password, thereby also increasing
   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
   environment and circumstances, and 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, hence the independent definition of these
   functions.

   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.

Top      ToC       Page 10 
   A typical application of the key derivation functions defined here
   might include the following steps:

      1.  Select a salt S and an iteration count c, as outlined in
          Section 4.

      2.  Select a length in octets for the derived key, dkLen.

      3.  Apply the key derivation function to the password, the salt,
          the iteration count and the key length to produce a derived
          key.

      4.  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

   PBKDF1 applies a hash function, which shall be MD2 [RFC1319], MD5
   [RFC1321], or SHA-1 [NIST180], to derive keys.  The length of the
   derived key is bounded by the length of the hash function output,
   which is 16 octets for MD2 and MD5 and 20 octets for SHA-1.  PBKDF1
   is compatible with the key derivation process in PKCS #5 v1.5
   [PKCS5_15].

   PBKDF1 is recommended only for compatibility with existing
   applications since the keys it produces 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:

      1.  If dkLen > 16 for MD2 and MD5, or dkLen > 20 for SHA-1, output
          "derived key too long" and stop.

Top      ToC       Page 11 
      2.  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:

                            T_1 = Hash (P || S) ,
                            T_2 = Hash (T_1) ,
                            ...
                            T_c = Hash (T_{c-1}) ,
                            DK = T_c<0..dkLen-1>

      3.  Output the derived key DK.

5.2.  PBKDF2

   PBKDF2 applies a pseudorandom function (see Appendix B.1 for an
   example) to derive keys.  The length of the derived key 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:

      1.  If dkLen > (2^32 - 1) * hLen, output "derived key too long"
          and stop.

      2.  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

Top      ToC       Page 12 
          Here, CEIL (x) is the "ceiling" function, i.e., the smallest
          integer greater than, or equal to, x.

      3.  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.

      4.  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>

      5.  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.

Top      ToC       Page 13 
6.  Encryption Schemes

   An encryption scheme, in the symmetric setting, consists of an
   encryption operation and a decryption operation, where 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 which 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:

      1.  Select an eight-octet salt S and an iteration count c, as
          outlined in Section 4.

      2.  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)

Top      ToC       Page 14 
      3.  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>

      4.  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].)

      5.  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.

      6.  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).

Top      ToC       Page 15 
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:

      1.  Obtain the eight-octet salt S and the iteration count c.

      2.  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)

      3.  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>

      4.  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.

      5.  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.

      6.  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.

Top      ToC       Page 16 
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:

      1.  Select a salt S and an iteration count c, as outlined in
          Section 4.

      2.  Select the length in octets, dkLen, for the derived key for
          the underlying encryption scheme.

      3.  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)

      4.  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.)

      5.  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

   The decryption operation for PBES2 consists of the following steps,
   which decrypt a ciphertext C under a password P to recover a message
   M:

      1.  Obtain the salt S for the operation.

      2.  Obtain the iteration count c for the key derivation function.

      3.  Obtain the key length in octets, dkLen, for the derived key
          for the underlying encryption scheme.

Top      ToC       Page 17 
      4.  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)

      5.  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.

      6.  Output the recovered message M.

7.  Message Authentication Schemes

   A message authentication scheme consists of a MAC (Message
   Authentication Code) generation operation and a MAC verification
   operation, where the MAC generation operation produces a MAC from a
   message under a key, and the MAC verification operation verifies the
   message authentication code under the same key.  In a password-based
   message authentication 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 the scheme.

7.1.1.  PBMAC1 Generation Operation

   The MAC generation operation for PBMAC1 consists of the following
   steps, which process a message M under a password P to generate a
   message authentication code T, applying a selected key derivation
   function KDF and a selected underlying message authentication scheme:

      1.  Select a salt S and an iteration count c, as outlined in
          Section 4.

      2.  Select a key length in octets, dkLen, for the derived key for
          the underlying message authentication function.

Top      ToC       Page 18 
      3.  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)

      4.  Process the message M with the underlying message
          authentication scheme under the derived key DK to generate a
          message authentication code T.

      5.  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).

7.1.2.  PBMAC1 Verification Operation

   The MAC verification operation for PBMAC1 consists of the following
   steps, which process a message M under a password P to verify a
   message authentication code T:

      1.  Obtain the salt S and the iteration count c.

      2.  Obtain the key length in octets, dkLen, for the derived key
          for the underlying message authentication scheme.

      3.  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)

      4.  Process the message M with the underlying message
          authentication scheme under the derived key DK to verify the
          message authentication code T.

      5.  If the message authentication code verifies, output "correct";
          else output "incorrect".

8.  Security Considerations

   Password-based cryptography is generally limited in the security that
   it can provide, particularly for methods such as those defined in
   this document where offline password search is possible.  While the
   use of salt and iteration count can increase the complexity of attack
   (see Section 4 for recommendations), it is essential that passwords

Top      ToC       Page 19 
   are selected well, and relevant guidelines (e.g., [NISTSP63]) should
   be taken into account.  It is also important that passwords be
   protected well if stored.

   In general, different keys should be derived from a password for
   different uses to minimize the possibility of unintended
   interactions.  For password-based encryption with a single algorithm,
   a random salt is sufficient to ensure that different keys will be
   produced.  In certain other situations, as outlined in Section 4, a
   structured salt is necessary.  The recommendations in Section 4
   should thus be taken into account when selecting 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].



(page 19 continued on part 2)

Next Section