Tech-invite3GPPspaceIETFspace
959493929190898887868584838281807978777675747372717069686766656463626160595857565554535251504948474645444342414039383736353433323130292827262524232221201918171615141312111009080706050403020100
in Index   Prev   Next

RFC 8017

PKCS #1: RSA Cryptography Specifications Version 2.2

Pages: 78
Informational
Errata
Obsoletes:  3447
Part 2 of 4 – Pages 18 to 39
First   Prev   Next

Top   ToC   RFC8017 - Page 18   prevText

7. Encryption Schemes

For the purposes of this document, an encryption scheme consists of an encryption operation and a decryption operation, where the encryption operation produces a ciphertext from a message with a recipient's RSA public key, and the decryption operation recovers the message from the ciphertext with the recipient's corresponding RSA private key. An encryption scheme can be employed in a variety of applications. A typical application is a key establishment protocol, where the message contains key material to be delivered confidentially from one party to another. For instance, PKCS #7 [RFC2315] employs such a protocol to deliver a content-encryption key from a sender to a recipient; the encryption schemes defined here would be suitable key- encryption algorithms in that context. Two encryption schemes are specified in this document: RSAES-OAEP and RSAES-PKCS1-v1_5. RSAES-OAEP is REQUIRED to be supported for new applications; RSAES-PKCS1-v1_5 is included only for compatibility with existing applications. The encryption schemes given here follow a general model similar to that employed in IEEE 1363 [IEEE1363], combining encryption and decryption primitives with an encoding method for encryption. The encryption operations apply a message encoding operation to a message to produce an encoded message, which is then converted to an integer message representative. An encryption primitive is applied to the message representative to produce the ciphertext. Reversing this, the decryption operations apply a decryption primitive to the
Top   ToC   RFC8017 - Page 19
   ciphertext to recover a message representative, which is then
   converted to an octet-string-encoded message.  A message decoding
   operation is applied to the encoded message to recover the message
   and verify the correctness of the decryption.

   To avoid implementation weaknesses related to the way errors are
   handled within the decoding operation (see [BLEICHENBACHER] and
   [MANGER]), the encoding and decoding operations for RSAES-OAEP and
   RSAES-PKCS1-v1_5 are embedded in the specifications of the respective
   encryption schemes rather than defined in separate specifications.
   Both encryption schemes are compatible with the corresponding schemes
   in PKCS #1 v2.1.

7.1. RSAES-OAEP

RSAES-OAEP combines the RSAEP and RSADP primitives (Sections 5.1.1 and 5.1.2) with the EME-OAEP encoding method (Step 2 in Section 7.1.1, and Step 3 in Section 7.1.2). EME-OAEP is based on Bellare and Rogaway's Optimal Asymmetric Encryption scheme [OAEP]. It is compatible with the Integer Factorization Encryption Scheme (IFES) defined in IEEE 1363 [IEEE1363], where the encryption and decryption primitives are IFEP-RSA and IFDP-RSA and the message encoding method is EME-OAEP. RSAES-OAEP can operate on messages of length up to k - 2hLen -2 octets, where hLen is the length of the output from the underlying hash function and k is the length in octets of the recipient's RSA modulus. Assuming that computing e-th roots modulo n is infeasible and the mask generation function in RSAES-OAEP has appropriate properties, RSAES-OAEP is semantically secure against adaptive chosen-ciphertext attacks. This assurance is provable in the sense that the difficulty of breaking RSAES-OAEP can be directly related to the difficulty of inverting the RSA function, provided that the mask generation function is viewed as a black box or random oracle; see [FOPS] and the note below for further discussion. Both the encryption and the decryption operations of RSAES-OAEP take the value of a label L as input. In this version of PKCS #1, L is the empty string; other uses of the label are outside the scope of this document. See Appendix A.2.1 for the relevant ASN.1 syntax. RSAES-OAEP is parameterized by the choice of hash function and mask generation function. This choice should be fixed for a given RSA key. Suggested hash and mask generation functions are given in Appendix B.
Top   ToC   RFC8017 - Page 20
   Note: Past results have helpfully clarified the security properties
   of the OAEP encoding method [OAEP]  (roughly the procedure described
   in Step 2 in Section 7.1.1).  The background is as follows.  In 1994,
   Bellare and Rogaway [OAEP] introduced a security concept that they
   denoted plaintext awareness (PA94).  They proved that if a
   deterministic public-key encryption primitive (e.g., RSAEP) is hard
   to invert without the private key, then the corresponding OAEP-based
   encryption scheme is plaintext aware (in the random oracle model),
   meaning roughly that an adversary cannot produce a valid ciphertext
   without actually "knowing" the underlying plaintext.  Plaintext
   awareness of an encryption scheme is closely related to the
   resistance of the scheme against chosen-ciphertext attacks.  In such
   attacks, an adversary is given the opportunity to send queries to an
   oracle simulating the decryption primitive.  Using the results of
   these queries, the adversary attempts to decrypt a challenge
   ciphertext.

   However, there are two flavors of chosen-ciphertext attacks, and PA94
   implies security against only one of them.  The difference relies on
   what the adversary is allowed to do after she is given the challenge
   ciphertext.  The indifferent attack scenario (denoted CCA1) does not
   admit any queries to the decryption oracle after the adversary is
   given the challenge ciphertext, whereas the adaptive scenario
   (denoted CCA2) does (except that the decryption oracle refuses to
   decrypt the challenge ciphertext once it is published).  In 1998,
   Bellare and Rogaway, together with Desai and Pointcheval [PA98], came
   up with a new, stronger notion of plaintext awareness (PA98) that
   does imply security against CCA2.

   To summarize, there have been two potential sources for
   misconception: that PA94 and PA98 are equivalent concepts, or that
   CCA1 and CCA2 are equivalent concepts.  Either assumption leads to
   the conclusion that the Bellare-Rogaway paper implies security of
   OAEP against CCA2, which it does not.

   (Footnote: It might be fair to mention that PKCS #1 v2.0 cites [OAEP]
   and claims that "a chosen ciphertext attack is ineffective against a
   plaintext-aware encryption scheme such as RSAES-OAEP" without
   specifying the kind of plaintext awareness or chosen ciphertext
   attack considered.)

   OAEP has never been proven secure against CCA2; in fact, Victor Shoup
   [SHOUP] has demonstrated that such a proof does not exist in the
   general case.  Put briefly, Shoup showed that an adversary in the
   CCA2 scenario who knows how to partially invert the encryption
   primitive but does not know how to invert it completely may well be
   able to break the scheme.  For example, one may imagine an attacker
   who is able to break RSAES-OAEP if she knows how to recover all but
Top   ToC   RFC8017 - Page 21
   the first 20 bytes of a random integer encrypted with RSAEP.  Such an
   attacker does not need to be able to fully invert RSAEP, because she
   does not use the first 20 octets in her attack.

   Still, RSAES-OAEP is secure against CCA2, which was proved by
   Fujisaki, Okamoto, Pointcheval, and Stern [FOPS] shortly after the
   announcement of Shoup's result.  Using clever lattice reduction
   techniques, they managed to show how to invert RSAEP completely given
   a sufficiently large part of the pre-image.  This observation,
   combined with a proof that OAEP is secure against CCA2 if the
   underlying encryption primitive is hard to partially invert, fills
   the gap between what Bellare and Rogaway proved about RSAES-OAEP and
   what some may have believed that they proved.  Somewhat
   paradoxically, we are hence saved by an ostensible weakness in RSAEP
   (i.e., the whole inverse can be deduced from parts of it).

   Unfortunately, however, the security reduction is not efficient for
   concrete parameters.  While the proof successfully relates an
   adversary A against the CCA2 security of RSAES-OAEP to an algorithm I
   inverting RSA, the probability of success for I is only approximately
   \epsilon^2 / 2^18, where \epsilon is the probability of success for
   A.

   (Footnote: In [FOPS], the probability of success for the inverter was
   \epsilon^2 / 4.  The additional factor 1 / 2^16 is due to the eight
   fixed zero bits at the beginning of the encoded message EM, which are
   not present in the variant of OAEP considered in [FOPS].  (A must be
   applied twice to invert RSA, and each application corresponds to a
   factor 1 / 2^8.))

   In addition, the running time for I is approximately t^2, where t is
   the running time of the adversary.  The consequence is that we cannot
   exclude the possibility that attacking RSAES-OAEP is considerably
   easier than inverting RSA for concrete parameters.  Still, the
   existence of a security proof provides some assurance that the
   RSAES-OAEP construction is sounder than ad hoc constructions such as
   RSAES-PKCS1-v1_5.

   Hybrid encryption schemes based on the RSA Key Encapsulation
   Mechanism (RSA-KEM) paradigm offer tight proofs of security directly
   applicable to concrete parameters; see [ISO18033] for discussion.
   Future versions of PKCS #1 may specify schemes based on this
   paradigm.
Top   ToC   RFC8017 - Page 22

7.1.1. Encryption Operation

RSAES-OAEP-ENCRYPT ((n, e), M, L) Options: Hash hash function (hLen denotes the length in octets of the hash function output) MGF mask generation function Input: (n, e) recipient's RSA public key (k denotes the length in octets of the RSA modulus n) M message to be encrypted, an octet string of length mLen, where mLen <= k - 2hLen - 2 L optional label to be associated with the message; the default value for L, if L is not provided, is the empty string Output: C ciphertext, an octet string of length k Errors: "message too long"; "label too long" Assumption: RSA public key (n, e) is valid Steps: 1. Length checking: a. If the length of L is greater than the input limitation for the hash function (2^61 - 1 octets for SHA-1), output "label too long" and stop. b. If mLen > k - 2hLen - 2, output "message too long" and stop. 2. EME-OAEP encoding (see Figure 1 below): a. If the label L is not provided, let L be the empty string. Let lHash = Hash(L), an octet string of length hLen (see the note below). b. Generate a padding string PS consisting of k - mLen - 2hLen - 2 zero octets. The length of PS may be zero.
Top   ToC   RFC8017 - Page 23
          c.  Concatenate lHash, PS, a single octet with hexadecimal
              value 0x01, and the message M to form a data block DB of
              length k - hLen - 1 octets as

                 DB = lHash || PS || 0x01 || M.

          d.  Generate a random octet string seed of length hLen.

          e.  Let dbMask = MGF(seed, k - hLen - 1).

          f.  Let maskedDB = DB \xor dbMask.

          g.  Let seedMask = MGF(maskedDB, hLen).

          h.  Let maskedSeed = seed \xor seedMask.

          i.  Concatenate a single octet with hexadecimal value 0x00,
              maskedSeed, and maskedDB to form an encoded message EM of
              length k octets as

                 EM = 0x00 || maskedSeed || maskedDB.

      3.  RSA encryption:

          a.  Convert the encoded message EM to an integer message
              representative m (see Section 4.2):

                 m = OS2IP (EM).

          b.  Apply the RSAEP encryption primitive (Section 5.1.1) to
              the RSA public key (n, e) and the message representative m
              to produce an integer ciphertext representative c:

                 c = RSAEP ((n, e), m).

          c.  Convert the ciphertext representative c to a ciphertext C
              of length k octets (see Section 4.1):

                 C = I2OSP (c, k).
Top   ToC   RFC8017 - Page 24
      4.  Output the ciphertext C.

      _________________________________________________________________

                                +----------+------+--+-------+
                           DB = |  lHash   |  PS  |01|   M   |
                                +----------+------+--+-------+
                                               |
                     +----------+              |
                     |   seed   |              |
                     +----------+              |
                           |                   |
                           |-------> MGF ---> xor
                           |                   |
                  +--+     V                   |
                  |00|    xor <----- MGF <-----|
                  +--+     |                   |
                    |      |                   |
                    V      V                   V
                  +--+----------+----------------------------+
            EM =  |00|maskedSeed|          maskedDB          |
                  +--+----------+----------------------------+
      _________________________________________________________________

                   Figure 1: EME-OAEP Encoding Operation

   Notes:

   -  lHash is the hash of the optional label L.

   -  The decoding operation follows reverse steps to recover M and
      verify lHash and PS.

   -  If L is the empty string, the corresponding hash value lHash has
      the following hexadecimal representation for different choices of
      Hash:

      SHA-1:   (0x)da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709
      SHA-256: (0x)e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c
                   a495991b 7852b855
      SHA-384: (0x)38b060a7 51ac9638 4cd9327e b1b1e36a 21fdb711 14be0743
                   4c0cc7bf 63f6e1da 274edebf e76f65fb d51ad2f1 4898b95b
      SHA-512: (0x)cf83e135 7eefb8bd f1542850 d66d8007 d620e405 0b5715dc
                   83f4a921 d36ce9ce 47d0d13c 5d85f2b0 ff8318d2 877eec2f
                   63b931bd 47417a81 a538327a f927da3e
Top   ToC   RFC8017 - Page 25

7.1.2. Decryption Operation

RSAES-OAEP-DECRYPT (K, C, L) Options: Hash hash function (hLen denotes the length in octets of the hash function output) MGF mask generation function Input: K recipient's RSA private key (k denotes the length in octets of the RSA modulus n), where k >= 2hLen + 2 C ciphertext to be decrypted, an octet string of length k L optional label whose association with the message is to be verified; the default value for L, if L is not provided, is the empty string Output: M message, an octet string of length mLen, where mLen <= k - 2hLen - 2 Error: "decryption error" Steps: 1. Length checking: a. If the length of L is greater than the input limitation for the hash function (2^61 - 1 octets for SHA-1), output "decryption error" and stop. b. If the length of the ciphertext C is not k octets, output "decryption error" and stop. c. If k < 2hLen + 2, output "decryption error" and stop. 2. RSA decryption: a. Convert the ciphertext C to an integer ciphertext representative c (see Section 4.2): c = OS2IP (C).
Top   ToC   RFC8017 - Page 26
          b.  Apply the RSADP decryption primitive (Section 5.1.2) to
              the RSA private key K and the ciphertext representative c
              to produce an integer message representative m:

                 m = RSADP (K, c).

              If RSADP outputs "ciphertext representative out of range"
              (meaning that c >= n), output "decryption error" and stop.

          c.  Convert the message representative m to an encoded message
              EM of length k octets (see Section 4.1):

                 EM = I2OSP (m, k).

      3.  EME-OAEP decoding:

          a.  If the label L is not provided, let L be the empty string.
              Let lHash = Hash(L), an octet string of length hLen (see
              the note in Section 7.1.1).

          b.  Separate the encoded message EM into a single octet Y, an
              octet string maskedSeed of length hLen, and an octet
              string maskedDB of length k - hLen - 1 as

                 EM = Y || maskedSeed || maskedDB.

          c.  Let seedMask = MGF(maskedDB, hLen).

          d.  Let seed = maskedSeed \xor seedMask.

          e.  Let dbMask = MGF(seed, k - hLen - 1).

          f.  Let DB = maskedDB \xor dbMask.

          g.  Separate DB into an octet string lHash' of length hLen, a
              (possibly empty) padding string PS consisting of octets
              with hexadecimal value 0x00, and a message M as

                 DB = lHash' || PS || 0x01 || M.

              If there is no octet with hexadecimal value 0x01 to
              separate PS from M, if lHash does not equal lHash', or if
              Y is nonzero, output "decryption error" and stop.  (See
              the note below.)
Top   ToC   RFC8017 - Page 27
      4.  Output the message M.

      Note: Care must be taken to ensure that an opponent cannot
      distinguish the different error conditions in Step 3.g, whether by
      error message or timing, and, more generally, that an opponent
      cannot learn partial information about the encoded message EM.
      Otherwise, an opponent may be able to obtain useful information
      about the decryption of the ciphertext C, leading to a chosen-
      ciphertext attack such as the one observed by Manger [MANGER].

7.2. RSAES-PKCS1-v1_5

RSAES-PKCS1-v1_5 combines the RSAEP and RSADP primitives (Sections 5.1.1 and 5.1.2) with the EME-PKCS1-v1_5 encoding method (Step 2 in Section 7.2.1, and Step 3 in Section 7.2.2). It is mathematically equivalent to the encryption scheme in PKCS #1 v1.5. RSAES-PKCS1-v1_5 can operate on messages of length up to k - 11 octets (k is the octet length of the RSA modulus), although care should be taken to avoid certain attacks on low-exponent RSA due to Coppersmith, Franklin, Patarin, and Reiter when long messages are encrypted (see the third bullet in the notes below and [LOWEXP]; [NEWATTACK] contains an improved attack). As a general rule, the use of this scheme for encrypting an arbitrary message, as opposed to a randomly generated key, is NOT RECOMMENDED. It is possible to generate valid RSAES-PKCS1-v1_5 ciphertexts without knowing the corresponding plaintexts, with a reasonable probability of success. This ability can be exploited in a chosen-ciphertext attack as shown in [BLEICHENBACHER]. Therefore, if RSAES-PKCS1-v1_5 is to be used, certain easily implemented countermeasures should be taken to thwart the attack found in [BLEICHENBACHER]. Typical examples include the addition of structure to the data to be encoded, rigorous checking of PKCS #1 v1.5 conformance (and other redundancy) in decrypted messages, and the consolidation of error messages in a client-server protocol based on PKCS #1 v1.5. These can all be effective countermeasures and do not involve changes to a protocol based on PKCS #1 v1.5. See [BKS] for a further discussion of these and other countermeasures. It has recently been shown that the security of the SSL/TLS handshake protocol [RFC5246], which uses RSAES-PKCS1-v1_5 and certain countermeasures, can be related to a variant of the RSA problem; see [RSATLS] for discussion. Note: The following passages describe some security recommendations pertaining to the use of RSAES-PKCS1-v1_5. Recommendations from PKCS #1 v1.5 are included as well as new recommendations motivated by cryptanalytic advances made in the intervening years.
Top   ToC   RFC8017 - Page 28
   o  It is RECOMMENDED that the pseudorandom octets in Step 2 in
      Section 7.2.1 be generated independently for each encryption
      process, especially if the same data is input to more than one
      encryption process.  Haastad's results [HAASTAD] are one
      motivation for this recommendation.

   o  The padding string PS in Step 2 in Section 7.2.1 is at least eight
      octets long, which is a security condition for public-key
      operations that makes it difficult for an attacker to recover data
      by trying all possible encryption blocks.

   o  The pseudorandom octets can also help thwart an attack due to
      Coppersmith et al.  [LOWEXP] (see [NEWATTACK] for an improvement
      of the attack) when the size of the message to be encrypted is
      kept small.  The attack works on low-exponent RSA when similar
      messages are encrypted with the same RSA public key.  More
      specifically, in one flavor of the attack, when two inputs to
      RSAEP agree on a large fraction of bits (8/9) and low-exponent RSA
      (e = 3) is used to encrypt both of them, it may be possible to
      recover both inputs with the attack.  Another flavor of the attack
      is successful in decrypting a single ciphertext when a large
      fraction (2/3) of the input to RSAEP is already known.  For
      typical applications, the message to be encrypted is short (e.g.,
      a 128-bit symmetric key), so not enough information will be known
      or common between two messages to enable the attack.  However, if
      a long message is encrypted, or if part of a message is known,
      then the attack may be a concern.  In any case, the RSAES-OAEP
      scheme overcomes the attack.

7.2.1. Encryption Operation

RSAES-PKCS1-V1_5-ENCRYPT ((n, e), M) Input: (n, e) recipient's RSA public key (k denotes the length in octets of the modulus n) M message to be encrypted, an octet string of length mLen, where mLen <= k - 11 Output: C ciphertext, an octet string of length k Error: "message too long"
Top   ToC   RFC8017 - Page 29
   Steps:

      1.  Length checking: If mLen > k - 11, output "message too long"
          and stop.

      2.  EME-PKCS1-v1_5 encoding:

          a.  Generate an octet string PS of length k - mLen - 3
              consisting of pseudo-randomly generated nonzero octets.
              The length of PS will be at least eight octets.

          b.  Concatenate PS, the message M, and other padding to form
              an encoded message EM of length k octets as

                 EM = 0x00 || 0x02 || PS || 0x00 || M.

      3.  RSA encryption:

          a.  Convert the encoded message EM to an integer message
              representative m (see Section 4.2):

                 m = OS2IP (EM).

          b.  Apply the RSAEP encryption primitive (Section 5.1.1) to
              the RSA public key (n, e) and the message representative m
              to produce an integer ciphertext representative c:

                 c = RSAEP ((n, e), m).

          c.  Convert the ciphertext representative c to a ciphertext C
              of length k octets (see Section 4.1):

                 C = I2OSP (c, k).

      4.  Output the ciphertext C.

7.2.2. Decryption Operation

RSAES-PKCS1-V1_5-DECRYPT (K, C) Input: K recipient's RSA private key C ciphertext to be decrypted, an octet string of length k, where k is the length in octets of the RSA modulus n
Top   ToC   RFC8017 - Page 30
   Output:

      M        message, an octet string of length at most k - 11

   Error:  "decryption error"

   Steps:

      1.  Length checking: If the length of the ciphertext C is not k
          octets (or if k < 11), output "decryption error" and stop.

      2.  RSA decryption:

          a.  Convert the ciphertext C to an integer ciphertext
              representative c (see Section 4.2):

                 c = OS2IP (C).

          b.  Apply the RSADP decryption primitive (Section 5.1.2) to
              the RSA private key (n, d) and the ciphertext
              representative c to produce an integer message
              representative m:

                 m = RSADP ((n, d), c).

              If RSADP outputs "ciphertext representative out of range"
              (meaning that c >= n), output "decryption error" and stop.

          c.  Convert the message representative m to an encoded message
              EM of length k octets (see Section 4.1):

                 EM = I2OSP (m, k).

      3.  EME-PKCS1-v1_5 decoding: Separate the encoded message EM into
          an octet string PS consisting of nonzero octets and a message
          M as

             EM = 0x00 || 0x02 || PS || 0x00 || M.

          If the first octet of EM does not have hexadecimal value 0x00,
          if the second octet of EM does not have hexadecimal value
          0x02, if there is no octet with hexadecimal value 0x00 to
          separate PS from M, or if the length of PS is less than 8
          octets, output "decryption error" and stop.  (See the note
          below.)

      4.  Output M.
Top   ToC   RFC8017 - Page 31
      Note: Care shall be taken to ensure that an opponent cannot
      distinguish the different error conditions in Step 3, whether by
      error message or timing.  Otherwise, an opponent may be able to
      obtain useful information about the decryption of the ciphertext
      C, leading to a strengthened version of Bleichenbacher's attack
      [BLEICHENBACHER]; compare to Manger's attack [MANGER].

8. Signature Scheme with Appendix

For the purposes of this document, a signature scheme with appendix consists of a signature generation operation and a signature verification operation, where the signature generation operation produces a signature from a message with a signer's RSA private key, and the signature verification operation verifies the signature on the message with the signer's corresponding RSA public key. To verify a signature constructed with this type of scheme, it is necessary to have the message itself. In this way, signature schemes with appendix are distinguished from signature schemes with message recovery, which are not supported in this document. A signature scheme with appendix can be employed in a variety of applications. For instance, the signature schemes with appendix defined here would be suitable signature algorithms for X.509 certificates [ISO9594]. Related signature schemes could be employed in PKCS #7 [RFC2315], although for technical reasons the current version of PKCS #7 separates a hash function from a signature scheme, which is different than what is done here; see the note in Appendix A.2.3 for more discussion. Two signature schemes with appendix are specified in this document: RSASSA-PSS and RSASSA-PKCS1-v1_5. Although no attacks are known against RSASSA-PKCS1-v1_5, in the interest of increased robustness, RSASSA-PSS is REQUIRED in new applications. RSASSA-PKCS1-v1_5 is included only for compatibility with existing applications. The signature schemes with appendix given here follow a general model similar to that employed in IEEE 1363 [IEEE1363], combining signature and verification primitives with an encoding method for signatures. The signature generation operations apply a message encoding operation to a message to produce an encoded message, which is then converted to an integer message representative. A signature primitive is applied to the message representative to produce the signature. Reversing this, the signature verification operations apply a signature verification primitive to the signature to recover a message representative, which is then converted to an octet-string- encoded message. A verification operation is applied to the message and the encoded message to determine whether they are consistent.
Top   ToC   RFC8017 - Page 32
   If the encoding method is deterministic (e.g., EMSA-PKCS1-v1_5), the
   verification operation may apply the message encoding operation to
   the message and compare the resulting encoded message to the
   previously derived encoded message.  If there is a match, the
   signature is considered valid.  If the method is randomized (e.g.,
   EMSA-PSS), the verification operation is typically more complicated.
   For example, the verification operation in EMSA-PSS extracts the
   random salt and a hash output from the encoded message and checks
   whether the hash output, the salt, and the message are consistent;
   the hash output is a deterministic function in terms of the message
   and the salt.  For both signature schemes with appendix defined in
   this document, the signature generation and signature verification
   operations are readily implemented as "single-pass" operations if the
   signature is placed after the message.  See PKCS #7 [RFC2315] for an
   example format in the case of RSASSA-PKCS1-v1_5.

8.1. RSASSA-PSS

RSASSA-PSS combines the RSASP1 and RSAVP1 primitives with the EMSA-PSS encoding method. It is compatible with the Integer Factorization Signature Scheme with Appendix (IFSSA) as amended in IEEE 1363a [IEEE1363A], where the signature and verification primitives are IFSP-RSA1 and IFVP-RSA1 as defined in IEEE 1363 [IEEE1363], and the message encoding method is EMSA4. EMSA4 is slightly more general than EMSA-PSS as it acts on bit strings rather than on octet strings. EMSA-PSS is equivalent to EMSA4 restricted to the case that the operands as well as the hash and salt values are octet strings. The length of messages on which RSASSA-PSS can operate is either unrestricted or constrained by a very large number, depending on the hash function underlying the EMSA-PSS encoding method. Assuming that computing e-th roots modulo n is infeasible and the hash and mask generation functions in EMSA-PSS have appropriate properties, RSASSA-PSS provides secure signatures. This assurance is provable in the sense that the difficulty of forging signatures can be directly related to the difficulty of inverting the RSA function, provided that the hash and mask generation functions are viewed as black boxes or random oracles. The bounds in the security proof are essentially "tight", meaning that the success probability and running time for the best forger against RSASSA-PSS are very close to the corresponding parameters for the best RSA inversion algorithm; see [RSARABIN] [PSSPROOF] [JONSSON] for further discussion. In contrast to the RSASSA-PKCS1-v1_5 signature scheme, a hash function identifier is not embedded in the EMSA-PSS encoded message, so in theory it is possible for an adversary to substitute a
Top   ToC   RFC8017 - Page 33
   different (and potentially weaker) hash function than the one
   selected by the signer.  Therefore, it is RECOMMENDED that the
   EMSA-PSS mask generation function be based on the same hash function.
   In this manner, the entire encoded message will be dependent on the
   hash function, and it will be difficult for an opponent to substitute
   a different hash function than the one intended by the signer.  This
   matching of hash functions is only for the purpose of preventing hash
   function substitution and is not necessary if hash function
   substitution is addressed by other means (e.g., the verifier accepts
   only a designated hash function).  See [HASHID] for further
   discussion of these points.  The provable security of RSASSA-PSS does
   not rely on the hash function in the mask generation function being
   the same as the hash function applied to the message.

   RSASSA-PSS is different from other RSA-based signature schemes in
   that it is probabilistic rather than deterministic, incorporating a
   randomly generated salt value.  The salt value enhances the security
   of the scheme by affording a "tighter" security proof than
   deterministic alternatives such as Full Domain Hashing (FDH); see
   [RSARABIN] for discussion.  However, the randomness is not critical
   to security.  In situations where random generation is not possible,
   a fixed value or a sequence number could be employed instead, with
   the resulting provable security similar to that of FDH [FDH].

8.1.1. Signature Generation Operation

RSASSA-PSS-SIGN (K, M) Input: K signer's RSA private key M message to be signed, an octet string Output: S signature, an octet string of length k, where k is the length in octets of the RSA modulus n Errors: "message too long;" "encoding error" Steps: 1. EMSA-PSS encoding: Apply the EMSA-PSS encoding operation (Section 9.1.1) to the message M to produce an encoded message EM of length \ceil ((modBits - 1)/8) octets such that the bit length of the integer OS2IP (EM) (see Section 4.2) is at most modBits - 1, where modBits is the length in bits of the RSA modulus n:
Top   ToC   RFC8017 - Page 34
             EM = EMSA-PSS-ENCODE (M, modBits - 1).

          Note that the octet length of EM will be one less than k if
          modBits - 1 is divisible by 8 and equal to k otherwise.  If
          the encoding operation outputs "message too long", output
          "message too long" and stop.  If the encoding operation
          outputs "encoding error", output "encoding error" and stop.

      2.  RSA signature:

          a.  Convert the encoded message EM to an integer message
              representative m (see Section 4.2):

                 m = OS2IP (EM).

          b.  Apply the RSASP1 signature primitive (Section 5.2.1) to
              the RSA private key K and the message representative m to
              produce an integer signature representative s:

                 s = RSASP1 (K, m).

          c.  Convert the signature representative s to a signature S of
              length k octets (see Section 4.1):

                 S = I2OSP (s, k).

      3.  Output the signature S.

8.1.2. Signature Verification Operation

RSASSA-PSS-VERIFY ((n, e), M, S) Input: (n, e) signer's RSA public key M message whose signature is to be verified, an octet string S signature to be verified, an octet string of length k, where k is the length in octets of the RSA modulus n Output: "valid signature" or "invalid signature" Steps: 1. Length checking: If the length of the signature S is not k octets, output "invalid signature" and stop.
Top   ToC   RFC8017 - Page 35
      2.  RSA verification:

          a.  Convert the signature S to an integer signature
              representative s (see Section 4.2):

                 s = OS2IP (S).

          b.  Apply the RSAVP1 verification primitive (Section 5.2.2) to
              the RSA public key (n, e) and the signature representative
              s to produce an integer message representative m:

                 m = RSAVP1 ((n, e), s).

              If RSAVP1 output "signature representative out of range",
              output "invalid signature" and stop.

          c.  Convert the message representative m to an encoded message
              EM of length emLen = \ceil ((modBits - 1)/8) octets, where
              modBits is the length in bits of the RSA modulus n (see
              Section 4.1):

                 EM = I2OSP (m, emLen).

              Note that emLen will be one less than k if modBits - 1 is
              divisible by 8 and equal to k otherwise.  If I2OSP outputs
              "integer too large", output "invalid signature" and stop.

      3.  EMSA-PSS verification: Apply the EMSA-PSS verification
          operation (Section 9.1.2) to the message M and the encoded
          message EM to determine whether they are consistent:

             Result = EMSA-PSS-VERIFY (M, EM, modBits - 1).

      4.  If Result = "consistent", output "valid signature".
          Otherwise, output "invalid signature".

8.2. RSASSA-PKCS1-v1_5

RSASSA-PKCS1-v1_5 combines the RSASP1 and RSAVP1 primitives with the EMSA-PKCS1-v1_5 encoding method. It is compatible with the IFSSA scheme defined in IEEE 1363 [IEEE1363], where the signature and verification primitives are IFSP-RSA1 and IFVP-RSA1, and the message encoding method is EMSA-PKCS1-v1_5 (which is not defined in IEEE 1363 but is in IEEE 1363a [IEEE1363A]). The length of messages on which RSASSA-PKCS1-v1_5 can operate is either unrestricted or constrained by a very large number, depending on the hash function underlying the EMSA-PKCS1-v1_5 method.
Top   ToC   RFC8017 - Page 36
   Assuming that computing e-th roots modulo n is infeasible and the
   hash function in EMSA-PKCS1-v1_5 has appropriate properties,
   RSASSA-PKCS1-v1_5 is conjectured to provide secure signatures.  More
   precisely, forging signatures without knowing the RSA private key is
   conjectured to be computationally infeasible.  Also, in the encoding
   method EMSA-PKCS1-v1_5, a hash function identifier is embedded in the
   encoding.  Because of this feature, an adversary trying to find a
   message with the same signature as a previously signed message must
   find collisions of the particular hash function being used; attacking
   a different hash function than the one selected by the signer is not
   useful to the adversary.  See [HASHID] for further discussion.

   Note: As noted in PKCS #1 v1.5, the EMSA-PKCS1-v1_5 encoding method
   has the property that the encoded message, converted to an integer
   message representative, is guaranteed to be large and at least
   somewhat "random".  This prevents attacks of the kind proposed by
   Desmedt and Odlyzko [CHOSEN] where multiplicative relationships
   between message representatives are developed by factoring the
   message representatives into a set of small values (e.g., a set of
   small primes).  Coron, Naccache, and Stern [PADDING] showed that a
   stronger form of this type of attack could be quite effective against
   some instances of the ISO/IEC 9796-2 signature scheme.  They also
   analyzed the complexity of this type of attack against the
   EMSA-PKCS1-v1_5 encoding method and concluded that an attack would be
   impractical, requiring more operations than a collision search on the
   underlying hash function (i.e., more than 2^80 operations).
   Coppersmith, Halevi, and Jutla [FORGERY] subsequently extended Coron
   et al.'s attack to break the ISO/IEC 9796-1 signature scheme with
   message recovery.  The various attacks illustrate the importance of
   carefully constructing the input to the RSA signature primitive,
   particularly in a signature scheme with message recovery.
   Accordingly, the EMSA-PKCS-v1_5 encoding method explicitly includes a
   hash operation and is not intended for signature schemes with message
   recovery.  Moreover, while no attack is known against the
   EMSA-PKCS-v1_5 encoding method, a gradual transition to EMSA-PSS is
   recommended as a precaution against future developments.

8.2.1. Signature Generation Operation

RSASSA-PKCS1-V1_5-SIGN (K, M) Input: K signer's RSA private key M message to be signed, an octet string
Top   ToC   RFC8017 - Page 37
   Output:

      S        signature, an octet string of length k, where k is the
               length in octets of the RSA modulus n

   Errors:  "message too long"; "RSA modulus too short"

   Steps:

      1.  EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
          operation (Section 9.2) to the message M to produce an encoded
          message EM of length k octets:

             EM = EMSA-PKCS1-V1_5-ENCODE (M, k).

          If the encoding operation outputs "message too long", output
          "message too long" and stop.  If the encoding operation
          outputs "intended encoded message length too short", output
          "RSA modulus too short" and stop.

      2.  RSA signature:

          a.  Convert the encoded message EM to an integer message
              representative m (see Section 4.2):

                 m = OS2IP (EM).

          b.  Apply the RSASP1 signature primitive (Section 5.2.1) to
              the RSA private key K and the message representative m to
              produce an integer signature representative s:

                 s = RSASP1 (K, m).

          c.  Convert the signature representative s to a signature S of
              length k octets (see Section 4.1):

                 S = I2OSP (s, k).

      3.  Output the signature S.

8.2.2. Signature Verification Operation

RSASSA-PKCS1-V1_5-VERIFY ((n, e), M, S) Input: (n, e) signer's RSA public key M message whose signature is to be verified, an octet string
Top   ToC   RFC8017 - Page 38
      S       signature to be verified, an octet string of length k,
              where k is the length in octets of the RSA modulus n

   Output  "valid signature" or "invalid signature"

   Errors:  "message too long"; "RSA modulus too short"

   Steps:

      1.  Length checking: If the length of the signature S is not k
          octets, output "invalid signature" and stop.

      2.  RSA verification:

          a.  Convert the signature S to an integer signature
              representative s (see Section 4.2):

                 s = OS2IP (S).

          b.  Apply the RSAVP1 verification primitive (Section 5.2.2) to
              the RSA public key (n, e) and the signature representative
              s to produce an integer message representative m:

                 m = RSAVP1 ((n, e), s).

              If RSAVP1 outputs "signature representative out of range",
              output "invalid signature" and stop.

          c.  Convert the message representative m to an encoded message
              EM of length k octets (see Section 4.1):

                 EM = I2OSP (m, k).

              If I2OSP outputs "integer too large", output "invalid
              signature" and stop.

      3.  EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
          operation (Section 9.2) to the message M to produce a second
          encoded message EM' of length k octets:

             EM' = EMSA-PKCS1-V1_5-ENCODE (M, k).

          If the encoding operation outputs "message too long", output
          "message too long" and stop.  If the encoding operation
          outputs "intended encoded message length too short", output
          "RSA modulus too short" and stop.
Top   ToC   RFC8017 - Page 39
      4.  Compare the encoded message EM and the second encoded message
          EM'.  If they are the same, output "valid signature";
          otherwise, output "invalid signature".

      Note: Another way to implement the signature verification
      operation is to apply a "decoding" operation (not specified in
      this document) to the encoded message to recover the underlying
      hash value, and then compare it to a newly computed hash value.
      This has the advantage that it requires less intermediate storage
      (two hash values rather than two encoded messages), but the
      disadvantage that it requires additional code.



(page 39 continued on part 3)

Next Section