RFC 8017

PKCS #1: RSA Cryptography Specifications Version 2.2

๐Ÿ“… published November 2016, from ietf

1. Introduction โœจ

PKCS #1: RSA Cryptography Specifications Version 2.2 ๐ŸŽ€ is RFC 8017, published in November 2016 ๐Ÿ“… by K. Moriarty, Ed. (EMC Corporation), B. Kaliski (Verisign), J. Jonsson (Subset AB), and A. Rusch (RSA). It's Informational, so it's published for information rather than as a Standards Track spec ๐Ÿงš and it OBSOLETES RFC 3447 (the old one). Its ISSN is 2070-1721 ๐Ÿ’œ.

Abstract ๐ŸŒธ

This doc gives recommendations for implementing public-key cryptography based on the RSA algorithm ๐Ÿ”. It covers cryptographic primitives, encryption schemes, signature schemes with appendix, and ASN.1 syntax for representing keys and identifying the schemes ๐Ÿ’….

This doc is a republication of PKCS #1 v2.2 from RSA Laboratories' Public-Key Cryptography Standards (PKCS) series ๐Ÿ“š. By publishing this RFC, change control is transferred to the IETF ๐Ÿซถ.

This doc also obsoletes RFC 3447 ๐Ÿ™ˆ.

Status of This Memo ๐Ÿฆ‹

This doc is not an Internet Standards Track specification. It's published for informational purposes โœจ.

This doc is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community and has received public review, and it was approved for publication by the Internet Engineering Steering Group (IESG) ๐Ÿ‘‘. Not every IESG-approved doc is a candidate for any level of Internet Standard, so see Section 2 of RFC 7841 for that ๐Ÿ’€.

For info about the current status of this doc, any errata, and how to give feedback on it, go to http://www.rfc-editor.org/info/rfc8017 ๐Ÿ“.

Copyright (c) 2016 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) in effect on the date of publication of this document. Please read these carefully, because they describe your rights and restrictions with respect to this doc ๐Ÿ“œ. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they're provided without warranty as described in the Simplified BSD License ๐Ÿงก.

Table of Contents ๐Ÿ—บ๏ธ

1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   4
  1.1.  Requirements Language . . . . . . . . . . . . . . . . . .   5
2.  Notation  . . . . . . . . . . . . . . . . . . . . . . . . . .   6
3.  Key Types . . . . . . . . . . . . . . . . . . . . . . . . . .   8
  3.1.  RSA Public Key  . . . . . . . . . . . . . . . . . . . . .   8
  3.2.  RSA Private Key . . . . . . . . . . . . . . . . . . . . .   9
4.  Data Conversion Primitives  . . . . . . . . . . . . . . . . .  11
  4.1.  I2OSP . . . . . . . . . . . . . . . . . . . . . . . . . .  11
  4.2.  OS2IP . . . . . . . . . . . . . . . . . . . . . . . . . .  12
5.  Cryptographic Primitives  . . . . . . . . . . . . . . . . . .  12
  5.1.  Encryption and Decryption Primitives  . . . . . . . . . .  12
    5.1.1.  RSAEP . . . . . . . . . . . . . . . . . . . . . . . .  13
    5.1.2.  RSADP . . . . . . . . . . . . . . . . . . . . . . . .  13
  5.2.  Signature and Verification Primitives . . . . . . . . . .  15
    5.2.1.  RSASP1  . . . . . . . . . . . . . . . . . . . . . . .  15
    5.2.2.  RSAVP1  . . . . . . . . . . . . . . . . . . . . . . .  16
6.  Overview of Schemes . . . . . . . . . . . . . . . . . . . . .  17
7.  Encryption Schemes  . . . . . . . . . . . . . . . . . . . . .  18
  7.1.  RSAES-OAEP  . . . . . . . . . . . . . . . . . . . . . . .  19
    7.1.1.  Encryption Operation  . . . . . . . . . . . . . . . .  22
    7.1.2.  Decryption Operation  . . . . . . . . . . . . . . . .  25
  7.2.  RSAES-PKCS1-v1_5  . . . . . . . . . . . . . . . . . . . .  27
    7.2.1.  Encryption Operation  . . . . . . . . . . . . . . . .  28
    7.2.2.  Decryption Operation  . . . . . . . . . . . . . . . .  29
8.  Signature Scheme with Appendix  . . . . . . . . . . . . . . .  31
  8.1.  RSASSA-PSS  . . . . . . . . . . . . . . . . . . . . . . .  32
    8.1.1.  Signature Generation Operation  . . . . . . . . . . .  33
    8.1.2.  Signature Verification Operation  . . . . . . . . . .  34
  8.2.  RSASSA-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . . .  35
    8.2.1.  Signature Generation Operation  . . . . . . . . . . .  36
    8.2.2.  Signature Verification Operation  . . . . . . . . . .  37
9.  Encoding Methods for Signatures with Appendix . . . . . . . .  39
  9.1.  EMSA-PSS  . . . . . . . . . . . . . . . . . . . . . . . .  40
    9.1.1.  Encoding Operation  . . . . . . . . . . . . . . . . .  42
    9.1.2.  Verification Operation  . . . . . . . . . . . . . . .  44
  9.2.  EMSA-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . . . .  45
10. Security Considerations . . . . . . . . . . . . . . . . . . .  47
11. References  . . . . . . . . . . . . . . . . . . . . . . . . .  48
  11.1.  Normative References . . . . . . . . . . . . . . . . . .  48
  11.2.  Informative References . . . . . . . . . . . . . . . . .  48

Appendix A.  ASN.1 Syntax . . . . . . . . . . . . . . . . . . . .  54
  A.1.  RSA Key Representation  . . . . . . . . . . . . . . . . .  54
    A.1.1.  RSA Public Key Syntax . . . . . . . . . . . . . . . .  54
    A.1.2.  RSA Private Key Syntax  . . . . . . . . . . . . . . .  55
  A.2.  Scheme Identification . . . . . . . . . . . . . . . . . .  57
    A.2.1.  RSAES-OAEP  . . . . . . . . . . . . . . . . . . . . .  57
    A.2.2.  RSAES-PKCS-v1_5 . . . . . . . . . . . . . . . . . . .  60
    A.2.3.  RSASSA-PSS  . . . . . . . . . . . . . . . . . . . . .  60
    A.2.4.  RSASSA-PKCS-v1_5  . . . . . . . . . . . . . . . . . .  62
Appendix B.  Supporting Techniques  . . . . . . . . . . . . . . .  63
  B.1.  Hash Functions  . . . . . . . . . . . . . . . . . . . . .  63
  B.2.  Mask Generation Functions . . . . . . . . . . . . . . . .  66
    B.2.1.  MGF1  . . . . . . . . . . . . . . . . . . . . . . . .  67
Appendix C.  ASN.1 Module . . . . . . . . . . . . . . . . . . . .  68
Appendix D.  Revision History of PKCS #1  . . . . . . . . . . . .  76
Appendix E.  About PKCS . . . . . . . . . . . . . . . . . . . . .  77
Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . .  78
Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  78

1. Introduction ๐Ÿ’ซ

This doc gives recommendations for implementing public-key cryptography based on the RSA algorithm [RSA]. It covers:

  • Cryptographic primitives ๐Ÿ”ข
  • Encryption schemes ๐Ÿ”’
  • Signature schemes with appendix โœ๏ธ
  • ASN.1 syntax for representing keys and for identifying the schemes ๐Ÿงฉ

These recommendations are meant for general use in computer and communications systems, so they include a fair amount of flexibility ๐Ÿฆ‹. Application standards based on these specs are expected to add extra constraints, and they may include additional constraints ๐ŸŽ€. The recommendations are meant to be compatible with IEEE 1363 [IEEE1363], IEEE 1363a [IEEE1363A], and ANSI X9.44 [ANSIX944] ๐ŸŒˆ.

This doc supersedes PKCS #1 version 2.1 [RFC3447] but keeps compatible techniques ๐Ÿ™Œ.

Here's how the doc is laid out ๐Ÿ—บ๏ธ:

  • Section 1 is the intro ๐ŸŒธ.
  • Section 2 defines some notation used in this doc ๐Ÿ“.
  • Section 3 defines the RSA public and private key types ๐Ÿ”‘.
  • Sections 4 and 5 define several primitives, which are basic mathematical operations ๐Ÿงฎ. Data conversion primitives are in Section 4, and cryptographic primitives (encryption-decryption and signature-verification) are in Section 5.
  • Sections 6, 7, and 8 deal with the encryption and signature schemes in this doc ๐Ÿ’…. Section 6 gives an overview. Along with the methods found in PKCS #1 v1.5, Section 7 defines an encryption scheme based on Optimal Asymmetric Encryption Padding (OAEP) [OAEP], and Section 8 defines a signature scheme with appendix based on the Probabilistic Signature Scheme (PSS) [RSARABIN] [PSS] ๐Ÿซง.
  • Section 9 defines the encoding methods for the signature schemes in Section 8 ๐ŸŽ.
  • Appendix A defines the ASN.1 syntax for the keys defined in Section 3 and the schemes in Sections 7 and 8 ๐Ÿงš.
  • Appendix B defines the hash functions and the mask generation function (MGF) used in this doc, including ASN.1 syntax for the techniques ๐Ÿ“.
  • Appendix C gives an ASN.1 module ๐Ÿ’œ.
  • Appendices D and E outline the revision history of PKCS #1 and give general info about the Public-Key Cryptography Standards ๐Ÿ“š.

This doc is a republication of PKCS #1 v2.2 [PKCS1_22] from RSA Laboratories' Public-Key Cryptography Standards (PKCS) series โœจ.

1.1. Requirements Language ๐Ÿซถ

Okay so the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this doc are to be interpreted as described in [RFC2119] ๐Ÿ”ฅ.

Part 1 of 15 is done, and part 2 is next ๐Ÿงšโœจ

2. Notation โœจ

okay so this section is basically the cheat sheet for the whole doc ๐Ÿงš every letter and symbol we're gonna use later gets defined here, so bookmark it bestie ๐Ÿ”–

c              ciphertext representative, an integer between 0 and
               n-1

C              ciphertext, an octet string

d              RSA private exponent

d_i            additional factor r_i's CRT exponent,
               a positive integer such that

                 e * d_i == 1 (mod (r_i-1)), i = 3, ..., u

dP             p's CRT exponent, a positive integer such that

                 e * dP == 1 (mod (p-1))

dQ             q's CRT exponent, a positive integer such that

                 e * dQ == 1 (mod (q-1))

e              RSA public exponent

EM             encoded message, an octet string

emBits         (intended) length in bits of an encoded message EM

emLen          (intended) length in octets of an encoded message
               EM

GCD(. , .)     greatest common divisor of two nonnegative integers

Hash           hash function

hLen           output length in octets of hash function Hash

k              length in octets of the RSA modulus n

K              RSA private key

L              optional RSAES-OAEP label, an octet string

LCM(., ..., .) least common multiple of a list of nonnegative
               integers

m              message representative, an integer between 0 and
               n-1

M              message, an octet string

mask           MGF output, an octet string

maskLen        (intended) length of the octet string mask

MGF            mask generation function

mgfSeed        seed from which mask is generated, an octet string

mLen           length in octets of a message M

n              RSA modulus, n = r_1 * r_2 * ... * r_u , u >= 2

(n, e)         RSA public key

p, q           first two prime factors of the RSA modulus n

qInv           CRT coefficient, a positive integer less than
               p such that q * qInv == 1 (mod p)

r_i            prime factors of the RSA modulus n, including
               r_1 = p, r_2 = q, and additional factors if any

s              signature representative, an integer between 0 and
               n-1

S              signature, an octet string

sLen           length in octets of the EMSA-PSS salt

t_i            additional prime factor r_i's CRT coefficient, a
               positive integer less than r_i such that

                 r_1 * r_2 * ... * r_(i-1) * t_i == 1 (mod r_i) ,

               i = 3, ... , u

u              number of prime factors of the RSA modulus, u >= 2

x              a nonnegative integer

X              an octet string corresponding to x

xLen           (intended) length of the octet string X
0x             indicator of hexadecimal representation of an octet
               or an octet string: "0x48" denotes the octet with
               hexadecimal value 48; "(0x)48 09 0e" denotes the
               string of three consecutive octets with hexadecimal
               values 48, 09, and 0e, respectively

\lambda(n)     LCM(r_1-1, r_2-1, ... , r_u-1)

\xor           bit-wise exclusive-or of two octet strings

\ceil(.)       ceiling function; \ceil(x) is the smallest integer
               larger than or equal to the real number x

||             concatenation operator

==             congruence symbol; a == b (mod n) means that the
               integer n divides the integer a - b
Note: The Chinese Remainder Theorem (CRT) can be applied in a non-recursive as well as a recursive way. In this document, we go with the recursive approach following Garner's algorithm [GARNER]. See also Note 1 in Section 3.2. ๐Ÿง ๐Ÿ’•

3. Key Types ๐Ÿ”‘

okay so there are two key types in this doc: the RSA public key and the RSA private key. Put them together and you get an RSA key pair, which is giving matching set ๐Ÿ‘ฏโ€โ™€๏ธ

This spec supports so-called "multi-prime" RSA, where the modulus can have more than two prime factors. The perk of multi-prime RSA is lower computational cost for the decryption and signature primitives, as long as the CRT is used ๐Ÿš€ Performance is better on single-processor platforms, but the gains are even bigger on multiprocessor platforms, because the modular exponentiations involved can run in parallel. iconic ๐Ÿ’…

If you want the tea on how multi-prime affects the security of the RSA cryptosystem, go read [SILVERMAN] ๐Ÿ“š

3.1. RSA Public Key ๐ŸŒธ

For this document, an RSA public key has two components:

n        the RSA modulus, a positive integer
e        the RSA public exponent, a positive integer

In a valid RSA public key, the RSA modulus n is a product of u distinct odd primes r_i, i = 1, 2, ..., u, where u >= 2. The RSA public exponent e is an integer between 3 and n - 1 that satisfies GCD(e,\lambda(n)) = 1, where \lambda(n) = LCM(r_1 - 1, ..., r_u - 1). By convention, the first two primes r_1 and r_2 may also be written as p and q, respectively. ๐ŸŽ€

A recommended syntax for swapping RSA public keys between implementations is given in Appendix A.1.1. An implementation's internal representation is allowed to be different, so don't stress ๐Ÿซถ

3.2. RSA Private Key ๐Ÿ”

For this document, an RSA private key can come in either of two representations. Let's go ๐Ÿ‘€

  1. The first representation is the pair (n, d), where the components mean the following:
n       the RSA modulus, a positive integer
d       the RSA private exponent, a positive integer
  1. The second representation is a quintuple (p, q, dP, dQ, qInv) plus a (possibly empty) sequence of triplets (r_i, d_i, t_i), i = 3, ..., u, one for each prime that isn't in the quintuple. The components mean the following:
p      the first factor, a positive integer
q      the second factor, a positive integer
dP     the first factor's CRT exponent, a positive integer
dQ     the second factor's CRT exponent, a positive integer
qInv   the (first) CRT coefficient, a positive integer
r_i    the i-th factor, a positive integer
d_i    the i-th factor's CRT exponent, a positive integer
t_i    the i-th factor's CRT coefficient, a positive integer

In a valid RSA private key with the first representation, the RSA modulus n is the same as in the matching RSA public key, and it's a product of u distinct odd primes r_i, i = 1, 2, ..., u, where u >= 2. The RSA private exponent d is a positive integer less than n that satisfies:

e * d == 1 (mod \lambda(n))

Here e is the matching RSA public exponent, and \lambda(n) is defined the same way as in Section 3.1. โœจ

In a valid RSA private key with the second representation, the two factors p and q are the first two prime factors of the RSA modulus n (that's r_1 and r_2). The CRT exponents dP and dQ are positive integers less than p and q, respectively, and they satisfy:

e * dP == 1 (mod (p-1))

e * dQ == 1 (mod (q-1))

The CRT coefficient qInv is a positive integer less than p that satisfies:

q * qInv == 1 (mod p)

If u > 2, the representation includes one or more triplets (r_i, d_i, t_i), i = 3, ..., u. The factors r_i are the additional prime factors of the RSA modulus n. Each CRT exponent d_i (i = 3, ..., u) satisfies:

e * d_i == 1 (mod (r_i - 1))

Each CRT coefficient t_i (i = 3, ..., u) is a positive integer less than r_i that satisfies:

R_i * t_i == 1 (mod r_i)

where R_i = r_1 * r_2 * ... * r_(i-1). ๐Ÿงฉ

A recommended syntax for swapping RSA private keys between implementations is given in Appendix A.1.2. It mixes components from both representations, and an implementation's internal representation is allowed to differ. ๐Ÿซง

Notes: 1. The definition of the CRT coefficients here, and the formulas that use them in the primitives in Section 5, generally follow Garner's algorithm [GARNER] (see also Algorithm 14.71 in [HANDBOOK]). However, for compatibility with the representations of RSA private keys in PKCS #1 v2.0 and earlier versions, the roles of p and q are reversed compared to the rest of the primes. So the first CRT coefficient, qInv, is defined as the inverse of q mod p, instead of as the inverse of R_1 mod r_2, i.e., of p mod q. Plot twist ๐ŸŒ€ 2. Quisquater and Couvreur [FASTDEC] noticed the benefit of applying the CRT to RSA operations. Big brain energy ๐Ÿง โœจ

4. Data Conversion Primitives ๐ŸŽ€

Two data conversion primitives show up in the schemes in this document:

  • I2OSP - Integer-to-Octet-String primitive
  • OS2IP - Octet-String-to-Integer primitive

For this document, and consistent with ASN.1 syntax, an octet string is an ordered sequence of octets (eight-bit bytes). The sequence is indexed from first (conventionally, leftmost) to last (rightmost). For conversions to and from integers, the first octet counts as the most significant one in these conversion primitives. ๐Ÿ“

4.1. I2OSP ๐Ÿ”ขโžก๏ธ๐Ÿงต

I2OSP converts a nonnegative integer into an octet string of a specified length. Here's the whole recipe:

I2OSP (x, xLen)

Input:

   x        nonnegative integer to be converted

   xLen     intended length of the resulting octet string

Output:

      X corresponding octet string of length xLen

Error:  "integer too large"

Steps:

   1.  If x >= 256^xLen, output "integer too large" and stop.

   2.  Write the integer x in its unique xLen-digit representation in
       base 256:

          x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) + ...
          + x_1 256 + x_0,

       where 0 <= x_i < 256 (note that one or more leading digits
       will be zero if x is less than 256^(xLen-1)).

   3.  Let the octet X_i have the integer value x_(xLen-i) for 1 <= i
       <= xLen.  Output the octet string

          X = X_1 X_2 ... X_xLen.

4.2. OS2IP ๐Ÿงตโžก๏ธ๐Ÿ”ข

OS2IP converts an octet string into a nonnegative integer. The recipe is:

OS2IP (X)

Input:  X octet string to be converted

Output:  x corresponding nonnegative integer

Steps:

   1.  Let X_1 X_2 ... X_xLen be the octets of X from first to last,
       and let x_(xLen-i) be the integer value of the octet X_i for 1
       <= i <= xLen.

   2.  Let x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) +
       ...  + x_1 256 + x_0.

   3.  Output x.

5. Cryptographic Primitives ๐Ÿ’œ

Cryptographic primitives are the basic math operations that cryptographic schemes get built on. They're meant to be implemented in hardware or as software modules, and they are not meant to provide security on their own, apart from a scheme. So they're the building blocks, not the whole outfit ๐Ÿงฑ๐Ÿ’–

This document specifies four types of primitive, organized in pairs: encryption and decryption, and signature and verification. ๐Ÿฆ‹

The specifications of the primitives assume the inputs meet certain conditions, in particular that the RSA public and private keys are valid. So always check your keys first, bestie ๐Ÿ”‘โœ…

5.1. Encryption and Decryption Primitives ๐Ÿ”

okay so an encryption primitive takes a message representative and turns it into a ciphertext representative using a public key ๐Ÿ’Œ. The decryption primitive does the reverse: it gets the message representative back from the ciphertext representative using the matching private key ๐Ÿ—๏ธโœจ

We only need one encryption and decryption pair for the encryption schemes in this doc, and it's specified right here: RSA Encryption Primitive (RSAEP) / RSA Decryption Primitive (RSADP) ๐ŸŽ€ RSAEP and RSADP do the same math, they just take different keys as input ๐Ÿ’… These primitives match Integer Factorization Encryption Primitive using RSA (IFEP-RSA) / Integer Factorization Decryption Primitive using RSA (IFDP-RSA) from IEEE 1363 [IEEE1363], with one upgrade: multi-prime RSA support got added ๐ŸŒˆ They're also compatible with PKCS #1 v1.5 ๐Ÿซถ

The main operation in each primitive is exponentiation ๐Ÿฆ‹

5.1.1. RSAEP ๐Ÿ’–

RSAEP ((n, e), m)

Input:

  • (n, e) RSA public key
  • m message representative, an integer between 0 and n - 1

Output: c ciphertext representative, an integer between 0 and n - 1

Error: "message representative out of range"

Assumption: RSA public key (n, e) is valid

Steps:

  1. If the message representative m is not between 0 and n - 1, output "message representative out of range" and stop.
  2. Let c = m^e mod n.
  3. Output c.

5.1.2. RSADP ๐ŸŒธ

RSADP (K, c)

Input:

  • K RSA private key, where K has one of the following forms:
    • a pair (n, d)
    • a quintuple (p, q, dP, dQ, qInv) and a possibly empty sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
  • c ciphertext representative, an integer between 0 and n - 1

Output: m message representative, an integer between 0 and n - 1

Error: "ciphertext representative out of range"

Assumption: RSA private key K is valid

Steps:

  1. If the ciphertext representative c is not between 0 and n - 1, output "ciphertext representative out of range" and stop.
  2. The message representative m is computed as follows.
    • a. If the first form (n, d) of K is used, let m = c^d mod n.
    • b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i) of K is used, proceed as follows:
      • i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.
      • ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.
      • iii. Let h = (m_1 - m_2) * qInv mod p.
      • iv. Let m = m_2 + q * h.
      • v. If u > 2, let R = r_1 and for i = 3 to u do:
        1. Let R = R * r_(i-1).
        2. Let h = (m_i - m) * t_i mod r_i.
        3. Let m = m + R * h.
  3. Output m.
Note: Step 2.b can be rewritten as a single loop, provided that one reverses the order of p and q. For consistency with PKCS #1 v2.0, however, the first two primes p and q are treated separately from the additional primes. ๐Ÿ™ˆ

5.2. Signature and Verification Primitives โœ๏ธ

A signature primitive takes a message representative and makes a signature representative under a private key ๐Ÿ–‹๏ธ and a verification primitive gets the message representative back out of that signature representative using the matching public key ๐Ÿ’œ We only need one signature and verification pair for the signature schemes in this doc, and it's RSA Signature Primitive, version 1 (RSASP1) / RSA Verification Primitive, version 1 (RSAVP1) โญ

These match Integer Factorization Signature Primitive using RSA, version 1 (IFSP-RSA1) / Integer Factorization Verification Primitive using RSA, version 1 (IFVP-RSA1) in IEEE 1363 [IEEE1363]. Again, multi-prime RSA support was added ๐Ÿฆ‹ and they're compatible with PKCS #1 v1.5 ๐ŸŽ€

The main operation in each one is exponentiation, same as the encryption and decryption primitives in Section 5.1. RSASP1 and RSAVP1 are literally the same as RSADP and RSAEP except for the names of their input and output arguments ๐Ÿ™ƒ They're kept separate because they're meant for different jobs ๐Ÿ’…

5.2.1. RSASP1 ๐ŸŒˆ

RSASP1 (K, m)

Input:

  • K RSA private key, where K has one of the following forms:
    • a pair (n, d)
    • a quintuple (p, q, dP, dQ, qInv) and a (possibly empty) sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
  • m message representative, an integer between 0 and n - 1

Output:

  • s signature representative, an integer between 0 and n - 1

Error: "message representative out of range"

Assumption: RSA private key K is valid

Steps:

  1. If the message representative m is not between 0 and n - 1, output "message representative out of range" and stop.
  2. The signature representative s is computed as follows.
    • a. If the first form (n, d) of K is used, let s = m^d mod n.
    • b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i) of K is used, proceed as follows:
      1. Let s_1 = m^dP mod p and s_2 = m^dQ mod q.
      2. If u > 2, let s_i = m^(d_i) mod r_i, i = 3, ..., u.
      3. Let h = (s_1 - s_2) * qInv mod p.
      4. Let s = s_2 + q * h.
      5. If u > 2, let R = r_1 and for i = 3 to u do:
        • a. Let R = R * r_(i-1).
        • b. Let h = (s_i - s) * t_i mod r_i.
        • c. Let s = s + R * h.
  3. Output s.
Note: Step 2.b can be rewritten as a single loop, provided that one reverses the order of p and q. For consistency with PKCS #1 v2.0, however, the first two primes p and q are treated separately from the additional primes. ๐ŸŒธ

5.2.2. RSAVP1 ๐Ÿงš

RSAVP1 ((n, e), s)

Input:

  • (n, e) RSA public key
  • s signature representative, an integer between 0 and n - 1

Output:

  • m message representative, an integer between 0 and n - 1

Error: "signature representative out of range"

Assumption: RSA public key (n, e) is valid

Steps:

  1. If the signature representative s is not between 0 and n - 1, output "signature representative out of range" and stop.
  2. Let m = s^e mod n.
  3. Output m.

6. Overview of Schemes ๐Ÿ—บ๏ธ

okay so a scheme is when you combine cryptographic primitives and other techniques to hit a specific security goal ๐ŸŽฏ This doc specifies two kinds: encryption schemes and signature schemes with appendix โœจ

The schemes here are pretty limited in scope ๐Ÿ™ˆ Their operations only process data with an RSA public or private key, and they don't cover getting or validating the key. So an application will usually also handle key management, which is how parties pick RSA public and private keys for a scheme operation. Those extra operations and details are outside this doc's scope ๐Ÿ’…

Like with the primitives in Section 5, the scheme specs assume the inputs meet certain conditions, especially that RSA public and private keys are valid. So the behavior of an implementation is unspecified when a key is invalid, and the impact of that depends on the application ๐Ÿ˜ญ Ways to deal with key validation include explicit key validation by the application, key validation within the public-key infrastructure, and assigning liability for operations done with an invalid key to whoever generated the key ๐Ÿ”‘

Generally, good crypto practice is to use a given RSA key pair in only one scheme ๐Ÿซถ That way, a weakness in one scheme can't compromise the other, and it may be essential for provable security. RSAES-PKCS1-v1_5 (Section 7.2) and RSASSA-PKCS1-v1_5 (Section 8.2) have traditionally been used together with no known bad interactions (this is literally the model PKCS #1 v1.5 introduced!), but using one RSA key pair that way is NOT RECOMMENDED for new applications ๐Ÿ’€

Here's why the risk is real. Say an RSA key pair is used in both RSAES-OAEP (Section 7.1) and RSAES-PKCS1-v1_5. RSAES-OAEP would resist attack on its own, but an opponent might exploit a weakness in the implementation of RSAES-PKCS1-v1_5 to recover messages encrypted with either scheme ๐Ÿ˜ฑ Another example: say an RSA key pair is used in both RSASSA-PSS (Section 8.1) and RSASSA-PKCS1-v1_5. Then the security proof for RSASSA-PSS no longer holds, since the proof doesn't account for signatures possibly being generated with a second scheme ๐Ÿšจ Similar concerns may apply if an RSA key pair is used in one of the schemes defined here and in a variant defined elsewhere ๐ŸŒˆ

7. Encryption Schemes ๐ŸŽ€

For this doc, an encryption scheme is an encryption operation plus a decryption operation ๐Ÿ’Œ The encryption operation makes a ciphertext from a message using a recipient's RSA public key, and the decryption operation recovers the message from that ciphertext using the recipient's matching RSA private key ๐Ÿ”

Encryption schemes show up in all kinds of applications ๐Ÿง A typical one is a key establishment protocol, where the message carries key material that gets delivered confidentially from one party to another. For example, PKCS #7 [RFC2315] uses a protocol like this to deliver a content-encryption key from a sender to a recipient, and the encryption schemes here would be suitable key-encryption algorithms in that context ๐Ÿ—๏ธ

Two encryption schemes are specified in this doc: RSAES-OAEP and RSAES-PKCS1-v1_5. RSAES-OAEP is REQUIRED to be supported for new applications ๐Ÿ† RSAES-PKCS1-v1_5 is only included for compatibility with existing applications ๐Ÿ•ฐ๏ธ

The encryption schemes here follow a general model similar to the one used in IEEE 1363 [IEEE1363]: they combine 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 then gets converted to an integer message representative. An encryption primitive is applied to that message representative to produce the ciphertext. In reverse, the decryption operations apply a decryption primitive to the ciphertext to recover a message representative, which then gets converted to an octet-string-encoded message. A message decoding operation is applied to the encoded message to recover the message and verify the decryption was correct ๐Ÿ’–

To avoid implementation weaknesses tied to how errors get handled inside the decoding operation (see [BLEICHENBACHER] and [MANGER]), the encoding and decoding operations for RSAES-OAEP and RSAES-PKCS1-v1_5 are embedded in the specs of their respective encryption schemes, instead of being defined in separate specifications ๐Ÿ™Œ Both encryption schemes are compatible with the corresponding schemes in PKCS #1 v2.1 ๐Ÿซถ

7.1. RSAES-OAEP โœจ

okay bestie, RSAES-OAEP is the RSA encryption scheme that really gives me life ๐Ÿ’– It 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's 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 handle messages up to k - 2hLen -2 octets long, 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 ๐ŸŽ€

the security vibes are immaculate too ๐Ÿฆ‹ 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, meaning the difficulty of breaking RSAES-OAEP can be directly related to the difficulty of inverting the RSA function, as long as the mask generation function is viewed as a black box or random oracle. see [FOPS] and the note below for the full tea โ˜•

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, and 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 ๐Ÿ’…

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 backstory is kinda wild ๐Ÿ˜ญ 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 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). the plot twist of the century ๐Ÿ‘‘

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 ๐Ÿงš


7.1.1. Encryption Operation

Here's the function signature for the encryption operation:

RSAES-OAEP-ENCRYPT ((n, e), M, L)

Options:

  • Hash: the hash function (hLen denotes the length in octets of the hash function output)
  • MGF: the mask generation function

Input:

  • (n, e): the recipient's RSA public key (k denotes the length in octets of the RSA modulus n)
  • M: the message to be encrypted, an octet string of length mLen, where mLen <= k - 2hLen - 2
  • L: an optional label to be associated with the message; the default value for L, if L is not provided, is the empty string

Output:

  • C: the ciphertext, an octet string of length k ๐ŸŽ€

Errors: "message too long"; "label too long" ๐Ÿ™ˆ

Assumption: the 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.
    • 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
  1. 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)
  1. Output the ciphertext C.

Here's the diagram of how the EME-OAEP encoding fits together ๐Ÿฆ‹

                          +----------+------+--+-------+
                     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

7.1.2. Decryption Operation ๐Ÿ”“โœจ

Okay bestie, time to undo all that wrapping ๐Ÿ”“. This is where the recipient uses their private key to get the message back out. Here's the setup:

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"

Now the steps, and they're giving careful checkpoints ๐Ÿง:

  1. Length checking ๐Ÿ“:
    • a. If L is longer than the input limit for the hash function (2^61 - 1 octets for SHA-1), output "decryption error" and stop.
    • b. If the ciphertext C isn't exactly k octets, output "decryption error" and stop.
    • c. If k < 2hLen + 2, output "decryption error" and stop.
  2. RSA decryption ๐Ÿ”:
    • a. Turn the ciphertext C into an integer, the ciphertext representative c (see Section 4.2):
c = OS2IP (C).
  • b. Run the RSADP decryption primitive (Section 5.1.2) with the private key K and c to get the integer message representative m:
m = RSADP (K, c).

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

  • c. Turn m back into an encoded message EM of k octets (see Section 4.1):
EM = I2OSP (m, k).
  1. EME-OAEP decoding ๐Ÿงฉ:
    • a. If L isn't provided, let L be the empty string. Then compute lHash = Hash(L), an octet string of hLen octets (see the note in Section 7.1.1).
    • b. Split the encoded message EM into a single octet Y, an octet string maskedSeed of hLen octets, and an octet string maskedDB of k - hLen - 1 octets:
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. Split DB into an octet string lHash' of hLen octets, a (possibly empty) padding string PS made of octets with hexadecimal value 0x00, and a message M:
DB = lHash' || PS || 0x01 || M.

If there's no octet with hexadecimal value 0x01 to separate PS from M, if lHash doesn't equal lHash', or if Y is nonzero, output "decryption error" and stop. (See the note below.)

  1. Output the message M ๐Ÿ“ค๐Ÿ’–.
Heads up, bestie ๐Ÿšจ: care must be taken to make sure an opponent can't tell apart the different error conditions in Step 3.g, whether by error message or by timing. More generally, an opponent must not be able to learn partial information about the encoded message EM. Otherwise, an opponent may be able to get useful information about the decryption of the ciphertext C, which could lead to a chosen-ciphertext attack like the one Manger observed [MANGER].

7.2. RSAES-PKCS1-v1_5

RSAES-PKCS1-v1_5 mixes 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's mathematically equivalent to the encryption scheme in PKCS #1 v1.5. It can handle messages up to k - 11 octets long (k is the octet length of the RSA modulus), but 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, using this scheme to encrypt an arbitrary message, as opposed to a randomly generated key, is NOT RECOMMENDED ๐Ÿ™…โ€โ™€๏ธ.

It's possible to make valid RSAES-PKCS1-v1_5 ciphertexts without knowing the plaintexts, with a reasonable chance of success. That ability can be exploited in a chosen-ciphertext attack, as shown in [BLEICHENBACHER] ๐Ÿ˜ฌ. So if RSAES-PKCS1-v1_5 is going to be used, certain easy-to-implement countermeasures should be taken to stop the attack found in [BLEICHENBACHER]. Typical examples include adding structure to the data being encoded, strictly checking PKCS #1 v1.5 conformance (and other redundancy) in decrypted messages, and consolidating error messages in a client-server protocol based on PKCS #1 v1.5. These can all be effective countermeasures, and none of them involve changes to a protocol based on PKCS #1 v1.5. See [BKS] for more on 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 for using RSAES-PKCS1-v1_5. Recommendations from PKCS #1 v1.5 are included, along with new recommendations motivated by cryptanalytic advances made in the years since.

  • 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 ๐ŸŒธ.
  • The padding string PS in Step 2 in Section 7.2.1 is at least eight octets long. That's a security condition for public-key operations, and it makes it hard for an attacker to recover data by trying every possible encryption block ๐Ÿ›ก๏ธ.
  • 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 being 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. Another flavor of the attack can decrypt a single ciphertext when a large fraction (2/3) of the input to RSAEP is already known. For typical applications, the message is short (e.g., a 128-bit symmetric key), so not enough information will be known or shared 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

Time to lock it up ๐Ÿ”’๐Ÿ’œ.

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"
  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, made of pseudo-randomly generated nonzero octets. PS will be at least eight octets long.
    • b. Put together PS, the message M, and other padding to form an encoded message EM of length k octets:
EM = 0x00 || 0x02 || PS || 0x00 || M.
  1. RSA encryption ๐Ÿ”:
    • a. Turn the encoded message EM into 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 get an integer ciphertext representative c:
c = RSAEP ((n, e), m).
  • c. Turn the ciphertext representative c into a ciphertext C of length k octets (see Section 4.1):
C = I2OSP (c, k).
  1. Output the ciphertext C ๐Ÿ’Œ.

7.2.2. Decryption Operation

Unlocking time again ๐Ÿ—๏ธโœจ.

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

Output:

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

Error:  "decryption error"
  1. Length checking ๐Ÿ“: If the ciphertext C isn't exactly k octets (or if k < 11), output "decryption error" and stop.
  2. RSA decryption ๐Ÿ”:
    • a. Turn the ciphertext C into 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 get an integer message representative m:
m = RSADP ((n, d), c).

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

  • c. Turn the message representative m into an encoded message EM of k octets (see Section 4.1):
EM = I2OSP (m, k).
  1. EME-PKCS1-v1_5 decoding ๐Ÿงฉ: Split the encoded message EM into an octet string PS made of nonzero octets and a message M:
EM = 0x00 || 0x02 || PS || 0x00 || M.

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

  1. Output M ๐ŸŽ‰.
Note, bestie ๐Ÿšจ: care shall be taken to make sure an opponent can't tell apart the different error conditions in Step 3, whether by error message or by timing. Otherwise, an opponent may be able to get useful information about the decryption of the ciphertext C, which could lead to a strengthened version of Bleichenbacher's attack [BLEICHENBACHER]. Compare to Manger's attack [MANGER] ๐Ÿ’….

8. Signature Scheme with Appendix โœจ

Okay so, a signature scheme with appendix has two operations: signing, which takes a message and the signer's RSA private key and produces a signature, and verifying, which checks that signature against the message using the matching RSA public key. ๐Ÿ’– To verify one of these, you need the actual message, bestie. That's what makes them different from signature schemes with message recovery, which this document doesn't support. ๐Ÿฆ‹

These schemes show up in a bunch of places. The ones defined here would be solid signature algorithms for X.509 certificates [ISO9594]. Related schemes could also be used in PKCS #7 [RFC2315], but ngl, the current PKCS #7 version keeps the hash function separate from the signature scheme, which is different from how this works. Check the note in Appendix A.2.3 for more tea. โ˜•

There are two signature schemes with appendix in this document: RSASSA-PSS and RSASSA-PKCS1-v1_5. Nobody knows of any attacks on RSASSA-PKCS1-v1_5, but for extra robustness, RSASSA-PSS is REQUIRED in new applications. RSASSA-PKCS1-v1_5 is only here for compatibility with existing apps. ๐Ÿซถ

Both schemes follow a general model similar to the one in IEEE 1363 [IEEE1363]. They combine signature and verification primitives with an encoding method for signatures. The signature generation operations apply a message encoding operation to the message to get an encoded message, then convert that into an integer message representative. A signature primitive runs on the message representative to produce the signature. Going the other way, the signature verification operations run a signature verification primitive on the signature to recover a message representative, then convert it back into an octet-string-encoded message. Finally, a verification operation looks at the message and the encoded message and checks whether they're consistent. ๐ŸŒธ

If the encoding method is deterministic (like EMSA-PKCS1-v1_5), the verification operation can run the message encoding operation on the message and compare the result to the encoded message you already derived. If they match, the signature is considered valid. โœจ If the method is randomized (like EMSA-PSS), verification gets more involved. For example, EMSA-PSS verification pulls the random salt and a hash output out of the encoded message, then checks that the hash output, the salt, and the message all line up. The hash output is a deterministic function of the message and the salt. ๐Ÿงš

For both schemes in this document, the signature generation and verification operations can be implemented as "single-pass" operations if the signature is placed after the message. For an example format using RSASSA-PKCS1-v1_5, see PKCS #7 [RFC2315]. ๐Ÿ’…


8.1. RSASSA-PSS ๐ŸŽ€

RSASSA-PSS combines the RSASP1 and RSAVP1 primitives with the EMSA-PSS encoding method. It's 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 a bit more general than EMSA-PSS because it works on bit strings instead of octet strings. EMSA-PSS is basically EMSA4 limited to the case where the operands, plus the hash and salt values, are all octet strings. ๐Ÿฆ‹

The length of messages RSASSA-PSS can handle is either unrestricted or capped by a really huge number, depending on the hash function underneath 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 the right properties, RSASSA-PSS gives you secure signatures. This is provable, meaning forging signatures can be directly tied to how hard it is to invert the RSA function, as long as the hash and mask generation functions are treated as black boxes or random oracles. The security proof bounds are basically "tight," so the best forger's success probability and running time are very close to the best RSA inversion algorithm's. For more on this, see [RSARABIN] [PSSPROOF] [JONSSON]. ๐Ÿ‘‘

Here's the thing: unlike RSASSA-PKCS1-v1_5, the EMSA-PSS encoded message doesn't embed a hash function identifier. So in theory, an adversary could swap in a different, potentially weaker hash function than the one the signer picked. ๐Ÿ˜ญ To prevent that, it is RECOMMENDED that the EMSA-PSS mask generation function be based on the same hash function. That way the whole encoded message depends on the hash function, and it gets really hard for an opponent to substitute a different one than the signer intended. This hash matching is only about preventing hash function substitution, and you don't need it if substitution is handled some other way (like the verifier only accepting one designated hash function). See [HASHID] for more on all of this. The provable security of RSASSA-PSS doesn't depend on the mask generation function's hash being the same as the one applied to the message. ๐Ÿ’œ

RSASSA-PSS is different from other RSA-based signature schemes because it's probabilistic instead of deterministic. It uses a randomly generated salt value. The salt makes the scheme's security proof "tighter" than deterministic options like Full Domain Hashing (FDH); see [RSARABIN] for discussion. The randomness isn't critical to security, though. If random generation isn't possible, you could use a fixed value or a sequence number instead, and the provable security would be similar to FDH's [FDH]. ๐Ÿ“

8.1.1. Signature Generation Operation ๐ŸŒŸ

Here's the interface for the 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"

Now the steps:

  1. EMSA-PSS encoding: Run the EMSA-PSS encoding operation (Section 9.1.1) on the message M to produce an encoded message EM. EM has a length of \ceil ((modBits - 1)/8) octets, and the bit length of the integer OS2IP (EM) (see Section 4.2) is at most modBits - 1. Here modBits is the length in bits of the RSA modulus n: EM = EMSA-PSS-ENCODE (M, modBits - 1). Heads up: 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 it outputs "encoding error", output "encoding error" and stop.
  2. RSA signature:
    • a. Convert the encoded message EM into 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 into 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 ๐Ÿ”

Here's the interface for the 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"

And the 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 into 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 into 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're consistent: Result = EMSA-PSS-VERIFY (M, EM, modBits - 1).
  4. If Result = "consistent", output "valid signature". Otherwise, output "invalid signature". Signature verified, periodt! ๐Ÿ‘‘

8.2. RSASSA-PKCS1-v1_5 ๐Ÿ’…

okay bestie, RSASSA-PKCS1-v1_5 is literally the RSASP1 and RSAVP1 primitives teamed up with the EMSA-PKCS1-v1_5 encoding method ๐ŸŽ€. It's compatible with the IFSSA scheme from 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. EMSA-PKCS1-v1_5 isn't defined in IEEE 1363 itself, but it is in IEEE 1363a [IEEE1363A] ๐ŸŒธ

How long a message can be depends on the hash function sitting under EMSA-PKCS1-v1_5. It's either unrestricted or capped by a really, really huge number โœจ

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. To be more precise, forging signatures without knowing the RSA private key is conjectured to be computationally infeasible ๐Ÿ” Also, EMSA-PKCS1-v1_5 embeds a hash function identifier in the encoding. Because of that, an adversary who wants a message with the same signature as an already-signed message has to find collisions of the exact hash function in use. Attacking a different hash function than the one the signer picked doesn't help the adversary at all ๐Ÿ™…โ€โ™€๏ธ See [HASHID] for more on this.

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] later extended Coron et al.'s attack to break the ISO/IEC 9796-1 signature scheme with message recovery. The various attacks show how important it is to carefully construct the input to the RSA signature primitive, especially in a signature scheme with message recovery ๐Ÿ‘€ So the EMSA-PKCS-v1_5 encoding method explicitly includes a hash operation and isn't intended for signature schemes with message recovery. Also, 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

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
   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.
  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. ๐Ÿค“


9. Encoding Methods for Signatures with Appendix ๐ŸŽ€

Encoding methods are operations that map between octet string messages and octet-string-encoded messages. Those get converted to and from integer message representatives in the schemes, and the integer message representatives are processed via the primitives. So the encoding methods are the bridge between the schemes, which process messages, and the primitives ๐ŸŒˆ

An encoding method for signatures with appendix, for the purposes of this document, consists of an encoding operation and optionally a verification operation. An encoding operation maps a message M to an encoded message EM of a specified length. A verification operation determines whether a message M and an encoded message EM are consistent, i.e., whether the encoded message EM is a valid encoding of the message M ๐Ÿ’–

The encoding operation may introduce some randomness, so different applications of the encoding operation to the same message produce different encoded messages. That has benefits for provable security โœจ For such an encoding method, both an encoding and a verification operation are needed unless the verifier can reproduce the randomness (e.g., by obtaining the salt value from the signer). For a deterministic encoding method, only an encoding operation is needed.

Two encoding methods for signatures with appendix are employed in the signature schemes and are specified here: EMSA-PSS and EMSA-PKCS1-v1_5 ๐Ÿฆ‹

9.1. EMSA-PSS โœจ

okay so this encoding method has three knobs: the hash function, the mask generation function, and the salt length ๐Ÿง‚. For a given RSA key, these options should be fixed, except the salt length, which can vary (check [JONSSON] for the drama on that one ๐Ÿ‘€). Suggested hash and mask generation functions are in Appendix B ๐Ÿ’–. The whole thing is based on Bellare and Rogaway's Probabilistic Signature Scheme (PSS) [RSARABIN][PSS], it's randomized, and it has an encoding operation and a verification operation ๐Ÿฆ‹.

Figure 2 shows the encoding operation. Look at how the message gets hashed, the salt gets mixed in, and everything folds into EM ๐ŸŽ€

      __________________________________________________________________

                                     +-----------+
                                     |     M     |
                                     +-----------+
                                           |
                                           V
                                         Hash
                                           |
                                           V
                             +--------+----------+----------+
                        M' = |Padding1|  mHash   |   salt   |
                             +--------+----------+----------+
                                            |
                  +--------+----------+     V
            DB =  |Padding2|   salt   |   Hash
                  +--------+----------+     |
                            |               |
                            V               |
                           xor <--- MGF <---|
                            |               |
                            |               |
                            V               V
                  +-------------------+----------+--+
            EM =  |    maskedDB       |     H    |bc|
                  +-------------------+----------+--+
      __________________________________________________________________

Figure 2: EMSA-PSS Encoding Operation ๐ŸŒธ

Note that the verification operation runs the steps in reverse to recover salt, and then goes forward again to recompute and compare H ๐Ÿ” it's giving detective energy ๐Ÿ•ต๏ธโ€โ™€๏ธ

Notes:

  1. The encoding method defined here differs from the one in Bellare and Rogaway's submission to IEEE 1363a [PSS] in three respects ๐Ÿ’…:
    • It applies a hash function rather than a mask generation function to the message. Even though the mask generation function is based on a hash function, it seems more natural to apply a hash function directly ๐Ÿง .
    • The value that is hashed together with the salt value is the string (0x)00 00 00 00 00 00 00 00 || mHash rather than the message M itself. Here, mHash is the hash of M. Note that the hash function is the same in both steps. See Note 3 below for further discussion. (Also, the name "salt" is used instead of "seed", as it is more reflective of the value's role ๐Ÿง‚โœจ)
    • The encoded message in EMSA-PSS has nine fixed bits. The first bit is 0 and the last eight bits form a "trailer field", the octet 0xbc. In the original scheme, only the first bit is fixed. The rationale for the trailer field is compatibility with the Integer Factorization Signature Primitive using Rabin-Williams (IFSP-RW) in IEEE 1363 [IEEE1363] and the corresponding primitive in ISO/IEC 9796-2:2010 [ISO9796] ๐ŸŽ€
  2. Assuming the mask generation function is based on a hash function, it is RECOMMENDED that the hash function be the same as the one applied to the message. See Section 8.1 for further discussion ๐Ÿ’œ
  3. Without compromising the security proof for RSASSA-PSS, you can perform Steps 1 and 2 of EMSA-PSS-ENCODE and EMSA-PSS-VERIFY (the application of the hash function to the message) outside the module that computes the rest of the signature operation. That way, mHash rather than the message M itself is input to the module. In other words, the security proof for RSASSA-PSS still holds even if an opponent can control the value of mHash ๐Ÿ˜ค This is convenient if the module has limited I/O bandwidth, e.g., a smart card ๐Ÿ’ณ Note that previous versions of PSS [RSARABIN][PSS] did not have this property. Of course, it may be desirable for other security reasons to have the module process the full message. For instance, the module may need to "see" what it is signing if it does not trust the component that computes the hash value ๐Ÿ‘€
  4. Typical salt lengths in octets are hLen (the length of the output of the hash function Hash) and 0 ๐ŸŒˆ In both cases, the security of RSASSA-PSS can be closely related to the hardness of inverting RSAVP1. Bellare and Rogaway [RSARABIN] give a tight lower bound for the security of the original RSA-PSS scheme, which corresponds roughly to the former case. Coron [FDH] gives a lower bound for the related Full Domain Hashing scheme, which corresponds roughly to the latter case. In [PSSPROOF], Coron provides a general treatment with various salt lengths ranging from 0 to hLen; see [IEEE1363A] for discussion. See also [JONSSON], which adapts the security proofs in [RSARABIN] [PSSPROOF] to address the differences between the original and the present version of RSA-PSS as listed in Note 1 above ๐Ÿ“š
  5. As noted in IEEE 1363a [IEEE1363A], the use of randomization in signature schemes (such as the salt value in EMSA-PSS) may provide a "covert channel" for transmitting information other than the message being signed ๐Ÿ•ต๏ธ For more on covert channels, see [SIMMONS] ๐Ÿซฃ

9.1.1. Encoding Operation ๐Ÿซถ

   EMSA-PSS-ENCODE (M, emBits)

   Options:

      Hash     hash function (hLen denotes the length in octets of
               the hash function output)
      MGF      mask generation function
      sLen     intended length in octets of the salt

   Input:

      M        message to be encoded, an octet string
      emBits   maximal bit length of the integer OS2IP (EM) (see Section
               4.2), at least 8hLen + 8sLen + 9

   Output:

      EM       encoded message, an octet string of length emLen = \ceil
               (emBits/8)

   Errors:  "Encoding error"; "message too long"

Steps:

  1. If the length of M is greater than the input limitation for the hash function (2^61 - 1 octets for SHA-1), output "message too long" and stop. ๐Ÿ›‘
  2. Let mHash = Hash(M), an octet string of length hLen. ๐Ÿ”ข
  3. If emLen < hLen + sLen + 2, output "encoding error" and stop. ๐Ÿ™…โ€โ™€๏ธ
  4. Generate a random octet string salt of length sLen. If sLen = 0, then salt is the empty string. ๐ŸŽฒ
  5. Let M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt. M' is an octet string of length 8 + hLen + sLen with eight initial zero octets. ๐Ÿง
  6. Let H = Hash(M'), an octet string of length hLen. ๐Ÿ”
  7. Generate an octet string PS consisting of emLen - sLen - hLen - 2 zero octets. The length of PS may be 0. 0๏ธโƒฃ
  8. Let DB = PS || 0x01 || salt. DB is an octet string of length emLen - hLen - 1. ๐Ÿงฉ
  9. Let dbMask = MGF(H, emLen - hLen - 1). ๐ŸŽญ
  10. Let maskedDB = DB \xor dbMask. ๐Ÿ’ซ
  11. Set the leftmost 8emLen - emBits bits of the leftmost octet in maskedDB to zero. ๐Ÿซง
  12. Let EM = maskedDB || H || 0xbc. ๐ŸŽ€
  13. Output EM. ๐Ÿฆ‹

9.1.2. Verification Operation ๐Ÿ”

   EMSA-PSS-VERIFY (M, EM, emBits)

   Options:

      Hash     hash function (hLen denotes the length in octets of
               the hash function output)
      MGF      mask generation function
      sLen     intended length in octets of the salt

   Input:

      M        message to be verified, an octet string
      EM       encoded message, an octet string of length emLen = \ceil
               (emBits/8)
      emBits   maximal bit length of the integer OS2IP (EM) (see Section
               4.2), at least 8hLen + 8sLen + 9

   Output:  "consistent" or "inconsistent"

Steps:

  1. If the length of M is greater than the input limitation for the hash function (2^61 - 1 octets for SHA-1), output "inconsistent" and stop. ๐Ÿšซ
  2. Let mHash = Hash(M), an octet string of length hLen. ๐Ÿ”ข
  3. If emLen < hLen + sLen + 2, output "inconsistent" and stop. ๐Ÿ™…โ€โ™€๏ธ
  4. If the rightmost octet of EM does not have hexadecimal value 0xbc, output "inconsistent" and stop. ๐Ÿง
  5. Let maskedDB be the leftmost emLen - hLen - 1 octets of EM, and let H be the next hLen octets. โœ‚๏ธ
  6. If the leftmost 8emLen - emBits bits of the leftmost octet in maskedDB are not all equal to zero, output "inconsistent" and stop. ๐Ÿ™ˆ
  7. Let dbMask = MGF(H, emLen - hLen - 1). ๐ŸŽญ
  8. Let DB = maskedDB \xor dbMask. ๐Ÿ’ซ
  9. Set the leftmost 8emLen - emBits bits of the leftmost octet in DB to zero. ๐Ÿซง
  10. If the emLen - hLen - sLen - 2 leftmost octets of DB are not zero, or if the octet at position emLen - hLen - sLen - 1 (the leftmost position is "position 1") does not have hexadecimal value 0x01, output "inconsistent" and stop. ๐Ÿ˜ฌ
  11. Let salt be the last sLen octets of DB. ๐Ÿง‚
  12. Let M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt. M' is an octet string of length 8 + hLen + sLen with eight initial zero octets. ๐Ÿง
  13. Let H' = Hash(M'), an octet string of length hLen. ๐Ÿ”
  14. If H = H', output "consistent". Otherwise, output "inconsistent". โœจ and that's the whole verification glow-up โœจ ๐ŸŒˆ

9.2. EMSA-PKCS1-v1_5 ๐ŸŒธ

okay bestie, this encoding method is deterministic ๐Ÿซถ and it only has an encoding operation. there's no verification side here, so it's giving simple but still so iconic ๐Ÿ’…

EMSA-PKCS1-v1_5-ENCODE (M, emLen)

Option:

  • Hash: hash function (hLen is the length in octets of the hash function output) ๐Ÿงš

Input:

  • M: message to be encoded ๐Ÿ’Œ
  • emLen: intended length in octets of the encoded message. It has to be at least tLen + 11, where tLen is the octet length of the Distinguished Encoding Rules (DER) encoding T of a certain value computed during the encoding operation ๐ŸŽ€

Output:

  • EM: encoded message, an octet string of length emLen โœจ

Errors:

  • "message too long"
  • "intended encoded message length too short"

Steps:

  1. Apply the hash function to the message M to produce a hash value H:
H = Hash(M).

If the hash function outputs "message too long", output "message too long" and stop. ๐Ÿ›‘

  1. Encode the algorithm ID for the hash function and the hash value into an ASN.1 value of type DigestInfo (see Appendix A.2.4) with the DER. The type DigestInfo has the syntax:
DigestInfo ::= SEQUENCE {
    digestAlgorithm AlgorithmIdentifier,
    digest OCTET STRING
}

The first field identifies the hash function and the second contains the hash value. Let T be the DER encoding of the DigestInfo value (see the notes below), and let tLen be the length in octets of T. ๐Ÿง

  1. If emLen < tLen + 11, output "intended encoded message length too short" and stop. ๐Ÿ™ˆ
  2. Generate an octet string PS consisting of emLen - tLen - 3 octets with hexadecimal value 0xff. The length of PS will be at least 8 octets. ๐ŸŒˆ
  3. Concatenate PS, the DER encoding T, and other padding to form the encoded message EM as:
EM = 0x00 || 0x01 || PS || 0x00 || T.
  1. Output EM. ๐Ÿ’–

Notes:

  1. For the nine hash functions mentioned in Appendix B.1, the DER encoding T of the DigestInfo value is equal to the following:
MD2:     (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04
             10 || H.
MD5:     (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04
             10 || H.
SHA-1:   (0x)30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 || H.
SHA-224:  (0x)30 2d 30 0d 06 09 60 86 48 01 65 03 04 02 04
             05 00 04 1c || H.
SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00
             04 20 || H.
SHA-384: (0x)30 41 30 0d 06 09 60 86 48 01 65 03 04 02 02 05 00
             04 30 || H.
SHA-512: (0x)30 51 30 0d 06 09 60 86 48 01 65 03 04 02 03 05 00
             04 40 || H.
SHA-512/224:  (0x)30 2d 30 0d 06 09 60 86 48 01 65 03 04 02 05
                  05 00 04 1c || H.
SHA-512/256:  (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 06
                  05 00 04 20 || H.
  1. In version 1.5 of this document, T was defined as the BER encoding, rather than the DER encoding, of the DigestInfo value. This means it's possible (at least in theory ๐Ÿค”) that the verification operation defined in this document, as well as the one in version 2.0, rejects a signature that is valid under the specification given in PKCS #1 v1.5. That happens if rules other than DER are applied to DigestInfo, such as an indefinite length encoding of the underlying SEQUENCE type. While this is unlikely to be a concern in practice, a cautious implementor may choose to use a verification operation based on a BER decoding operation as specified in PKCS #1 v1.5. That way, compatibility with any valid implementation based on PKCS #1 v1.5 is kept. Such a verification operation should indicate whether the underlying BER encoding is a DER encoding, and therefore whether the signature is valid under the specification given in this document. ๐Ÿง

10. Security Considerations ๐Ÿ”

Security considerations are discussed throughout this memo. bestie, this part is serious, so read the whole memo ๐Ÿ˜ญ


11. References โœจ

11.1. Normative References

[GARNER] Garner, H., "The Residue Number System", IRE Transactions on Electronic Computers, Volume EC-8, Issue 2, pp. 140-147, DOI 10.1109/TEC.1959.5219515, June 1959. ๐Ÿ“š

[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, <http://www.rfc-editor.org/info/rfc2119>. ๐ŸŽ€

[RSA] Rivest, R., Shamir, A., and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM, Volume 21, Issue 2, pp. 120-126, DOI 10.1145/359340.359342, February 1978. ๐Ÿฆ‹

11.2. Informative References ๐Ÿ“šโœจ

okay bestie, these are the extra reading picks. not required to build anything, but they're where the receipts live ๐Ÿงพ๐Ÿ’… the whole list is copied exactly below so you can find every paper and spec.

[ANSIX944] ANSI, "Key Establishment Using Integer Factorization
           Cryptography", ANSI X9.44-2007, August 2007.

[BKS]      Bleichenbacher, D., Kaliski, B., and J. Staddon, "Recent
           Results on PKCS #1: RSA Encryption Standard", RSA
           Laboratories, Bulletin No. 7, June 1998.

[BLEICHENBACHER]
           Bleichenbacher, D., "Chosen Ciphertext Attacks Against
           Protocols Based on the RSA Encryption Standard PKCS #1",
           Lecture Notes in Computer Science, Volume 1462, pp. 1-12,
           1998.

[CHOSEN]   Desmedt, Y. and A. Odlyzko, "A Chosen Text Attack on the
           RSA Cryptosystem and Some Discrete Logarithm Schemes",
           Lecture Notes in Computer Science, Volume 218, pp.
           516-522, 1985.

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

[FASTDEC]  Quisquater, J. and C. Couvreur, "Fast Decipherment
           Algorithm for RSA Public-Key Cryptosystem", Electronic
           Letters, Volume 18, Issue 21, pp. 905-907,
           DOI 10.1049/el:19820617, October 1982.

[FDH]      Coron, J., "On the Exact Security of Full Domain Hash",
           Lecture Notes in Computer Science, Volume 1880, pp.
           229-235, 2000.

[FOPS]     Fujisaki, E., Okamoto, T., Pointcheval, D., and J. Stern,
           "RSA-OAEP is Secure under the RSA Assumption", Lecture
           Notes in Computer Science, Volume 2139, pp. 260-274,
           August 2001.

[FORGERY]  Coppersmith, D., Halevi, S., and C. Jutla, "ISO 9796-1 and
           the new forgery strategy", rump session of Crypto, August
           1999.

[HAASTAD]  Haastad, J., "Solving Simultaneous Modular Equations of
           Low Degree", SIAM Journal on Computing, Volume 17,
           Issue 2, pp. 336-341, DOI 10.1137/0217019, April 1988.

[HANDBOOK] Menezes, A., van Oorschot, P., and S. Vanstone, "Handbook
           of Applied Cryptography", CRC Press, ISBN: 0849385237,
           1996.

[HASHID]   Kaliski, B., "On Hash Function Firewalls in Signature
           Schemes", Lecture Notes in Computer Science, Volume 2271,
           pp. 1-16, DOI 10.1007/3-540-45760-7_1, February 2002.

[IEEE1363] IEEE, "Standard Specifications for Public Key
           Cryptography", IEEE Std 1363-2000,
           DOI 10.1109/IEEESTD.2000.92292, August 2000,
           <http://ieeexplore.ieee.org/document/891000/>.

[IEEE1363A]
           IEEE, "Standard Specifications for Public Key Cryptography
           - Amendment 1: Additional Techniques", IEEE Std 1363a-
           2004, DOI 10.1109/IEEESTD.2004.94612, September 2004,
           <http://ieeexplore.ieee.org/document/1335427/>.

[ISO18033] International Organization for Standardization,
           "Information technology -- Security techniques --
           Encryption algorithms - Part 2: Asymmetric ciphers", ISO/
           IEC 18033-2:2006, May 2006.

[ISO9594]  International Organization for Standardization,
           "Information technology - Open Systems Interconnection -
           The Directory: Public-key and attribute certificate
           frameworks", ISO/IEC 9594-8:2008, December 2008.

[ISO9796]  International Organization for Standardization,
           "Information technology - Security techniques - Digital
           signature schemes giving message recovery - Part 2:
           Integer factorization based mechanisms",
           ISO/IEC 9796-2:2010, December 2010.

[JONSSON]  Jonsson, J., "Security Proofs for the RSA-PSS Signature
           Scheme and Its Variants", Cryptology ePrint
           Archive: Report 2001/053, March 2002,
           <http://eprint.iacr.org/2001/053>.

[LOWEXP]   Coppersmith, D., Franklin, M., Patarin, J., and M. Reiter,
           "Low-Exponent RSA with Related Messages", Lecture Notes in
           Computer Science, Volume 1070, pp. 1-9, 1996.

[MANGER]   Manger, J., "A Chosen Ciphertext Attack on RSA Optimal
           Asymmetric Encryption Padding (OAEP) as Standardized in
           PKCS #1 v2.0", Lecture Notes in Computer Science, Volume
           2139, pp. 230-238, DOI 10.1007/3-540-44647-8_14, 2001.

[MD4]      Dobbertin, H., "Cryptanalysis of MD4", Lecture Notes in
           Computer Science, Volume 1039, pp. 53-69,
           DOI 10.1007/3-540-60865-6_43, 1996.

[MD4FIRST] Dobbertin, H., "The First Two Rounds of MD4 are Not One-
           Way", Lecture Notes in Computer Science, Volume 1372, pp.
           284-292, DOI 10.1007/3-540-69710-1_19, March 1998.

[MD4LAST]  den Boer, B. and A. Bosselaers, "An Attack on the Last Two
           Rounds of MD4", Lecture Notes in Computer Science, Volume
           576, pp. 194-203, DOI 10.1007/3-540-46766-1_14, 1992.

[NEWATTACK]
           Coron, J., Joye, M., Naccache, D., and P. Paillier, "New
           Attacks on PKCS #1 v1.5 Encryption", Lecture Notes in
           Computer Science, Volume 1807, pp. 369-381,
           DOI 10.1007/3-540-45539-6_25, May 2000.

[OAEP]     Bellare, M. and P. Rogaway, "Optimal Asymmetric Encryption
           - How to Encrypt with RSA", Lecture Notes in Computer
           Science, Volume 950, pp. 92-111, November 1995.

[PA98]     Bellare, M., Desai, A., Pointcheval, D., and P. Rogaway,
           "Relations Among Notions of Security for Public-Key
           Encryption Schemes", Lecture Notes in Computer
           Science, Volume 1462, pp. 26-45, DOI 10.1007/BFb0055718,
           1998.

[PADDING]  Coron, J., Naccache, D., and J. Stern, "On the Security of
           RSA Padding", Lecture Notes in Computer Science, Volume
           1666, pp. 1-18, DOI 10.1007/3-540-48405-1_1, December
           1999.

[PKCS1_22] RSA Laboratories, "PKCS #1: RSA Cryptography Standard
           Version 2.2", October 2012.

[PREFIX]   Stevens, M., Lenstra, A., and B. de Weger, "Chosen-prefix
           collisions for MD5 and applications", International
           Journal of Applied Cryptography, Volume 2, No. 4, pp.
           322-359, July 2012.

[PSS]      Bellare, M. and P. Rogaway, "PSS: Provably Secure Encoding
           Method for Digital Signatures", Submission to IEEE P1363a,
           August 1998, <http://grouper.ieee.org/groups/1363/
           P1363a/contributions/pss-submission.pdf>.

[PSSPROOF] Coron, J., "Optimal Security Proofs for PSS and Other
           Signature Schemes", Lecture Notes in Computer
           Science, Volume 2332, pp. 272-287,
           DOI 10.1007/3-540-46035-7_18, 2002.

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

[RFC2313]  Kaliski, B., "PKCS #1: RSA Encryption Version 1.5",
           RFC 2313, DOI 10.17487/RFC2313, March 1998,
           <http://www.rfc-editor.org/info/rfc2313>.

[RFC2315]  Kaliski, B., "PKCS #7: Cryptographic Message Syntax
           Version 1.5", RFC 2315, DOI 10.17487/RFC2315, March 1998,
           <http://www.rfc-editor.org/info/rfc2315>.

[RFC2437]  Kaliski, B. and J. Staddon, "PKCS #1: RSA Cryptography
           Specifications Version 2.0", RFC 2437,
           DOI 10.17487/RFC2437, October 1998,
           <http://www.rfc-editor.org/info/rfc2437>.

[RFC3447]  Jonsson, J. and B. Kaliski, "Public-Key Cryptography
           Standards (PKCS) #1: RSA Cryptography Specifications
           Version 2.1", RFC 3447, DOI 10.17487/RFC3447, February
           2003, <http://www.rfc-editor.org/info/rfc3447>.

[RFC5246]  Dierks, T. and E. Rescorla, "The Transport Layer Security
           (TLS) Protocol Version 1.2", RFC 5246,
           DOI 10.17487/RFC5246, August 2008,
           <http://www.rfc-editor.org/info/rfc5246>.

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

[RFC7292]  Moriarty, K., Ed., Nystrom, M., Parkinson, S., Rusch, A.,
           and M. Scott, "PKCS #12: Personal Information Exchange
           Syntax v1.1", RFC 7292, DOI 10.17487/RFC7292, July 2014,
           <http://www.rfc-editor.org/info/rfc7292>.

[RSARABIN] Bellare, M. and P. Rogaway, "The Exact Security of Digital
           Signatures - How to Sign with RSA and Rabin", Lecture
           Notes in Computer Science, Volume 1070, pp. 399-416,
           DOI 10.1007/3-540-68339-9_34, 1996.

[RSATLS]   Jonsson, J. and B. Kaliski, "On the Security of RSA
           Encryption in TLS", Lecture Notes in Computer
           Science, Volume 2442, pp. 127-142,
           DOI 10.1007/3-540-45708-9_9, 2002.

[SHA1CRYPT]
           Wang, X., Yao, A., and F. Yao, "Cryptanalysis on SHA-1",
           Lecture Notes in Computer Science, Volume 2442, pp.
           127-142, February 2005,
           <http://csrc.nist.gov/groups/ST/hash/documents/
           Wang_SHA1-New-Result.pdf>.

[SHOUP]    Shoup, V., "OAEP Reconsidered (Extended Abstract)",
           Lecture Notes in Computer Science, Volume 2139, pp.
           239-259, DOI 10.1007/3-540-44647-8_15, 2001.

[SHS]      National Institute of Standards and Technology, "Secure
           Hash Standard (SHS)", FIPS PUB 180-4, August 2015,
           <http://dx.doi.org/10.6028/NIST.FIPS.180-4>.

[SILVERMAN]
           Silverman, R., "A Cost-Based Security Analysis of
           Symmetric and Asymmetric Key Lengths", RSA
           Laboratories, Bulletin No. 13, 2000.

[SIMMONS]  Simmons, G., "Subliminal Communication is Easy Using the
           DSA", Lecture Notes in Computer Science, Volume 765, pp.
           218-232, DOI 10.1007/3-540-48285-7_18, 1994.

Appendix A. ASN.1 Syntax ๐Ÿงฉ๐ŸŽ€

A.1. RSA Key Representation ๐Ÿ”‘

this section is where we name the ASN.1 object identifiers for RSA public and private keys, and where we define the types RSAPublicKey and RSAPrivateKey. the plan is for these to show up in X.509 certificates, PKCS #8 [RFC5958], and PKCS #12 [RFC7292] ๐Ÿ“œ

the rsaEncryption OID is what tags RSA public and private keys, as defined in Appendices A.1.1 and A.1.2. the parameters field associated with this OID in a value of type AlgorithmIdentifier SHALL have a value of type NULL, no exceptions ๐Ÿ™…โ€โ™€๏ธ

   rsaEncryption    OBJECT IDENTIFIER ::= { pkcs-1 1 }

and the definitions in this section were extended to handle multi-prime RSA, but they're still backward compatible with the older versions ๐Ÿฅฐโœจ

A.1.1. RSA Public Key Syntax ๐Ÿ—๏ธ

an RSA public key should be represented with the ASN.1 type RSAPublicKey, lowkey the standard go-to ๐Ÿ’–

      RSAPublicKey ::= SEQUENCE {
          modulus           INTEGER,  -- n
          publicExponent    INTEGER   -- e
      }

the RSAPublicKey fields mean:

  • modulus is the RSA modulus n. ๐Ÿ’œ
  • publicExponent is the RSA public exponent e. ๐Ÿฆ‹

A.1.2. RSA Private Key Syntax ๐Ÿ”‘

okay so an RSA private key should be represented with the ASN.1 type RSAPrivateKey, and this is literally the blueprint for how the whole key gets packaged up ๐Ÿ’…

RSAPrivateKey ::= SEQUENCE {
    version           Version,
    modulus           INTEGER,  -- n
    publicExponent    INTEGER,  -- e
    privateExponent   INTEGER,  -- d
    prime1            INTEGER,  -- p
    prime2            INTEGER,  -- q
    exponent1         INTEGER,  -- d mod (p-1)
    exponent2         INTEGER,  -- d mod (q-1)
    coefficient       INTEGER,  -- (inverse of q) mod p
    otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

The fields of type RSAPrivateKey have the following meanings:

  • version is the version number, for compatibility with future revisions of this document. It SHALL be 0 for this version of the document, unless multi-prime is used; in which case, it SHALL be 1.
Version ::= INTEGER { two-prime(0), multi(1) }
   (CONSTRAINED BY
   {-- version must be multi if otherPrimeInfos present --})
  • modulus is the RSA modulus n. ๐Ÿง
  • publicExponent is the RSA public exponent e. ๐ŸŒธ
  • privateExponent is the RSA private exponent d. ๐Ÿ”
  • prime1 is the prime factor p of n. โœจ
  • prime2 is the prime factor q of n. โœจ
  • exponent1 is d mod (p - 1). ๐Ÿฆ‹
  • exponent2 is d mod (q - 1). ๐Ÿฆ‹
  • coefficient is the CRT coefficient q^(-1) mod p. ๐Ÿ’œ
  • otherPrimeInfos contains the information for the additional primes r_3, ..., r_u, in order. It SHALL be omitted if version is 0 and SHALL contain at least one instance of OtherPrimeInfo if version is 1.
OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo

OtherPrimeInfo ::= SEQUENCE {
    prime             INTEGER,  -- ri
    exponent          INTEGER,  -- di
    coefficient       INTEGER   -- ti
}

The fields of type OtherPrimeInfo have the following meanings:

  • prime is a prime factor r_i of n, where i >= 3. ๐Ÿ“
  • exponent is d_i = d mod (r_i - 1). ๐Ÿ“
  • coefficient is the CRT coefficient t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i. ๐Ÿ“
Note: It is important to protect the RSA private key against both disclosure and modification. Techniques for such protection are outside the scope of this document. Methods for storing and distributing private keys and other cryptographic data are described in PKCS #12 and #15. ๐Ÿšจ

A.2. Scheme Identification ๐Ÿชช

This section defines object identifiers for the encryption and signature schemes. The schemes compatible with PKCS #1 v1.5 have the same definitions as in PKCS #1 v1.5. The intended application of these definitions includes X.509 certificates and PKCS #7. ๐ŸŽ€

Here are type identifier definitions for the PKCS #1 OIDs:

PKCS1Algorithms    ALGORITHM-IDENTIFIER ::= {
    { OID rsaEncryption                PARAMETERS NULL } |
    { OID md2WithRSAEncryption         PARAMETERS NULL } |
    { OID md5WithRSAEncryption         PARAMETERS NULL } |
    { OID sha1WithRSAEncryption        PARAMETERS NULL } |
    { OID sha224WithRSAEncryption      PARAMETERS NULL } |
    { OID sha256WithRSAEncryption      PARAMETERS NULL } |
    { OID sha384WithRSAEncryption      PARAMETERS NULL } |
    { OID sha512WithRSAEncryption      PARAMETERS NULL } |
    { OID sha512-224WithRSAEncryption  PARAMETERS NULL } |
    { OID sha512-256WithRSAEncryption  PARAMETERS NULL } |
    { OID id-RSAES-OAEP   PARAMETERS RSAES-OAEP-params } |
    PKCS1PSourceAlgorithms                               |
    { OID id-RSASSA-PSS   PARAMETERS RSASSA-PSS-params },
    ...  -- Allows for future expansion --
}

A.2.1. RSAES-OAEP ๐Ÿ’œ

The object identifier id-RSAES-OAEP identifies the RSAES-OAEP encryption scheme. ๐Ÿฆ‹

id-RSAES-OAEP    OBJECT IDENTIFIER ::= { pkcs-1 7 }

The parameters field associated with this OID in a value of type AlgorithmIdentifier SHALL have a value of type RSAES-OAEP-params:

RSAES-OAEP-params ::= SEQUENCE {
    hashAlgorithm      [0] HashAlgorithm     DEFAULT sha1,
    maskGenAlgorithm   [1] MaskGenAlgorithm  DEFAULT mgf1SHA1,
    pSourceAlgorithm   [2] PSourceAlgorithm  DEFAULT pSpecifiedEmpty
}

The fields of type RSAES-OAEP-params have the following meanings:

  • hashAlgorithm identifies the hash function. It SHALL be an algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms. For a discussion of supported hash functions, see Appendix B.1.
HashAlgorithm ::= AlgorithmIdentifier {
   {OAEP-PSSDigestAlgorithms}
}

OAEP-PSSDigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
    { OID id-sha1       PARAMETERS NULL }|
    { OID id-sha224     PARAMETERS NULL }|
    { OID id-sha256     PARAMETERS NULL }|
    { OID id-sha384     PARAMETERS NULL }|
    { OID id-sha512     PARAMETERS NULL }|
    { OID id-sha512-224 PARAMETERS NULL }|
    { OID id-sha512-256 PARAMETERS NULL },
    ...  -- Allows for future expansion --
}

The default hash function is SHA-1:

sha1    HashAlgorithm ::= {
    algorithm   id-sha1,
    parameters  SHA1Parameters : NULL
}

SHA1Parameters ::= NULL
  • maskGenAlgorithm identifies the mask generation function. It SHALL be an algorithm ID with an OID in the set PKCS1MGFAlgorithms, which for this version SHALL consist of id-mgf1, identifying the MGF1 mask generation function (see Appendix B.2.1). The parameters field associated with id-mgf1 SHALL be an algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms, identifying the hash function on which MGF1 is based.
MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }

PKCS1MGFAlgorithms    ALGORITHM-IDENTIFIER ::= {
    { OID id-mgf1 PARAMETERS HashAlgorithm },
    ...  -- Allows for future expansion --
}
  • The default mask generation function is MGF1 with SHA-1:
mgf1SHA1    MaskGenAlgorithm ::= {
    algorithm   id-mgf1,
    parameters  HashAlgorithm : sha1
}
  • pSourceAlgorithm identifies the source (and possibly the value) of the label L. It SHALL be an algorithm ID with an OID in the set PKCS1PSourceAlgorithms, which for this version SHALL consist of id-pSpecified, indicating that the label is specified explicitly. The parameters field associated with id-pSpecified SHALL have a value of type OCTET STRING, containing the label. In previous versions of this specification, the term "encoding parameters" was used rather than "label", hence the name of the type below.
PSourceAlgorithm ::= AlgorithmIdentifier {
   {PKCS1PSourceAlgorithms}
}

PKCS1PSourceAlgorithms    ALGORITHM-IDENTIFIER ::= {
    { OID id-pSpecified PARAMETERS EncodingParameters },
    ...  -- Allows for future expansion --
}

id-pSpecified    OBJECT IDENTIFIER ::= { pkcs-1 9 }

EncodingParameters ::= OCTET STRING(SIZE(0..MAX))
  • The default label is an empty string (so that lHash will contain the hash of the empty string):
pSpecifiedEmpty    PSourceAlgorithm ::= {
    algorithm   id-pSpecified,
    parameters  EncodingParameters : emptyString
}

emptyString    EncodingParameters ::= ''H

If all of the default values of the fields in RSAES-OAEP-params are used, then the algorithm identifier will have the following value:

rSAES-OAEP-Default-Identifier    RSAES-AlgorithmIdentifier ::= {
    algorithm   id-RSAES-OAEP,
    parameters  RSAES-OAEP-params : {
        hashAlgorithm       sha1,
        maskGenAlgorithm    mgf1SHA1,
        pSourceAlgorithm    pSpecifiedEmpty
    }
}

RSAES-AlgorithmIdentifier ::= AlgorithmIdentifier  {
    {PKCS1Algorithms}
}

A.2.2. RSAES-PKCS-v1_5 ๐ŸŒˆ

The object identifier rsaEncryption (see Appendix A.1) identifies the RSAES-PKCS1-v1_5 encryption scheme. The parameters field associated with this OID in a value of type AlgorithmIdentifier SHALL have a value of type NULL. This is the same as in PKCS #1 v1.5. โœจ

rsaEncryption    OBJECT IDENTIFIER ::= { pkcs-1 1 }

A.2.3. RSASSA-PSS ๐ŸŽ€

Okay bestie, so the object identifier id-RSASSA-PSS is how we say "this is the RSASSA-PSS scheme" ๐Ÿ’… It's giving encryption scheme in the original wording, so that's what I'm sticking with โœจ

id-RSASSA-PSS    OBJECT IDENTIFIER ::= { pkcs-1 10 }

The parameters field tied to this OID inside an AlgorithmIdentifier value SHALL have a value of type RSASSA-PSS-params ๐Ÿงš

RSASSA-PSS-params ::= SEQUENCE {
    hashAlgorithm      [0] HashAlgorithm      DEFAULT sha1,
    maskGenAlgorithm   [1] MaskGenAlgorithm   DEFAULT mgf1SHA1,
    saltLength         [2] INTEGER            DEFAULT 20,
    trailerField       [3] TrailerField       DEFAULT trailerFieldBC
}

Here's what each field means, lowercase-bestie style ๐ŸŒธ

  • hashAlgorithm identifies the hash function. It SHALL be an algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms (see Appendix A.2.1). The default hash function is SHA-1.
  • maskGenAlgorithm identifies the mask generation function. It SHALL be an algorithm ID with an OID in the set PKCS1MGFAlgorithms (see Appendix A.2.1). The default mask generation function is MGF1 with SHA-1. For MGF1 (and more generally, for other mask generation functions based on a hash function), it is RECOMMENDED that the underlying hash function be the same as the one identified by hashAlgorithm. See Note 2 in Section 9.1 for further comments ๐Ÿฆ‹
  • saltLength is the octet length of the salt. It SHALL be an integer. For a given hashAlgorithm, the default value of saltLength is the octet length of the hash value. Unlike the other fields of type RSASSA-PSS-params, saltLength does not need to be fixed for a given RSA key pair ๐Ÿ’œ
  • trailerField is the trailer field number, for compatibility with IEEE 1363a [IEEE1363A]. It SHALL be 1 for this version of the document, which represents the trailer field with hexadecimal value 0xbc. Other trailer fields (including the trailer field HashID || 0xcc in IEEE 1363a) are not supported in this document. Not supported, periodt ๐Ÿ™…โ€โ™€๏ธ
TrailerField ::= INTEGER { trailerFieldBC(1) }

If the default values of the hashAlgorithm, maskGenAlgorithm, and trailerField fields of RSASSA-PSS-params are used, then the algorithm identifier ends up looking like this. Main character energy ๐Ÿ‘‘

rSASSA-PSS-Default-Identifier    RSASSA-AlgorithmIdentifier ::= {
    algorithm   id-RSASSA-PSS,
    parameters  RSASSA-PSS-params : {
        hashAlgorithm       sha1,
        maskGenAlgorithm    mgf1SHA1,
        saltLength          20,
        trailerField        trailerFieldBC
    }
}

RSASSA-AlgorithmIdentifier ::= AlgorithmIdentifier {
    {PKCS1Algorithms}
}
Note: some apps identify the hash function separately from the rest of the signature scheme, which is kind of a lot ๐Ÿ™ƒ For example, in PKCS #7 [RFC2315], a hash function identifier goes before the message, and a "digest encryption" algorithm identifier (covering the rest of the operations) gets carried with the signature. So for PKCS #7 to support RSASSA-PSS, you'd need an OID defined for the operations after the hash function, kind of like the RSAEncryption OID for RSASSA-PKCS1-v1_5. S/MIME Cryptographic Message Syntax (CMS) [RFC5652] goes a different way. A hash function identifier still goes before the message, but an algorithm identifier for the full signature scheme may be carried with a CMS signature (this is done for DSA signatures). Following that pattern, the id-RSASSA-PSS OID can identify RSASSA-PSS signatures in CMS. CMS is considered the successor to PKCS #7, and new work like adding RSASSA-PSS support is going to happen in CMS rather than PKCS #7. So an OID for the "rest of" RSASSA-PSS isn't defined in this version of PKCS #1. Plot twist, but make it make sense ๐Ÿง 

A.2.4. RSASSA-PKCS-v1_5 ๐ŸŒˆ

The object identifier for RSASSA-PKCS1-v1_5 SHALL be one of the following โœจ Which one you get depends on the hash algorithm you picked: MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, or SHA-512/256. If you're using MD2 or MD5, the OID is just the same as in PKCS #1 v1.5, no drama ๐Ÿซถ For each OID, the parameters field tied to it inside an AlgorithmIdentifier value SHALL have a value of type NULL. The OID should be chosen in accordance with the following table ๐Ÿ’–

      Hash algorithm   OID
------------------------------------------------------------
MD2              md2WithRSAEncryption        ::= {pkcs-1 2}
MD5              md5WithRSAEncryption        ::= {pkcs-1 4}
SHA-1            sha1WithRSAEncryption       ::= {pkcs-1 5}
SHA-256          sha224WithRSAEncryption     ::= {pkcs-1 14}
SHA-256          sha256WithRSAEncryption     ::= {pkcs-1 11}
SHA-384          sha384WithRSAEncryption     ::= {pkcs-1 12}
SHA-512          sha512WithRSAEncryption     ::= {pkcs-1 13}
SHA-512/224      sha512-224WithRSAEncryption ::= {pkcs-1 15}
SHA-512/256      sha512-256WithRSAEncryption ::= {pkcs-1 16}

The EMSA-PKCS1-v1_5 encoding method includes an ASN.1 value of type DigestInfo, and the type DigestInfo has this syntax ๐ŸŽ€

DigestInfo ::= SEQUENCE {
    digestAlgorithm DigestAlgorithm,
    digest OCTET STRING
}

digestAlgorithm identifies the hash function, and it SHALL be an algorithm ID with an OID in the set PKCS1-v1-5DigestAlgorithms. For a chat about supported hash functions, check Appendix B.1 ๐Ÿฆ‹

DigestAlgorithm ::= AlgorithmIdentifier {
   {PKCS1-v1-5DigestAlgorithms}
}

PKCS1-v1-5DigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
    { OID id-md2        PARAMETERS NULL }|
    { OID id-md5        PARAMETERS NULL }|
    { OID id-sha1       PARAMETERS NULL }|
    { OID id-sha224     PARAMETERS NULL }|
    { OID id-sha256     PARAMETERS NULL }|
    { OID id-sha384     PARAMETERS NULL }|
    { OID id-sha512     PARAMETERS NULL }|
    { OID id-sha512-224 PARAMETERS NULL }|
    { OID id-sha512-256 PARAMETERS NULL }
}

Appendix B. Supporting Techniques โœจ

This section gives a few examples of the underlying functions that back up the encryption schemes in Section 7 and the encoding methods in Section 9. A range of techniques is included so existing apps stay compatible while people migrate to newer ones ๐ŸŒธ These supporting techniques are appropriate for applications to implement, but none of them is required to be implemented. Profiles for PKCS #1 v2.2 are expected to be developed that pin down particular supporting techniques ๐Ÿ’œ

This section also gives object identifiers for the supporting techniques ๐Ÿงš

B.1. Hash Functions ๐Ÿ”

Okay so hash functions show up in the operations in Sections 7 and 9, bestie ๐Ÿซถ They're deterministic, which just means the output is completely decided by the input. Same input, same output, every single time ๐Ÿ’… They take octet strings of variable length and spit out fixed-length octet strings. The hash functions in Sections 7 and 9 should generally be collision-resistant, meaning it's basically impossible to find two different inputs that give the same output ๐Ÿ˜ญ A collision-resistant hash is also one-way, so if you're handed an output, it's infeasible to find an input that hashes to it ๐Ÿ™ˆ On top of all that, the hash function should yield a mask generation function (Appendix B.2) with pseudorandom output โœจ

Nine hash functions are given as examples for the encoding methods in this document: MD2 [RFC1319] (which was retired by [RFC6149]), MD5 [RFC1321], SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 [SHS] ๐ŸŒˆ For the RSAES-OAEP encryption scheme and EMSA-PSS encoding method, only SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 are RECOMMENDED ๐Ÿ‘‘ For the EMSA-PKCS1-v1_5 encoding method, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 are RECOMMENDED for new applications ๐ŸŽ€ MD2, MD5, and SHA-1 are recommended only for compatibility with existing applications based on PKCS #1 v1.5 ๐Ÿฅบ

The object identifiers id-md2, id-md5, id-sha1, id-sha224, id-sha256, id-sha384, id-sha512, id-sha512/224, and id-sha512/256 identify the respective hash functions ๐Ÿฆ‹

    id-md2      OBJECT IDENTIFIER ::= {
        iso (1) member-body (2) us (840) rsadsi (113549)
        digestAlgorithm (2) 2
    }

    id-md5      OBJECT IDENTIFIER ::= {
        iso (1) member-body (2) us (840) rsadsi (113549)
        digestAlgorithm (2) 5
    }

    id-sha1    OBJECT IDENTIFIER ::= {
        iso(1) identified-organization(3) oiw(14) secsig(3)
         algorithms(2) 26
    }

    id-sha224    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 4
    }

    id-sha256    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 1
    }

    id-sha384    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 2
    }
    id-sha512    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 3
    }

    id-sha512-224    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 5
    }

    id-sha512-256    OBJECT IDENTIFIER ::= {
        joint-iso-itu-t (2) country (16) us (840) organization (1)
        gov (101) csor (3) nistalgorithm (4) hashalgs (2) 6
    }

The parameters field associated with these OIDs in a value of type AlgorithmIdentifier SHALL have a value of type NULL ๐Ÿ’–

The parameters field associated with id-md2 and id-md5 in a value of type AlgorithmIdentifier shall have a value of type NULL ๐Ÿ“

The parameters field associated with id-sha1, id-sha224, id-sha256, id-sha384, id-sha512, id-sha512/224, and id-sha512/256 should generally be omitted, but if present, it shall have a value of type NULL ๐Ÿงš

This is to line up with the definitions originally promulgated by NIST ๐Ÿ›๏ธ For the SHA algorithms, implementations MUST accept AlgorithmIdentifier values both without parameters and with NULL parameters ๐Ÿ™Œ

Exception: when formatting the DigestInfoValue in EMSA-PKCS1-v1_5 (see Section 9.2), the parameters field associated with id-sha1, id-sha224, id-sha256, id-sha384, id-sha512, id-sha512/224, and id-sha512/256 shall have a value of type NULL. This is to maintain compatibility with existing implementations and with the numeric information values already published for EMSA-PKCS1-v1_5, which are also reflected in IEEE 1363a [IEEE1363A] ๐Ÿ“š

Note: Version 1.5 of PKCS #1 also allowed for the use of MD4 in signature schemes. The cryptanalysis of MD4 has progressed significantly in the intervening years ๐Ÿ’€ For example, Dobbertin [MD4] demonstrated how to find collisions for MD4, and that the first two rounds of MD4 are not one-way [MD4FIRST]. Because of these results and others (e.g., [MD4LAST]), MD4 is NOT RECOMMENDED ๐Ÿšซ

Further advances have been made in the cryptanalysis of MD2 and MD5, especially after the findings of Stevens et al. [PREFIX] on chosen-prefix collisions on MD5 ๐Ÿ˜ญ MD2 and MD5 should be considered cryptographically broken and removed from existing applications. This version of the standard supports MD2 and MD5 just for backwards-compatibility reasons ๐Ÿฅ€

There have also been advances in the cryptanalysis of SHA-1 ๐Ÿซ  In particular, the results of Wang et al. [SHA1CRYPT] (which have been independently verified by M. Cochran in his analysis [COCHRAN]) on using a differential path to find collisions in SHA-1 conclude that the security strength of the SHA-1 hashing algorithm is significantly reduced. However, this reduction is not significant enough to warrant the removal of SHA-1 from existing applications, but its usage is only recommended for backwards-compatibility reasons ๐Ÿ•ฐ๏ธ

To address these concerns, only SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 are RECOMMENDED for new applications โœจ As of today, the best (known) collision attacks against these hash functions are generic attacks with complexity 2L/2, where L is the bit length of the hash output. For the signature schemes in this document, a collision attack is easily translated into a signature forgery. Therefore, the value L / 2 should be at least equal to the desired security level in bits of the signature scheme (a security level of B bits means that the best attack has complexity 2B). The same rule of thumb can be applied to RSAES-OAEP; it is RECOMMENDED that the bit length of the seed (which is equal to the bit length of the hash output) be twice the desired security level in bits ๐ŸŽฏ


B.2. Mask Generation Functions ๐ŸŽญ

A mask generation function takes an octet string of variable length and a desired output length as input, and outputs an octet string of the desired length. There may be restrictions on the length of the input and output octet strings, but such bounds are generally very large ๐ŸŒธ Mask generation functions are deterministic, so the octet string output is completely determined by the input octet string. The output of a mask generation function should be pseudorandom: given one part of the output but not the input, it should be infeasible to predict another part of the output ๐Ÿ”ฎ The provable security of RSAES-OAEP and RSASSA-PSS relies on the random nature of the output of the mask generation function, which in turn relies on the random nature of the underlying hash ๐Ÿง 

One mask generation function is given here: MGF1, which is based on a hash function. MGF1 coincides with the mask generation functions defined in IEEE 1363 [IEEE1363] and ANSI X9.44 [ANSIX944]. Future versions of this document may define other mask generation functions ๐Ÿฆ„


B.2.1. MGF1 ๐ŸŒท

MGF1 is a mask generation function based on a hash function ๐Ÿ’œ

MGF1 (mgfSeed, maskLen)

Options:

   Hash     hash function (hLen denotes the length in octets of
            the hash function output)

Input:

   mgfSeed  seed from which mask is generated, an octet string
   maskLen  intended length in octets of the mask, at most 2^32 hLen

Output:

   mask     mask, an octet string of length maskLen

Error: "mask too long"

Here are the steps, in order ๐Ÿช„

  1. If maskLen > 2^32 hLen, output "mask too long" and stop.
  2. Let T be the empty octet string.
  3. For counter from 0 to \ceil (maskLen / hLen) - 1, do the following:
    • A. Convert counter to an octet string C of length 4 octets (see Section 4.1):
C = I2OSP (counter, 4) .
  • B. Concatenate the hash of the seed mgfSeed and C to the octet string T:
T = T || Hash(mgfSeed || C) .
  1. Output the leading maskLen octets of T as the octet string mask.

The object identifier id-mgf1 identifies the MGF1 mask generation function ๐Ÿท๏ธ

   id-mgf1    OBJECT IDENTIFIER ::= { pkcs-1 8 }

The parameters field associated with this OID in a value of type AlgorithmIdentifier shall have a value of type hashAlgorithm, identifying the hash function on which MGF1 is based ๐ŸŒŸ


Appendix C. ASN.1 Module ๐Ÿงฉ

Here's the ASN.1 module, bestie. Everything below is copied exactly as it appears in the document ๐Ÿซถ

-- PKCS #1 v2.2 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

PKCS-1 {
    iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)
    modules(0) pkcs-1(1)
}

DEFINITIONS EXPLICIT TAGS ::=

BEGIN

-- EXPORTS ALL
-- All types and values defined in this module are exported for use
-- in other ASN.1 modules.

IMPORTS

id-sha224, id-sha256, id-sha384, id-sha512, id-sha512-224,
id-sha512-256
    FROM NIST-SHA2 {
        joint-iso-itu-t(2) country(16) us(840) organization(1)
        gov(101) csor(3) nistalgorithm(4) hashAlgs(2)
    };

-- ============================
--   Basic object identifiers
-- ============================

-- The DER encoding of this in hexadecimal is:
-- (0x)06 08
--        2A 86 48 86 F7 0D 01 01
--
pkcs-1    OBJECT IDENTIFIER ::= {
    iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1
}

--
-- When rsaEncryption is used in an AlgorithmIdentifier,
-- the parameters MUST be present and MUST be NULL.
--
rsaEncryption    OBJECT IDENTIFIER ::= { pkcs-1 1 }

--
-- When id-RSAES-OAEP is used in an AlgorithmIdentifier, the
-- parameters MUST be present and MUST be RSAES-OAEP-params.
--
id-RSAES-OAEP    OBJECT IDENTIFIER ::= { pkcs-1 7 }

--
-- When id-pSpecified is used in an AlgorithmIdentifier, the
-- parameters MUST be an OCTET STRING.
--
id-pSpecified    OBJECT IDENTIFIER ::= { pkcs-1 9 }

--
-- When id-RSASSA-PSS is used in an AlgorithmIdentifier, the
-- parameters MUST be present and MUST be RSASSA-PSS-params.
--
id-RSASSA-PSS    OBJECT IDENTIFIER ::= { pkcs-1 10 }

--
-- When the following OIDs are used in an AlgorithmIdentifier,
-- the parameters MUST be present and MUST be NULL.
--
md2WithRSAEncryption         OBJECT IDENTIFIER ::= { pkcs-1 2 }
md5WithRSAEncryption         OBJECT IDENTIFIER ::= { pkcs-1 4 }
sha1WithRSAEncryption        OBJECT IDENTIFIER ::= { pkcs-1 5 }
sha224WithRSAEncryption      OBJECT IDENTIFIER ::= { pkcs-1 14 }
sha256WithRSAEncryption      OBJECT IDENTIFIER ::= { pkcs-1 11 }
sha384WithRSAEncryption      OBJECT IDENTIFIER ::= { pkcs-1 12 }
sha512WithRSAEncryption      OBJECT IDENTIFIER ::= { pkcs-1 13 }
sha512-224WithRSAEncryption  OBJECT IDENTIFIER ::= { pkcs-1 15 }
sha512-256WithRSAEncryption  OBJECT IDENTIFIER ::= { pkcs-1 16 }

--
-- This OID really belongs in a module with the secsig OIDs.
--
id-sha1    OBJECT IDENTIFIER ::= {
    iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2)
    26
}

--
-- OIDs for MD2 and MD5, allowed only in EMSA-PKCS1-v1_5.
--
id-md2 OBJECT IDENTIFIER ::= {
       iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2
   }

   id-md5 OBJECT IDENTIFIER ::= {
       iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5
   }

   --
   -- When id-mgf1 is used in an AlgorithmIdentifier, the parameters
   -- MUST be present and MUST be a HashAlgorithm, for example, sha1.
   --
   id-mgf1    OBJECT IDENTIFIER ::= { pkcs-1 8 }

   -- ================
   --   Useful types
   -- ================

   ALGORITHM-IDENTIFIER ::= CLASS {
       &id    OBJECT IDENTIFIER  UNIQUE,
       &Type  OPTIONAL
   }
       WITH SYNTAX { OID &id [PARAMETERS &Type] }

   -- Note: the parameter InfoObjectSet in the following definitions
   -- allows a distinct information object set to be specified for sets
   -- of algorithms such as:
   -- DigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
   --     { OID id-md2  PARAMETERS NULL }|
   --     { OID id-md5  PARAMETERS NULL }|
   --     { OID id-sha1 PARAMETERS NULL }
   -- }
   --

   AlgorithmIdentifier { ALGORITHM-IDENTIFIER:InfoObjectSet } ::=
       SEQUENCE {
         algorithm
             ALGORITHM-IDENTIFIER.&id({InfoObjectSet}),
         parameters
             ALGORITHM-IDENTIFIER.&Type({InfoObjectSet}{@.algorithm})
               OPTIONAL
   }

   -- ==============
   --   Algorithms
   -- ==============

   --
   -- Allowed EME-OAEP and EMSA-PSS digest algorithms.

   --
   OAEP-PSSDigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
       { OID id-sha1       PARAMETERS NULL }|
       { OID id-sha224     PARAMETERS NULL }|
       { OID id-sha256     PARAMETERS NULL }|
       { OID id-sha384     PARAMETERS NULL }|
       { OID id-sha512     PARAMETERS NULL }|
       { OID id-sha512-224 PARAMETERS NULL }|
       { OID id-sha512-256 PARAMETERS NULL },
       ...  -- Allows for future expansion --
   }

   --
   -- Allowed EMSA-PKCS1-v1_5 digest algorithms.
   --
   PKCS1-v1-5DigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
       { OID id-md2        PARAMETERS NULL }|
       { OID id-md5        PARAMETERS NULL }|
       { OID id-sha1       PARAMETERS NULL }|
       { OID id-sha224     PARAMETERS NULL }|
       { OID id-sha256     PARAMETERS NULL }|
       { OID id-sha384     PARAMETERS NULL }|
       { OID id-sha512     PARAMETERS NULL }|
       { OID id-sha512-224 PARAMETERS NULL }|
       { OID id-sha512-256 PARAMETERS NULL }
   }

   -- When id-md2 and id-md5 are used in an AlgorithmIdentifier, the
   -- parameters field shall have a value of type NULL.

   -- When id-sha1, id-sha224, id-sha256, id-sha384, id-sha512,
   -- id-sha512-224, and id-sha512-256 are used in an
   -- AlgorithmIdentifier, the parameters (which are optional) SHOULD be
   -- omitted, but if present, they SHALL have a value of type NULL.
   -- However, implementations MUST accept AlgorithmIdentifier values
   -- both without parameters and with NULL parameters.

   -- Exception: When formatting the DigestInfoValue in EMSA-PKCS1-v1_5
   -- (see Section 9.2), the parameters field associated with id-sha1,
   -- id-sha224, id-sha256, id-sha384, id-sha512, id-sha512-224, and
   -- id-sha512-256 SHALL have a value of type NULL.  This is to
   -- maintain compatibility with existing implementations and with the
   -- numeric information values already published for EMSA-PKCS1-v1_5,
   -- which are also reflected in IEEE 1363a.

   sha1    HashAlgorithm ::= {
       algorithm   id-sha1,
       parameters  SHA1Parameters : NULL

   }

   HashAlgorithm ::= AlgorithmIdentifier { {OAEP-PSSDigestAlgorithms} }

   SHA1Parameters ::= NULL

   --
   -- Allowed mask generation function algorithms.
   -- If the identifier is id-mgf1, the parameters are a HashAlgorithm.
   --
   PKCS1MGFAlgorithms    ALGORITHM-IDENTIFIER ::= {
       { OID id-mgf1 PARAMETERS HashAlgorithm },
       ...  -- Allows for future expansion --
   }

   --
   -- Default AlgorithmIdentifier for id-RSAES-OAEP.maskGenAlgorithm and
   -- id-RSASSA-PSS.maskGenAlgorithm.
   --
   mgf1SHA1    MaskGenAlgorithm ::= {
       algorithm   id-mgf1,
       parameters  HashAlgorithm : sha1
   }

   MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }

   --
   -- Allowed algorithms for pSourceAlgorithm.
   --
   PKCS1PSourceAlgorithms    ALGORITHM-IDENTIFIER ::= {
       { OID id-pSpecified PARAMETERS EncodingParameters },
       ...  -- Allows for future expansion --
   }

   EncodingParameters ::= OCTET STRING(SIZE(0..MAX))

   --
   -- This identifier means that the label L is an empty string, so the
   -- digest of the empty string appears in the RSA block before
   -- masking.
   --

   pSpecifiedEmpty    PSourceAlgorithm ::= {
       algorithm   id-pSpecified,
       parameters  EncodingParameters : emptyString
   }

   PSourceAlgorithm ::= AlgorithmIdentifier { {PKCS1PSourceAlgorithms} }
   emptyString    EncodingParameters ::= ''H

   --
   -- Type identifier definitions for the PKCS #1 OIDs.
   --
   PKCS1Algorithms    ALGORITHM-IDENTIFIER ::= {
       { OID rsaEncryption                PARAMETERS NULL } |
       { OID md2WithRSAEncryption         PARAMETERS NULL } |
       { OID md5WithRSAEncryption         PARAMETERS NULL } |
       { OID sha1WithRSAEncryption        PARAMETERS NULL } |
       { OID sha224WithRSAEncryption      PARAMETERS NULL } |
       { OID sha256WithRSAEncryption      PARAMETERS NULL } |
       { OID sha384WithRSAEncryption      PARAMETERS NULL } |
       { OID sha512WithRSAEncryption      PARAMETERS NULL } |
       { OID sha512-224WithRSAEncryption  PARAMETERS NULL } |
       { OID sha512-256WithRSAEncryption  PARAMETERS NULL } |
       { OID id-RSAES-OAEP   PARAMETERS RSAES-OAEP-params } |
       PKCS1PSourceAlgorithms                               |
       { OID id-RSASSA-PSS   PARAMETERS RSASSA-PSS-params },
       ...  -- Allows for future expansion --
   }

   -- ===================
   --   Main structures
   -- ===================

   RSAPublicKey ::= SEQUENCE {
       modulus           INTEGER,  -- n
       publicExponent    INTEGER   -- e
   }

   --
   -- Representation of RSA private key with information for the CRT
   -- algorithm.
   --
   RSAPrivateKey ::= SEQUENCE {
       version           Version,
       modulus           INTEGER,  -- n
       publicExponent    INTEGER,  -- e
       privateExponent   INTEGER,  -- d
       prime1            INTEGER,  -- p
       prime2            INTEGER,  -- q
       exponent1         INTEGER,  -- d mod (p-1)
       exponent2         INTEGER,  -- d mod (q-1)
       coefficient       INTEGER,  -- (inverse of q) mod p
       otherPrimeInfos   OtherPrimeInfos OPTIONAL
   }
   Version ::= INTEGER { two-prime(0), multi(1) }
       (CONSTRAINED BY
         {-- version MUST
    be multi if otherPrimeInfos present --})

   OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo


   OtherPrimeInfo ::= SEQUENCE {
       prime             INTEGER,  -- ri
       exponent          INTEGER,  -- di
       coefficient       INTEGER   -- ti
   }

   --
   -- AlgorithmIdentifier.parameters for id-RSAES-OAEP.
   -- Note that the tags in this Sequence are explicit.
   --
   RSAES-OAEP-params ::= SEQUENCE {
       hashAlgorithm      [0] HashAlgorithm     DEFAULT sha1,
       maskGenAlgorithm   [1] MaskGenAlgorithm  DEFAULT mgf1SHA1,
       pSourceAlgorithm   [2] PSourceAlgorithm  DEFAULT pSpecifiedEmpty
   }

   --
   -- Identifier for default RSAES-OAEP algorithm identifier.
   -- The DER encoding of this is in hexadecimal:
   -- (0x)30 0D
   --        06 09
   --           2A 86 48 86 F7 0D 01 01 07
   --        30 00
   -- Notice that the DER encoding of default values is "empty".
   --

   rSAES-OAEP-Default-Identifier    RSAES-AlgorithmIdentifier ::= {
       algorithm   id-RSAES-OAEP,
       parameters  RSAES-OAEP-params : {
           hashAlgorithm       sha1,
           maskGenAlgorithm    mgf1SHA1,
           pSourceAlgorithm    pSpecifiedEmpty
       }
   }

   RSAES-AlgorithmIdentifier ::= AlgorithmIdentifier {
       {PKCS1Algorithms}
   }

   --
   -- AlgorithmIdentifier.parameters for id-RSASSA-PSS.
   -- Note that the tags in this Sequence are explicit.
   --
   RSASSA-PSS-params ::= SEQUENCE {
       hashAlgorithm      [0] HashAlgorithm      DEFAULT sha1,
       maskGenAlgorithm   [1] MaskGenAlgorithm   DEFAULT mgf1SHA1,
       saltLength         [2] INTEGER            DEFAULT 20,
       trailerField       [3] TrailerField       DEFAULT trailerFieldBC
   }

   TrailerField ::= INTEGER { trailerFieldBC(1) }

   --
   -- Identifier for default RSASSA-PSS algorithm identifier
   -- The DER encoding of this is in hexadecimal:
   -- (0x)30 0D
   --        06 09
   --           2A 86 48 86 F7 0D 01 01 0A
   --        30 00
   -- Notice that the DER encoding of default values is "empty".
   --
   rSASSA-PSS-Default-Identifier    RSASSA-AlgorithmIdentifier ::= {
       algorithm   id-RSASSA-PSS,
       parameters  RSASSA-PSS-params : {
           hashAlgorithm       sha1,
           maskGenAlgorithm    mgf1SHA1,
           saltLength          20,
           trailerField        trailerFieldBC
       }
   }

   RSASSA-AlgorithmIdentifier ::= AlgorithmIdentifier {
       {PKCS1Algorithms}
   }

   --
   -- Syntax for the EMSA-PKCS1-v1_5 hash identifier.
   --
   DigestInfo ::= SEQUENCE {
       digestAlgorithm DigestAlgorithm,
       digest OCTET STRING
   }

   DigestAlgorithm ::= AlgorithmIdentifier {
       {PKCS1-v1-5DigestAlgorithms}
   }

   END

Appendix D. Revision History of PKCS #1 โœจ

Okay so this is the glow-up timeline for PKCS #1 ๐Ÿ’– It's giving history book, but make it iconic.

Versions 1.0 - 1.5 ๐ŸŒธ

Versions 1.0 through 1.3 were passed around to folks at RSA Data Security, Inc.'s Public-Key Cryptography Standards meetings back in February and March 1991. Version 1.4 was part of the initial public release of PKCS on June 3, 1991, and it was published as NIST/OSI Implementors' Workshop document SEC-SIG-91-18 ๐Ÿงš

Version 1.5 got a bunch of editorial touch-ups, like updated references and a shiny new revision history. The substantive changes were:

  • Section 10: the "MD4 with RSA" signature and verification processes were added.
  • Section 11: the md4WithRSAEncryption object identifier was added.

Version 1.5 was republished as [RFC2313] (which was later obsoleted by [RFC2437]). โœจ

Version 2.0 ๐Ÿ‘‘

Version 2.0 was a major editorial makeover, restructuring the whole document and introducing the RSAES-OAEP encryption scheme ๐Ÿ”ฅ It kept supporting the encryption and signature processes from version 1.5, but MD4 was no longer allowed because cryptanalytic advances over the intervening years made it a no-go ๐Ÿ’€ Version 2.0 was republished as [RFC2437] (which was later obsoleted by [RFC3447]).

Version 2.1 ๐Ÿฆ‹

Version 2.1 brought in multi-prime RSA and the RSASSA-PSS signature scheme with appendix, plus a bunch of editorial improvements. It kept supporting everything from version 2.0 too. Version 2.1 was republished as [RFC3447].

Version 2.2 ๐ŸŒˆ

Version 2.2 updates the list of allowed hashing algorithms so they line up with FIPS 180-4 [SHS] ๐Ÿ’… That means SHA-224, SHA-512/224, and SHA-512/256 are now in the mix. The substantive changes were:

  • Object identifiers for sha224WithRSAEncryption, sha512-224WithRSAEncryption, and sha512-256WithRSAEncryption were added.
  • This version continues to support the schemes in version 2.1. ๐Ÿซถ

Appendix E. About PKCS

Okay so this part is the wrap-up, and it's giving "behind the scenes" ๐ŸŽฌโœจ The Public-Key Cryptography Standards (PKCS) are specs made by RSA Laboratories, working with secure systems developers all over the world, to help public-key cryptography get deployed faster ๐Ÿš€๐Ÿ”. The PKCS docs first came out in 1991 after meetings with a small group of early adopters of public-key tech, and they've become seriously widely referenced and implemented ๐Ÿ’…. Bestie, their stuff ended up inside a bunch of formal and de facto standards ๐ŸŒˆ, including ANSI X9 and IEEE P1363 documents, PKIX, Secure Electronic Transaction (SET), S/MIME, SSL/TLS, and Wireless Application Protocol (WAP) / WAP Transport Layer Security (WTLS) ๐Ÿ˜ญ๐Ÿซถ.

Further development of most PKCS documents happens through the IETF ๐ŸŒธ, and suggestions for improvement are welcome ๐Ÿ’–.

Acknowledgements

This document is based on a contribution of RSA Laboratories, the research center of RSA Security Inc. ๐ŸŽ€โœจ

Authors' Addresses

Kathleen M. Moriarty (editor)

Kathleen is the editor, and she's at EMC Corporation ๐Ÿ’ผ:

Kathleen M. Moriarty (editor)
EMC Corporation
176 South Street
Hopkinton, MA  01748
United States of America

Email: kathleen.moriarty@emc.com

Burt Kaliski

Burt's at Verisign ๐Ÿฆ‹:

Burt Kaliski
Verisign
12061 Bluemont Way
Reston, VA  20190
United States of America

Email: bkaliski@verisign.com
URI:   http://verisignlabs.com

Jakob Jonsson

Jakob's at Subset AB in Stockholm ๐Ÿงš:

Jakob Jonsson
Subset AB
Munkbrogtan 4
Stockholm  SE-11127
Sweden

Phone: +46 8 428 687 43
Email: jakob.jonsson@subset.se

Andreas Rusch

Andreas is at RSA in Brisbane ๐Ÿ“:

Andreas Rusch
RSA
345 Queen Street
Brisbane, QLD  4000
Australia

Email: andreas.rusch@rsa.com
๐Ÿ“ฆ where this page comes from