Home | History | Annotate | Line # | Download | only in ref
      1  1.1  agc 
      2  1.1  agc 
      3  1.1  agc 
      4  1.1  agc 
      5  1.1  agc 
      6  1.1  agc 
      7  1.1  agc Network Working Group                                         B. Kaliski
      8  1.1  agc Request for Comments: 2437                                    J. Staddon
      9  1.1  agc Obsoletes: 2313                                         RSA Laboratories
     10  1.1  agc Category: Informational                                     October 1998
     11  1.1  agc 
     12  1.1  agc 
     13  1.1  agc                 PKCS #1: RSA Cryptography Specifications
     14  1.1  agc                               Version 2.0
     15  1.1  agc 
     16  1.1  agc Status of this Memo
     17  1.1  agc 
     18  1.1  agc    This memo provides information for the Internet community.  It does
     19  1.1  agc    not specify an Internet standard of any kind.  Distribution of this
     20  1.1  agc    memo is unlimited.
     21  1.1  agc 
     22  1.1  agc Copyright Notice
     23  1.1  agc 
     24  1.1  agc    Copyright (C) The Internet Society (1998).  All Rights Reserved.
     25  1.1  agc 
     26  1.1  agc Table of Contents
     27  1.1  agc 
     28  1.1  agc    1.       Introduction.....................................2
     29  1.1  agc    1.1      Overview.........................................3
     30  1.1  agc    2.       Notation.........................................3
     31  1.1  agc    3.       Key types........................................5
     32  1.1  agc    3.1      RSA public key...................................5
     33  1.1  agc    3.2      RSA private key..................................5
     34  1.1  agc    4.       Data conversion primitives.......................6
     35  1.1  agc    4.1      I2OSP............................................6
     36  1.1  agc    4.2      OS2IP............................................7
     37  1.1  agc    5.       Cryptographic primitives.........................8
     38  1.1  agc    5.1      Encryption and decryption primitives.............8
     39  1.1  agc    5.1.1    RSAEP............................................8
     40  1.1  agc    5.1.2    RSADP............................................9
     41  1.1  agc    5.2      Signature and verification primitives...........10
     42  1.1  agc    5.2.1    RSASP1..........................................10
     43  1.1  agc    5.2.2    RSAVP1..........................................11
     44  1.1  agc    6.       Overview of schemes.............................11
     45  1.1  agc    7.       Encryption schemes..............................12
     46  1.1  agc    7.1      RSAES-OAEP......................................13
     47  1.1  agc    7.1.1    Encryption operation............................13
     48  1.1  agc    7.1.2    Decryption operation............................14
     49  1.1  agc    7.2      RSAES-PKCS1-v1_5................................15
     50  1.1  agc    7.2.1    Encryption operation............................17
     51  1.1  agc    7.2.2    Decryption operation............................17
     52  1.1  agc    8.       Signature schemes with appendix.................18
     53  1.1  agc    8.1      RSASSA-PKCS1-v1_5...............................19
     54  1.1  agc    8.1.1    Signature generation operation..................20
     55  1.1  agc 
     56  1.1  agc 
     57  1.1  agc 
     58  1.1  agc Kaliski & Staddon            Informational                      [Page 1]
     59  1.1  agc 
     61  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
     62  1.1  agc 
     63  1.1  agc 
     64  1.1  agc    8.1.2    Signature verification operation................21
     65  1.1  agc    9.       Encoding methods................................22
     66  1.1  agc    9.1      Encoding methods for encryption.................22
     67  1.1  agc    9.1.1    EME-OAEP........................................22
     68  1.1  agc    9.1.2    EME-PKCS1-v1_5..................................24
     69  1.1  agc    9.2      Encoding methods for signatures with appendix...26
     70  1.1  agc    9.2.1    EMSA-PKCS1-v1_5.................................26
     71  1.1  agc    10.      Auxiliary Functions.............................27
     72  1.1  agc    10.1     Hash Functions..................................27
     73  1.1  agc    10.2     Mask Generation Functions.......................28
     74  1.1  agc    10.2.1   MGF1............................................28
     75  1.1  agc    11.      ASN.1 syntax....................................29
     76  1.1  agc    11.1     Key representation..............................29
     77  1.1  agc    11.1.1   Public-key syntax...............................30
     78  1.1  agc    11.1.2   Private-key syntax..............................30
     79  1.1  agc    11.2     Scheme identification...........................31
     80  1.1  agc    11.2.1   Syntax for RSAES-OAEP...........................31
     81  1.1  agc    11.2.2   Syntax for RSAES-PKCS1-v1_5.....................32
     82  1.1  agc    11.2.3   Syntax for RSASSA-PKCS1-v1_5....................33
     83  1.1  agc    12       Patent Statement................................33
     84  1.1  agc    12.1     Patent statement for the RSA algorithm..........34
     85  1.1  agc    13.      Revision history................................35
     86  1.1  agc    14.      References......................................35
     87  1.1  agc             Security Considerations.........................37
     88  1.1  agc             Acknowledgements................................37
     89  1.1  agc             Authors' Addresses..............................38
     90  1.1  agc             Full Copyright Statement........................39
     91  1.1  agc 
     92  1.1  agc 1. Introduction
     93  1.1  agc 
     94  1.1  agc    This memo is the successor to RFC 2313. This document provides
     95  1.1  agc    recommendations for the implementation of public-key cryptography
     96  1.1  agc    based on the RSA algorithm [18], covering the following aspects:
     97  1.1  agc 
     98  1.1  agc       -cryptographic primitives
     99  1.1  agc       -encryption schemes
    100  1.1  agc       -signature schemes with appendix
    101  1.1  agc       -ASN.1 syntax for representing keys and for identifying the
    102  1.1  agc        schemes
    103  1.1  agc 
    104  1.1  agc    The recommendations are intended for general application within
    105  1.1  agc    computer and communications systems, and as such include a fair
    106  1.1  agc    amount of flexibility. It is expected that application standards
    107  1.1  agc    based on these specifications may include additional constraints. The
    108  1.1  agc    recommendations are intended to be compatible with draft standards
    109  1.1  agc    currently being developed by the ANSI X9F1 [1] and IEEE P1363 working
    110  1.1  agc    groups [14].  This document supersedes PKCS #1 version 1.5 [20].
    111  1.1  agc 
    112  1.1  agc 
    113  1.1  agc 
    114  1.1  agc 
    115  1.1  agc Kaliski & Staddon            Informational                      [Page 2]
    116  1.1  agc 
    118  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    119  1.1  agc 
    120  1.1  agc 
    121  1.1  agc    Editor's note. It is expected that subsequent versions of PKCS #1 may
    122  1.1  agc    cover other aspects of the RSA algorithm such as key size, key
    123  1.1  agc    generation, key validation, and signature schemes with message
    124  1.1  agc    recovery.
    125  1.1  agc 
    126  1.1  agc 1.1 Overview
    127  1.1  agc 
    128  1.1  agc    The organization of this document is as follows:
    129  1.1  agc 
    130  1.1  agc       -Section 1 is an introduction.
    131  1.1  agc       -Section 2 defines some notation used in this document.
    132  1.1  agc       -Section 3 defines the RSA public and private key types.
    133  1.1  agc       -Sections 4 and 5 define several primitives, or basic mathematical
    134  1.1  agc        operations. Data conversion primitives are in Section 4, and
    135  1.1  agc        cryptographic primitives (encryption-decryption,
    136  1.1  agc        signature-verification) are in Section 5.
    137  1.1  agc       -Section 6, 7 and 8 deal with the encryption and signature schemes
    138  1.1  agc        in this document. Section 6 gives an overview. Section 7 defines
    139  1.1  agc        an OAEP-based [2] encryption scheme along with the method found
    140  1.1  agc        in PKCS #1 v1.5.  Section 8 defines a signature scheme with
    141  1.1  agc        appendix; the method is identical to that of PKCS #1 v1.5.
    142  1.1  agc       -Section 9 defines the encoding methods for the encryption and
    143  1.1  agc        signature schemes in Sections 7 and 8.
    144  1.1  agc       -Section 10 defines the hash functions and the mask generation
    145  1.1  agc        function used in this document.
    146  1.1  agc       -Section 11 defines the ASN.1 syntax for the keys defined in
    147  1.1  agc        Section 3 and the schemes gives in Sections 7 and 8.
    148  1.1  agc       -Section 12 outlines the revision history of PKCS #1.
    149  1.1  agc       -Section 13 contains references to other publications and
    150  1.1  agc        standards.
    151  1.1  agc 
    152  1.1  agc 2. Notation
    153  1.1  agc 
    154  1.1  agc    (n, e)        RSA public key
    155  1.1  agc 
    156  1.1  agc    c             ciphertext representative, an integer between 0 and n-1
    157  1.1  agc 
    158  1.1  agc    C             ciphertext, an octet string
    159  1.1  agc 
    160  1.1  agc    d             private exponent
    161  1.1  agc 
    162  1.1  agc    dP            p's exponent, a positive integer such that:
    163  1.1  agc                   e(dP)\equiv 1 (mod(p-1))
    164  1.1  agc 
    165  1.1  agc    dQ            q's exponent, a positive integer such that:
    166  1.1  agc                   e(dQ)\equiv 1 (mod(q-1))
    167  1.1  agc 
    168  1.1  agc    e             public exponent
    169  1.1  agc 
    170  1.1  agc 
    171  1.1  agc 
    172  1.1  agc Kaliski & Staddon            Informational                      [Page 3]
    173  1.1  agc 
    175  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    176  1.1  agc 
    177  1.1  agc 
    178  1.1  agc    EM            encoded message, an octet string
    179  1.1  agc 
    180  1.1  agc    emLen         intended length in octets of an encoded message
    181  1.1  agc 
    182  1.1  agc    H             hash value, an output of Hash
    183  1.1  agc 
    184  1.1  agc    Hash          hash function
    185  1.1  agc 
    186  1.1  agc    hLen          output length in octets of hash function Hash
    187  1.1  agc 
    188  1.1  agc    K             RSA private key
    189  1.1  agc 
    190  1.1  agc    k             length in octets of the modulus
    191  1.1  agc 
    192  1.1  agc    l             intended length of octet string
    193  1.1  agc 
    194  1.1  agc    lcm(.,.)      least common multiple of two
    195  1.1  agc                  nonnegative integers
    196  1.1  agc 
    197  1.1  agc    m             message representative, an integer between
    198  1.1  agc                  0 and n-1
    199  1.1  agc 
    200  1.1  agc    M             message, an octet string
    201  1.1  agc 
    202  1.1  agc    MGF           mask generation function
    203  1.1  agc 
    204  1.1  agc    n             modulus
    205  1.1  agc 
    206  1.1  agc    P             encoding parameters, an octet string
    207  1.1  agc 
    208  1.1  agc    p,q           prime factors of the modulus
    209  1.1  agc 
    210  1.1  agc    qInv          CRT coefficient, a positive integer less
    211  1.1  agc                  than p such: q(qInv)\equiv 1 (mod p)
    212  1.1  agc 
    213  1.1  agc    s             signature representative, an integer
    214  1.1  agc                  between 0 and n-1
    215  1.1  agc 
    216  1.1  agc    S             signature, an octet string
    217  1.1  agc 
    218  1.1  agc    x             a nonnegative integer
    219  1.1  agc 
    220  1.1  agc    X             an octet string corresponding to x
    221  1.1  agc 
    222  1.1  agc    \xor          bitwise exclusive-or of two octet strings
    223  1.1  agc 
    224  1.1  agc    \lambda(n)    lcm(p-1, q-1), where n = pq
    225  1.1  agc 
    226  1.1  agc 
    227  1.1  agc 
    228  1.1  agc 
    229  1.1  agc Kaliski & Staddon            Informational                      [Page 4]
    230  1.1  agc 
    232  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    233  1.1  agc 
    234  1.1  agc 
    235  1.1  agc    ||            concatenation operator
    236  1.1  agc 
    237  1.1  agc    ||.||         octet length operator
    238  1.1  agc 
    239  1.1  agc 3. Key types
    240  1.1  agc 
    241  1.1  agc    Two key types are employed in the primitives and schemes defined in
    242  1.1  agc    this document: RSA public key and RSA private key. Together, an RSA
    243  1.1  agc    public key and an RSA private key form an RSA key pair.
    244  1.1  agc 
    245  1.1  agc 3.1 RSA public key
    246  1.1  agc 
    247  1.1  agc    For the purposes of this document, an RSA public key consists of two
    248  1.1  agc    components:
    249  1.1  agc 
    250  1.1  agc    n, the modulus, a nonnegative integer
    251  1.1  agc    e, the public exponent, a nonnegative integer
    252  1.1  agc 
    253  1.1  agc    In a valid RSA public key, the modulus n is a product of two odd
    254  1.1  agc    primes p and q, and the public exponent e is an integer between 3 and
    255  1.1  agc    n-1 satisfying gcd (e, \lambda(n)) = 1, where \lambda(n) = lcm (p-
    256  1.1  agc    1,q-1).  A recommended syntax for interchanging RSA public keys
    257  1.1  agc    between implementations is given in Section 11.1.1; an
    258  1.1  agc    implementation's internal representation may differ.
    259  1.1  agc 
    260  1.1  agc 3.2 RSA private key
    261  1.1  agc 
    262  1.1  agc    For the purposes of this document, an RSA private key may have either
    263  1.1  agc    of two representations.
    264  1.1  agc 
    265  1.1  agc    1. The first representation consists of the pair (n, d), where the
    266  1.1  agc    components have the following meanings:
    267  1.1  agc 
    268  1.1  agc    n, the modulus, a nonnegative integer
    269  1.1  agc    d, the private exponent, a nonnegative integer
    270  1.1  agc 
    271  1.1  agc    2. The second representation consists of a quintuple (p, q, dP, dQ,
    272  1.1  agc    qInv), where the components have the following meanings:
    273  1.1  agc 
    274  1.1  agc    p, the first factor, a nonnegative integer
    275  1.1  agc    q, the second factor, a nonnegative integer
    276  1.1  agc    dP, the first factor's exponent, a nonnegative integer
    277  1.1  agc    dQ, the second factor's exponent, a nonnegative integer
    278  1.1  agc    qInv, the CRT coefficient, a nonnegative integer
    279  1.1  agc 
    280  1.1  agc    In a valid RSA private key with the first representation, the modulus
    281  1.1  agc    n is the same as in the corresponding public key and is the product
    282  1.1  agc    of two odd primes p and q, and the private exponent d is a positive
    283  1.1  agc 
    284  1.1  agc 
    285  1.1  agc 
    286  1.1  agc Kaliski & Staddon            Informational                      [Page 5]
    287  1.1  agc 
    289  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    290  1.1  agc 
    291  1.1  agc 
    292  1.1  agc    integer less than n satisfying:
    293  1.1  agc 
    294  1.1  agc    ed \equiv 1 (mod \lambda(n))
    295  1.1  agc 
    296  1.1  agc    where e is the corresponding public exponent and \lambda(n) is as
    297  1.1  agc    defined above.
    298  1.1  agc 
    299  1.1  agc    In a valid RSA private key with the second representation, the two
    300  1.1  agc    factors p and q are the prime factors of the modulus n, the exponents
    301  1.1  agc    dP and dQ are positive integers less than p and q respectively
    302  1.1  agc    satisfying
    303  1.1  agc 
    304  1.1  agc    e(dP)\equiv 1(mod(p-1))
    305  1.1  agc    e(dQ)\equiv 1(mod(q-1)),
    306  1.1  agc 
    307  1.1  agc    and the CRT coefficient qInv is a positive integer less than p
    308  1.1  agc    satisfying:
    309  1.1  agc 
    310  1.1  agc    q(qInv)\equiv 1 (mod p).
    311  1.1  agc 
    312  1.1  agc    A recommended syntax for interchanging RSA private keys between
    313  1.1  agc    implementations, which includes components from both representations,
    314  1.1  agc    is given in Section 11.1.2; an implementation's internal
    315  1.1  agc    representation may differ.
    316  1.1  agc 
    317  1.1  agc 4. Data conversion primitives
    318  1.1  agc 
    319  1.1  agc    Two data conversion primitives are employed in the schemes defined in
    320  1.1  agc    this document:
    321  1.1  agc 
    322  1.1  agc    I2OSP: Integer-to-Octet-String primitive
    323  1.1  agc    OS2IP: Octet-String-to-Integer primitive
    324  1.1  agc 
    325  1.1  agc    For the purposes of this document, and consistent with ASN.1 syntax, an
    326  1.1  agc    octet string is an ordered sequence of octets (eight-bit bytes). The
    327  1.1  agc    sequence is indexed from first (conventionally, leftmost) to last
    328  1.1  agc    (rightmost). For purposes of conversion to and from integers, the first
    329  1.1  agc    octet is considered the most significant in the following conversion
    330  1.1  agc    primitives
    331  1.1  agc 
    332  1.1  agc 4.1 I2OSP
    333  1.1  agc 
    334  1.1  agc    I2OSP converts a nonnegative integer to an octet string of a specified
    335  1.1  agc    length.
    336  1.1  agc 
    337  1.1  agc    I2OSP (x, l)
    338  1.1  agc 
    339  1.1  agc 
    340  1.1  agc 
    341  1.1  agc 
    342  1.1  agc 
    343  1.1  agc Kaliski & Staddon            Informational                      [Page 6]
    344  1.1  agc 
    346  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    347  1.1  agc 
    348  1.1  agc 
    349  1.1  agc    Input:
    350  1.1  agc    x         nonnegative integer to be converted
    351  1.1  agc    l         intended length of the resulting octet string
    352  1.1  agc 
    353  1.1  agc    Output:
    354  1.1  agc    X         corresponding octet string of length l; or
    355  1.1  agc              "integer too large"
    356  1.1  agc 
    357  1.1  agc    Steps:
    358  1.1  agc 
    359  1.1  agc    1. If x>=256^l, output "integer too large" and stop.
    360  1.1  agc 
    361  1.1  agc    2. Write the integer x in its unique l-digit representation base 256:
    362  1.1  agc 
    363  1.1  agc    x = x_{l-1}256^{l-1} + x_{l-2}256^{l-2} +... + x_1 256 + x_0
    364  1.1  agc 
    365  1.1  agc    where 0 <= x_i < 256 (note that one or more leading digits will be
    366  1.1  agc    zero if x < 256^{l-1}).
    367  1.1  agc 
    368  1.1  agc    3. Let the octet X_i have the value x_{l-i} for 1 <= i <= l.  Output
    369  1.1  agc    the octet string:
    370  1.1  agc 
    371  1.1  agc    X = X_1 X_2 ... X_l.
    372  1.1  agc 
    373  1.1  agc 4.2 OS2IP
    374  1.1  agc 
    375  1.1  agc    OS2IP converts an octet string to a nonnegative integer.
    376  1.1  agc 
    377  1.1  agc    OS2IP (X)
    378  1.1  agc 
    379  1.1  agc    Input:
    380  1.1  agc    X         octet string to be converted
    381  1.1  agc 
    382  1.1  agc    Output:
    383  1.1  agc    x         corresponding nonnegative integer
    384  1.1  agc 
    385  1.1  agc    Steps:
    386  1.1  agc 
    387  1.1  agc    1. Let X_1 X_2 ... X_l  be the octets of X from first to last, and
    388  1.1  agc    let x{l-i} have value X_i for 1<= i <= l.
    389  1.1  agc 
    390  1.1  agc    2. Let x = x{l-1} 256^{l-1} + x_{l-2} 256^{l-2} +...+ x_1 256 + x_0.
    391  1.1  agc 
    392  1.1  agc    3. Output x.
    393  1.1  agc 
    394  1.1  agc 
    395  1.1  agc 
    396  1.1  agc 
    397  1.1  agc 
    398  1.1  agc 
    399  1.1  agc 
    400  1.1  agc Kaliski & Staddon            Informational                      [Page 7]
    401  1.1  agc 
    403  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    404  1.1  agc 
    405  1.1  agc 
    406  1.1  agc 5. Cryptographic primitives
    407  1.1  agc 
    408  1.1  agc    Cryptographic primitives are basic mathematical operations on which
    409  1.1  agc    cryptographic schemes can be built. They are intended for
    410  1.1  agc    implementation in hardware or as software modules, and are not
    411  1.1  agc    intended to provide security apart from a scheme.
    412  1.1  agc 
    413  1.1  agc    Four types of primitive are specified in this document, organized in
    414  1.1  agc    pairs: encryption and decryption; and signature and verification.
    415  1.1  agc 
    416  1.1  agc    The specifications of the primitives assume that certain conditions
    417  1.1  agc    are met by the inputs, in particular that public and private keys are
    418  1.1  agc    valid.
    419  1.1  agc 
    420  1.1  agc 5.1 Encryption and decryption primitives
    421  1.1  agc 
    422  1.1  agc    An encryption primitive produces a ciphertext representative from a
    423  1.1  agc    message representative under the control of a public key, and a
    424  1.1  agc    decryption primitive recovers the message representative from the
    425  1.1  agc    ciphertext representative under the control of the corresponding
    426  1.1  agc    private key.
    427  1.1  agc 
    428  1.1  agc    One pair of encryption and decryption primitives is employed in the
    429  1.1  agc    encryption schemes defined in this document and is specified here:
    430  1.1  agc    RSAEP/RSADP. RSAEP and RSADP involve the same mathematical operation,
    431  1.1  agc    with different keys as input.
    432  1.1  agc 
    433  1.1  agc    The primitives defined here are the same as in the draft IEEE P1363
    434  1.1  agc    and are compatible with PKCS #1 v1.5.
    435  1.1  agc 
    436  1.1  agc    The main mathematical operation in each primitive is exponentiation.
    437  1.1  agc 
    438  1.1  agc 5.1.1 RSAEP
    439  1.1  agc 
    440  1.1  agc    RSAEP((n, e), m)
    441  1.1  agc 
    442  1.1  agc    Input:
    443  1.1  agc    (n, e)    RSA public key
    444  1.1  agc    m         message representative, an integer between 0 and n-1
    445  1.1  agc 
    446  1.1  agc    Output:
    447  1.1  agc    c         ciphertext representative, an integer between 0 and n-1;
    448  1.1  agc              or "message representative out of range"
    449  1.1  agc 
    450  1.1  agc    Assumptions: public key (n, e) is valid
    451  1.1  agc 
    452  1.1  agc    Steps:
    453  1.1  agc 
    454  1.1  agc 
    455  1.1  agc 
    456  1.1  agc 
    457  1.1  agc Kaliski & Staddon            Informational                      [Page 8]
    458  1.1  agc 
    460  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    461  1.1  agc 
    462  1.1  agc 
    463  1.1  agc    1. If the message representative m is not between 0 and n-1, output
    464  1.1  agc    message representative out of range and stop.
    465  1.1  agc 
    466  1.1  agc    2. Let c = m^e mod n.
    467  1.1  agc 
    468  1.1  agc    3. Output c.
    469  1.1  agc 
    470  1.1  agc 5.1.2 RSADP
    471  1.1  agc 
    472  1.1  agc    RSADP (K, c)
    473  1.1  agc 
    474  1.1  agc    Input:
    475  1.1  agc 
    476  1.1  agc    K         RSA private key, where K has one of the following forms
    477  1.1  agc                  -a pair (n, d)
    478  1.1  agc                  -a quintuple (p, q, dP, dQ, qInv)
    479  1.1  agc    c         ciphertext representative, an integer between 0 and n-1
    480  1.1  agc 
    481  1.1  agc    Output:
    482  1.1  agc    m         message representative, an integer between 0 and n-1; or
    483  1.1  agc              "ciphertext representative out of range"
    484  1.1  agc 
    485  1.1  agc    Assumptions: private key K is valid
    486  1.1  agc 
    487  1.1  agc    Steps:
    488  1.1  agc 
    489  1.1  agc    1. If the ciphertext representative c is not between 0 and n-1,
    490  1.1  agc    output "ciphertext representative out of range" and stop.
    491  1.1  agc 
    492  1.1  agc    2. If the first form (n, d) of K is used:
    493  1.1  agc 
    494  1.1  agc    2.1 Let m = c^d mod n.          Else, if the second form (p, q, dP,
    495  1.1  agc    dQ, qInv) of K is used:
    496  1.1  agc 
    497  1.1  agc    2.2 Let m_1 = c^dP mod p.
    498  1.1  agc 
    499  1.1  agc    2.3 Let m_2 = c^dQ mod q.
    500  1.1  agc 
    501  1.1  agc    2.4 Let h = qInv ( m_1 - m_2 ) mod p.
    502  1.1  agc 
    503  1.1  agc    2.5 Let m = m_2 + hq.
    504  1.1  agc 
    505  1.1  agc    3. Output m.
    506  1.1  agc 
    507  1.1  agc 
    508  1.1  agc 
    509  1.1  agc 
    510  1.1  agc 
    511  1.1  agc 
    512  1.1  agc 
    513  1.1  agc 
    514  1.1  agc Kaliski & Staddon            Informational                      [Page 9]
    515  1.1  agc 
    517  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    518  1.1  agc 
    519  1.1  agc 
    520  1.1  agc 5.2 Signature and verification primitives
    521  1.1  agc 
    522  1.1  agc    A signature primitive produces a signature representative from a
    523  1.1  agc    message representative under the control of a private key, and a
    524  1.1  agc    verification primitive recovers the message representative from the
    525  1.1  agc    signature representative under the control of the corresponding
    526  1.1  agc    public key. One pair of signature and verification primitives is
    527  1.1  agc    employed in the signature schemes defined in this document and is
    528  1.1  agc    specified here: RSASP1/RSAVP1.
    529  1.1  agc 
    530  1.1  agc    The primitives defined here are the same as in the draft IEEE P1363
    531  1.1  agc    and are compatible with PKCS #1 v1.5.
    532  1.1  agc 
    533  1.1  agc    The main mathematical operation in each primitive is exponentiation,
    534  1.1  agc    as in the encryption and decryption primitives of Section 5.1. RSASP1
    535  1.1  agc    and RSAVP1 are the same as RSADP and RSAEP except for the names of
    536  1.1  agc    their input and output arguments; they are distinguished as they are
    537  1.1  agc    intended for different purposes.
    538  1.1  agc 
    539  1.1  agc 5.2.1 RSASP1
    540  1.1  agc 
    541  1.1  agc    RSASP1 (K, m)
    542  1.1  agc 
    543  1.1  agc    Input:
    544  1.1  agc    K             RSA private key, where K has one of the following
    545  1.1  agc                  forms:
    546  1.1  agc                     -a pair (n, d)
    547  1.1  agc                     -a quintuple (p, q, dP, dQ, qInv)
    548  1.1  agc 
    549  1.1  agc    m             message representative, an integer between 0 and n-1
    550  1.1  agc 
    551  1.1  agc    Output:
    552  1.1  agc    s             signature representative, an integer between  0 and
    553  1.1  agc                  n-1, or "message representative out of range"
    554  1.1  agc 
    555  1.1  agc    Assumptions:
    556  1.1  agc    private key K is valid
    557  1.1  agc 
    558  1.1  agc    Steps:
    559  1.1  agc 
    560  1.1  agc    1. If the message representative m is not between 0 and n-1, output
    561  1.1  agc    "message representative out of range" and stop.
    562  1.1  agc 
    563  1.1  agc    2. If the first form (n, d) of K is used:
    564  1.1  agc 
    565  1.1  agc    2.1 Let s = m^d mod n.          Else, if the second form (p, q, dP,
    566  1.1  agc    dQ, qInv) of K is used:
    567  1.1  agc 
    568  1.1  agc 
    569  1.1  agc 
    570  1.1  agc 
    571  1.1  agc Kaliski & Staddon            Informational                     [Page 10]
    572  1.1  agc 
    574  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    575  1.1  agc 
    576  1.1  agc 
    577  1.1  agc    2.2 Let s_1 = m^dP mod p.
    578  1.1  agc 
    579  1.1  agc    2.3 Let s_2 = m^dQ mod q.
    580  1.1  agc 
    581  1.1  agc    2.4 Let h = qInv ( s_1 - s_2 ) mod p.
    582  1.1  agc 
    583  1.1  agc    2.5 Let s = s_2 + hq.
    584  1.1  agc 
    585  1.1  agc    3. Output S.
    586  1.1  agc 
    587  1.1  agc 5.2.2 RSAVP1
    588  1.1  agc 
    589  1.1  agc    RSAVP1 ((n, e), s)
    590  1.1  agc 
    591  1.1  agc    Input:
    592  1.1  agc    (n, e)  RSA public key
    593  1.1  agc    s       signature representative, an integer between 0 and n-1
    594  1.1  agc 
    595  1.1  agc    Output:
    596  1.1  agc    m       message representative, an integer between 0 and n-1;
    597  1.1  agc            or "invalid"
    598  1.1  agc 
    599  1.1  agc    Assumptions:
    600  1.1  agc    public key (n, e) is valid
    601  1.1  agc 
    602  1.1  agc    Steps:
    603  1.1  agc 
    604  1.1  agc    1. If the signature representative s is not between 0 and n-1, output
    605  1.1  agc    "invalid" and stop.
    606  1.1  agc 
    607  1.1  agc    2. Let m = s^e mod n.
    608  1.1  agc 
    609  1.1  agc    3. Output m.
    610  1.1  agc 
    611  1.1  agc 6. Overview of schemes
    612  1.1  agc 
    613  1.1  agc    A scheme combines cryptographic primitives and other techniques to
    614  1.1  agc    achieve a particular security goal. Two types of scheme are specified
    615  1.1  agc    in this document: encryption schemes and signature schemes with
    616  1.1  agc    appendix.
    617  1.1  agc 
    618  1.1  agc    The schemes specified in this document are limited in scope in that
    619  1.1  agc    their operations consist only of steps to process data with a key,
    620  1.1  agc    and do not include steps for obtaining or validating the key. Thus,
    621  1.1  agc    in addition to the scheme operations, an application will typically
    622  1.1  agc    include key management operations by which parties may select public
    623  1.1  agc    and private keys for a scheme operation. The specific additional
    624  1.1  agc    operations and other details are outside the scope of this document.
    625  1.1  agc 
    626  1.1  agc 
    627  1.1  agc 
    628  1.1  agc Kaliski & Staddon            Informational                     [Page 11]
    629  1.1  agc 
    631  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    632  1.1  agc 
    633  1.1  agc 
    634  1.1  agc    As was the case for the cryptographic primitives (Section 5), the
    635  1.1  agc    specifications of scheme operations assume that certain conditions
    636  1.1  agc    are met by the inputs, in particular that public and private keys are
    637  1.1  agc    valid. The behavior of an implementation is thus unspecified when a
    638  1.1  agc    key is invalid. The impact of such unspecified behavior depends on
    639  1.1  agc    the application. Possible means of addressing key validation include
    640  1.1  agc    explicit key validation by the application; key validation within the
    641  1.1  agc    public-key infrastructure; and assignment of liability for operations
    642  1.1  agc    performed with an invalid key to the party who generated the key.
    643  1.1  agc 
    644  1.1  agc 7. Encryption schemes
    645  1.1  agc 
    646  1.1  agc    An encryption scheme consists of an encryption operation and a
    647  1.1  agc    decryption operation, where the encryption operation produces a
    648  1.1  agc    ciphertext from a message with a recipient's public key, and the
    649  1.1  agc    decryption operation recovers the message from the ciphertext with
    650  1.1  agc    the recipient's corresponding private key.
    651  1.1  agc 
    652  1.1  agc    An encryption scheme can be employed in a variety of applications. A
    653  1.1  agc    typical application is a key establishment protocol, where the
    654  1.1  agc    message contains key material to be delivered confidentially from one
    655  1.1  agc    party to another. For instance, PKCS #7 [21] employs such a protocol
    656  1.1  agc    to deliver a content-encryption key from a sender to a recipient; the
    657  1.1  agc    encryption schemes defined here would be suitable key-encryption
    658  1.1  agc    algorithms in that context.
    659  1.1  agc 
    660  1.1  agc    Two encryption schemes are specified in this document: RSAES-OAEP and
    661  1.1  agc    RSAES-PKCS1-v1_5. RSAES-OAEP is recommended for new applications;
    662  1.1  agc    RSAES-PKCS1-v1_5 is included only for compatibility with existing
    663  1.1  agc    applications, and is not recommended for new applications.
    664  1.1  agc 
    665  1.1  agc    The encryption schemes given here follow a general model similar to
    666  1.1  agc    that employed in IEEE P1363, by combining encryption and decryption
    667  1.1  agc    primitives with an encoding method for encryption. The encryption
    668  1.1  agc    operations apply a message encoding operation to a message to produce
    669  1.1  agc    an encoded message, which is then converted to an integer message
    670  1.1  agc    representative. An encryption primitive is applied to the message
    671  1.1  agc    representative to produce the ciphertext. Reversing this, the
    672  1.1  agc    decryption operations apply a decryption primitive to the ciphertext
    673  1.1  agc    to recover a message representative, which is then converted to an
    674  1.1  agc    octet string encoded message. A message decoding operation is applied
    675  1.1  agc    to the encoded message to recover the message and verify the
    676  1.1  agc    correctness of the decryption.
    677  1.1  agc 
    678  1.1  agc 
    679  1.1  agc 
    680  1.1  agc 
    681  1.1  agc 
    682  1.1  agc 
    683  1.1  agc 
    684  1.1  agc 
    685  1.1  agc Kaliski & Staddon            Informational                     [Page 12]
    686  1.1  agc 
    688  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    689  1.1  agc 
    690  1.1  agc 
    691  1.1  agc 7.1 RSAES-OAEP
    692  1.1  agc 
    693  1.1  agc    RSAES-OAEP combines the RSAEP and RSADP primitives (Sections 5.1.1
    694  1.1  agc    and 5.1.2) with the EME-OAEP encoding method (Section 9.1.1) EME-OAEP
    695  1.1  agc    is based on the method found in [2]. It is compatible with the IFES
    696  1.1  agc    scheme defined in the draft P1363 where the encryption and decryption
    697  1.1  agc    primitives are IFEP-RSA and IFDP-RSA and the message encoding method
    698  1.1  agc    is EME-OAEP. RSAES-OAEP can operate on messages of length up to k-2-
    699  1.1  agc    2hLen octets, where hLen is the length of the hash function output
    700  1.1  agc    for EME-OAEP and k is the length in octets of the recipient's RSA
    701  1.1  agc    modulus.  Assuming that the hash function in EME-OAEP has appropriate
    702  1.1  agc    properties, and the key size is sufficiently large, RSAEP-OAEP
    703  1.1  agc    provides "plaintext-aware encryption," meaning that it is
    704  1.1  agc    computationally infeasible to obtain full or partial information
    705  1.1  agc    about a message from a ciphertext, and computationally infeasible to
    706  1.1  agc    generate a valid ciphertext without knowing the corresponding
    707  1.1  agc    message.  Therefore, a chosen-ciphertext attack is ineffective
    708  1.1  agc    against a plaintext-aware encryption scheme such as RSAES-OAEP.
    709  1.1  agc 
    710  1.1  agc    Both the encryption and the decryption operations of RSAES-OAEP take
    711  1.1  agc    the value of the parameter string P as input. In this version of PKCS
    712  1.1  agc    #1, P is an octet string that is specified explicitly. See Section
    713  1.1  agc    11.2.1 for the relevant ASN.1 syntax. We briefly note that to receive
    714  1.1  agc    the full security benefit of RSAES-OAEP, it should not be used in a
    715  1.1  agc    protocol involving RSAES-PKCS1-v1_5. It is possible that in a
    716  1.1  agc    protocol on which both encryption schemes are present, an adaptive
    717  1.1  agc    chosen ciphertext attack such as [4] would be useful.
    718  1.1  agc 
    719  1.1  agc    Both the encryption and the decryption operations of RSAES-OAEP take
    720  1.1  agc    the value of the parameter string P as input. In this version of PKCS
    721  1.1  agc    #1, P is an octet string that is specified explicitly. See Section
    722  1.1  agc    11.2.1 for the relevant ASN.1 syntax.
    723  1.1  agc 
    724  1.1  agc 7.1.1 Encryption operation
    725  1.1  agc 
    726  1.1  agc    RSAES-OAEP-ENCRYPT ((n, e), M, P)
    727  1.1  agc 
    728  1.1  agc    Input:
    729  1.1  agc    (n, e)    recipient's RSA public key
    730  1.1  agc 
    731  1.1  agc    M         message to be encrypted, an octet string of length at
    732  1.1  agc              most k-2-2hLen, where k is the length in octets of the
    733  1.1  agc              modulus n and hLen is the length in octets of the hash
    734  1.1  agc              function output for EME-OAEP
    735  1.1  agc 
    736  1.1  agc    P         encoding parameters, an octet string that may be empty
    737  1.1  agc 
    738  1.1  agc 
    739  1.1  agc 
    740  1.1  agc 
    741  1.1  agc 
    742  1.1  agc Kaliski & Staddon            Informational                     [Page 13]
    743  1.1  agc 
    745  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    746  1.1  agc 
    747  1.1  agc 
    748  1.1  agc    Output:
    749  1.1  agc    C         ciphertext, an octet string of length k; or "message too
    750  1.1  agc              long"
    751  1.1  agc 
    752  1.1  agc    Assumptions: public key (n, e) is valid
    753  1.1  agc 
    754  1.1  agc    Steps:
    755  1.1  agc 
    756  1.1  agc    1. Apply the EME-OAEP encoding operation (Section 9.1.1.2) to the
    757  1.1  agc    message M and the encoding parameters P to produce an encoded message
    758  1.1  agc    EM of length k-1 octets:
    759  1.1  agc 
    760  1.1  agc    EM = EME-OAEP-ENCODE (M, P, k-1)
    761  1.1  agc 
    762  1.1  agc    If the encoding operation outputs "message too long," then output
    763  1.1  agc    "message too long" and stop.
    764  1.1  agc 
    765  1.1  agc    2. Convert the encoded message EM to an integer message
    766  1.1  agc    representative m: m = OS2IP (EM)
    767  1.1  agc 
    768  1.1  agc    3. Apply the RSAEP encryption primitive (Section 5.1.1) to the public
    769  1.1  agc    key (n, e) and the message representative m to produce an integer
    770  1.1  agc    ciphertext representative c:
    771  1.1  agc 
    772  1.1  agc    c = RSAEP ((n, e), m)
    773  1.1  agc 
    774  1.1  agc    4. Convert the ciphertext representative c to a ciphertext C of
    775  1.1  agc    length k octets: C = I2OSP (c, k)
    776  1.1  agc 
    777  1.1  agc    5. Output the ciphertext C.
    778  1.1  agc 
    779  1.1  agc 7.1.2 Decryption operation
    780  1.1  agc 
    781  1.1  agc    RSAES-OAEP-DECRYPT (K, C, P)
    782  1.1  agc 
    783  1.1  agc    Input:
    784  1.1  agc    K          recipient's RSA private key
    785  1.1  agc    C          ciphertext to be decrypted, an octet string of length
    786  1.1  agc               k, where k is the length in octets of the modulus n
    787  1.1  agc    P          encoding parameters, an octet string that may be empty
    788  1.1  agc 
    789  1.1  agc    Output:
    790  1.1  agc    M          message, an octet string of length at most k-2-2hLen,
    791  1.1  agc               where hLen is the length in octets of the hash
    792  1.1  agc               function output for EME-OAEP; or "decryption error"
    793  1.1  agc 
    794  1.1  agc 
    795  1.1  agc 
    796  1.1  agc 
    797  1.1  agc 
    798  1.1  agc 
    799  1.1  agc Kaliski & Staddon            Informational                     [Page 14]
    800  1.1  agc 
    802  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    803  1.1  agc 
    804  1.1  agc 
    805  1.1  agc    Steps:
    806  1.1  agc 
    807  1.1  agc    1. If the length of the ciphertext C is not k octets, output
    808  1.1  agc    "decryption error" and stop.
    809  1.1  agc 
    810  1.1  agc    2. Convert the ciphertext C to an integer ciphertext representative
    811  1.1  agc    c: c = OS2IP (C).
    812  1.1  agc 
    813  1.1  agc    3. Apply the RSADP decryption primitive (Section 5.1.2) to the
    814  1.1  agc    private key K and the ciphertext representative c to produce an
    815  1.1  agc    integer message representative m:
    816  1.1  agc 
    817  1.1  agc    m = RSADP (K, c)
    818  1.1  agc 
    819  1.1  agc    If RSADP outputs "ciphertext out of range," then output "decryption
    820  1.1  agc    error" and stop.
    821  1.1  agc 
    822  1.1  agc    4. Convert the message representative m to an encoded message EM of
    823  1.1  agc    length k-1 octets: EM = I2OSP (m, k-1)
    824  1.1  agc 
    825  1.1  agc    If I2OSP outputs "integer too large," then output "decryption error"
    826  1.1  agc    and stop.
    827  1.1  agc 
    828  1.1  agc    5. Apply the EME-OAEP decoding operation to the encoded message EM
    829  1.1  agc    and the encoding parameters P to recover a message M:
    830  1.1  agc 
    831  1.1  agc    M = EME-OAEP-DECODE (EM, P)
    832  1.1  agc 
    833  1.1  agc    If the decoding operation outputs "decoding error," then output
    834  1.1  agc    "decryption error" and stop.
    835  1.1  agc 
    836  1.1  agc    6. Output the message M.
    837  1.1  agc 
    838  1.1  agc    Note. It is important that the error messages output in steps 4 and 5
    839  1.1  agc    be the same, otherwise an adversary may be able to extract useful
    840  1.1  agc    information from the type of error message received. Error message
    841  1.1  agc    information is used to mount a chosen-ciphertext attack on PKCS #1
    842  1.1  agc    v1.5 encrypted messages in [4].
    843  1.1  agc 
    844  1.1  agc 7.2 RSAES-PKCS1-v1_5
    845  1.1  agc 
    846  1.1  agc    RSAES-PKCS1-v1_5 combines the RSAEP and RSADP primitives with the
    847  1.1  agc    EME-PKCS1-v1_5 encoding method. It is the same as the encryption
    848  1.1  agc    scheme in PKCS #1 v1.5. RSAES-PKCS1-v1_5 can operate on messages of
    849  1.1  agc    length up to k-11 octets, although care should be taken to avoid
    850  1.1  agc    certain attacks on low-exponent RSA due to Coppersmith, et al. when
    851  1.1  agc    long messages are encrypted (see the third bullet in the notes below
    852  1.1  agc    and [7]).
    853  1.1  agc 
    854  1.1  agc 
    855  1.1  agc 
    856  1.1  agc Kaliski & Staddon            Informational                     [Page 15]
    857  1.1  agc 
    859  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    860  1.1  agc 
    861  1.1  agc 
    862  1.1  agc    RSAES-PKCS1-v1_5 does not provide "plaintext aware" encryption. In
    863  1.1  agc    particular, it is possible to generate valid ciphertexts without
    864  1.1  agc    knowing the corresponding plaintexts, with a reasonable probability
    865  1.1  agc    of success. This ability can be exploited in a chosen ciphertext
    866  1.1  agc    attack as shown in [4]. Therefore, if RSAES-PKCS1-v1_5 is to be used,
    867  1.1  agc    certain easily implemented countermeasures should be taken to thwart
    868  1.1  agc    the attack found in [4]. The addition of structure to the data to be
    869  1.1  agc    encoded, rigorous checking of PKCS #1 v1.5 conformance and other
    870  1.1  agc    redundancy in decrypted messages, and the consolidation of error
    871  1.1  agc    messages in a client-server protocol based on PKCS #1 v1.5 can all be
    872  1.1  agc    effective countermeasures and don't involve changes to a PKCS #1
    873  1.1  agc    v1.5-based protocol. These and other countermeasures are discussed in
    874  1.1  agc    [5].
    875  1.1  agc 
    876  1.1  agc    Notes. The following passages describe some security recommendations
    877  1.1  agc    pertaining to the use of RSAES-PKCS1-v1_5. Recommendations from
    878  1.1  agc    version 1.5 of this document are included as well as new
    879  1.1  agc    recommendations motivated by cryptanalytic advances made in the
    880  1.1  agc    intervening years.
    881  1.1  agc 
    882  1.1  agc    -It is recommended that the pseudorandom octets in EME-PKCS1-v1_5 be
    883  1.1  agc    generated independently for each encryption process, especially if
    884  1.1  agc    the same data is input to more than one encryption process. Hastad's
    885  1.1  agc    results [13] are one motivation for this recommendation.
    886  1.1  agc 
    887  1.1  agc    -The padding string PS in EME-PKCS1-v1_5 is at least eight octets
    888  1.1  agc    long, which is a security condition for public-key operations that
    889  1.1  agc    prevents an attacker from recovering data by trying all possible
    890  1.1  agc    encryption blocks.
    891  1.1  agc 
    892  1.1  agc    -The pseudorandom octets can also help thwart an attack due to
    893  1.1  agc    Coppersmith et al. [7] when the size of the message to be encrypted
    894  1.1  agc    is kept small. The attack works on low-exponent RSA when similar
    895  1.1  agc    messages are encrypted with the same public key. More specifically,
    896  1.1  agc    in one flavor of the attack, when two inputs to RSAEP agree on a
    897  1.1  agc    large fraction of bits (8/9) and low-exponent RSA (e = 3) is used to
    898  1.1  agc    encrypt both of them, it may be possible to recover both inputs with
    899  1.1  agc    the attack. Another flavor of the attack is successful in decrypting
    900  1.1  agc    a single ciphertext when a large fraction (2/3) of the input to RSAEP
    901  1.1  agc    is already known. For typical applications, the message to be
    902  1.1  agc    encrypted is short (e.g., a 128-bit symmetric key) so not enough
    903  1.1  agc    information will be known or common between two messages to enable
    904  1.1  agc    the attack.  However, if a long message is encrypted, or if part of a
    905  1.1  agc    message is known, then the attack may be a concern. In any case, the
    906  1.1  agc    RSAEP-OAEP scheme overcomes the attack.
    907  1.1  agc 
    908  1.1  agc 
    909  1.1  agc 
    910  1.1  agc 
    911  1.1  agc 
    912  1.1  agc 
    913  1.1  agc Kaliski & Staddon            Informational                     [Page 16]
    914  1.1  agc 
    916  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    917  1.1  agc 
    918  1.1  agc 
    919  1.1  agc 7.2.1 Encryption operation
    920  1.1  agc 
    921  1.1  agc    RSAES-PKCS1-V1_5-ENCRYPT ((n, e), M)
    922  1.1  agc 
    923  1.1  agc    Input:
    924  1.1  agc    (n, e)  recipient's RSA public key
    925  1.1  agc    M       message to be encrypted, an octet string of length at
    926  1.1  agc            most k-11 octets, where k is the length in octets of the
    927  1.1  agc            modulus n
    928  1.1  agc 
    929  1.1  agc    Output:
    930  1.1  agc    C       ciphertext, an octet string of length k; or "message too
    931  1.1  agc            long"
    932  1.1  agc 
    933  1.1  agc    Steps:
    934  1.1  agc 
    935  1.1  agc    1. Apply the EME-PKCS1-v1_5 encoding operation (Section 9.1.2.1) to
    936  1.1  agc    the message M to produce an encoded message EM of length k-1 octets:
    937  1.1  agc 
    938  1.1  agc    EM = EME-PKCS1-V1_5-ENCODE (M, k-1)
    939  1.1  agc 
    940  1.1  agc    If the encoding operation outputs "message too long," then output
    941  1.1  agc    "message too long" and stop.
    942  1.1  agc 
    943  1.1  agc    2. Convert the encoded message EM to an integer message
    944  1.1  agc    representative m: m = OS2IP (EM)
    945  1.1  agc 
    946  1.1  agc    3. Apply the RSAEP encryption primitive (Section 5.1.1) to the public
    947  1.1  agc    key (n, e) and the message representative m to produce an integer
    948  1.1  agc    ciphertext representative c: c = RSAEP ((n, e), m)
    949  1.1  agc 
    950  1.1  agc    4. Convert the ciphertext representative c to a ciphertext C of
    951  1.1  agc    length k octets: C = I2OSP (c, k)
    952  1.1  agc 
    953  1.1  agc    5. Output the ciphertext C.
    954  1.1  agc 
    955  1.1  agc 7.2.2 Decryption operation
    956  1.1  agc 
    957  1.1  agc    RSAES-PKCS1-V1_5-DECRYPT (K, C)
    958  1.1  agc 
    959  1.1  agc    Input:
    960  1.1  agc    K       recipient's RSA private key
    961  1.1  agc    C       ciphertext to be decrypted, an octet string of length k,
    962  1.1  agc            where k is the length in octets of the modulus n
    963  1.1  agc 
    964  1.1  agc    Output:
    965  1.1  agc    M       message, an octet string of length at most k-11; or
    966  1.1  agc            "decryption error"
    967  1.1  agc 
    968  1.1  agc 
    969  1.1  agc 
    970  1.1  agc Kaliski & Staddon            Informational                     [Page 17]
    971  1.1  agc 
    973  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
    974  1.1  agc 
    975  1.1  agc 
    976  1.1  agc    Steps:
    977  1.1  agc 
    978  1.1  agc    1. If the length of the ciphertext C is not k octets, output
    979  1.1  agc    "decryption error" and stop.
    980  1.1  agc 
    981  1.1  agc    2. Convert the ciphertext C to an integer ciphertext representative
    982  1.1  agc    c: c = OS2IP (C).
    983  1.1  agc 
    984  1.1  agc    3. Apply the RSADP decryption primitive to the private key (n, d) and
    985  1.1  agc    the ciphertext representative c to produce an integer message
    986  1.1  agc    representative m: m = RSADP ((n, d), c).
    987  1.1  agc 
    988  1.1  agc    If RSADP outputs "ciphertext out of range," then output "decryption
    989  1.1  agc    error" and stop.
    990  1.1  agc 
    991  1.1  agc    4. Convert the message representative m to an encoded message EM of
    992  1.1  agc    length k-1 octets: EM = I2OSP (m, k-1)
    993  1.1  agc 
    994  1.1  agc    If I2OSP outputs "integer too large," then output "decryption error"
    995  1.1  agc    and stop.
    996  1.1  agc 
    997  1.1  agc    5. Apply the EME-PKCS1-v1_5 decoding operation to the encoded message
    998  1.1  agc    EM to recover a message M: M = EME-PKCS1-V1_5-DECODE (EM).
    999  1.1  agc 
   1000  1.1  agc    If the decoding operation outputs "decoding error," then output
   1001  1.1  agc    "decryption error" and stop.
   1002  1.1  agc 
   1003  1.1  agc    6. Output the message M.
   1004  1.1  agc 
   1005  1.1  agc    Note. It is important that only one type of error message is output
   1006  1.1  agc    by EME-PKCS1-v1_5, as ensured by steps 4 and 5. If this is not done,
   1007  1.1  agc    then an adversary may be able to use information extracted form the
   1008  1.1  agc    type of error message received to mount a chosen-ciphertext attack
   1009  1.1  agc    such as the one found in [4].
   1010  1.1  agc 
   1011  1.1  agc 8. Signature schemes with appendix
   1012  1.1  agc 
   1013  1.1  agc    A signature scheme with appendix consists of a signature generation
   1014  1.1  agc    operation and a signature verification operation, where the signature
   1015  1.1  agc    generation operation produces a signature from a message with a
   1016  1.1  agc    signer's private key, and the signature verification operation
   1017  1.1  agc    verifies the signature on the message with the signer's corresponding
   1018  1.1  agc    public key.  To verify a signature constructed with this type of
   1019  1.1  agc    scheme it is necessary to have the message itself. In this way,
   1020  1.1  agc    signature schemes with appendix are distinguished from signature
   1021  1.1  agc    schemes with message recovery, which are not supported in this
   1022  1.1  agc    document.
   1023  1.1  agc 
   1024  1.1  agc 
   1025  1.1  agc 
   1026  1.1  agc 
   1027  1.1  agc Kaliski & Staddon            Informational                     [Page 18]
   1028  1.1  agc 
   1030  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1031  1.1  agc 
   1032  1.1  agc 
   1033  1.1  agc    A signature scheme with appendix can be employed in a variety of
   1034  1.1  agc    applications. For instance, X.509 [6] employs such a scheme to
   1035  1.1  agc    authenticate the content of a certificate; the signature scheme with
   1036  1.1  agc    appendix defined here would be a suitable signature algorithm in that
   1037  1.1  agc    context. A related signature scheme could be employed in PKCS #7
   1038  1.1  agc    [21], although for technical reasons, the current version of PKCS #7
   1039  1.1  agc    separates a hash function from a signature scheme, which is different
   1040  1.1  agc    than what is done here.
   1041  1.1  agc 
   1042  1.1  agc    One signature scheme with appendix is specified in this document:
   1043  1.1  agc    RSASSA-PKCS1-v1_5.
   1044  1.1  agc 
   1045  1.1  agc    The signature scheme with appendix given here follows a general model
   1046  1.1  agc    similar to that employed in IEEE P1363, by combining signature and
   1047  1.1  agc    verification primitives with an encoding method for signatures. The
   1048  1.1  agc    signature generation operations apply a message encoding operation to
   1049  1.1  agc    a message to produce an encoded message, which is then converted to
   1050  1.1  agc    an integer message representative. A signature primitive is then
   1051  1.1  agc    applied to the message representative to produce the signature. The
   1052  1.1  agc    signature verification operations apply a signature verification
   1053  1.1  agc    primitive to the signature to recover a message representative, which
   1054  1.1  agc    is then converted to an octet string. The message encoding operation
   1055  1.1  agc    is again applied to the message, and the result is compared to the
   1056  1.1  agc    recovered octet string. If there is a match, the signature is
   1057  1.1  agc    considered valid. (Note that this approach assumes that the signature
   1058  1.1  agc    and verification primitives have the message-recovery form and the
   1059  1.1  agc    encoding method is deterministic, as is the case for RSASP1/RSAVP1
   1060  1.1  agc    and EMSA-PKCS1-v1_5. The signature generation and verification
   1061  1.1  agc    operations have a different form in P1363 for other primitives and
   1062  1.1  agc    encoding methods.)
   1063  1.1  agc 
   1064  1.1  agc    Editor's note. RSA Laboratories is investigating the possibility of
   1065  1.1  agc    including a scheme based on the PSS encoding methods specified in
   1066  1.1  agc    [3], which would be recommended for new applications.
   1067  1.1  agc 
   1068  1.1  agc 8.1 RSASSA-PKCS1-v1_5
   1069  1.1  agc 
   1070  1.1  agc    RSASSA-PKCS1-v1_5 combines the RSASP1 and RSAVP1 primitives with the
   1071  1.1  agc    EME-PKCS1-v1_5 encoding method. It is compatible with the IFSSA
   1072  1.1  agc    scheme defined in the draft P1363 where the signature and
   1073  1.1  agc    verification primitives are IFSP-RSA1 and IFVP-RSA1 and the message
   1074  1.1  agc    encoding method is EMSA-PKCS1-v1_5 (which is not defined in P1363).
   1075  1.1  agc    The length of messages on which RSASSA-PKCS1-v1_5 can operate is
   1076  1.1  agc    either unrestricted or constrained by a very large number, depending
   1077  1.1  agc    on the hash function underlying the message encoding method.
   1078  1.1  agc 
   1079  1.1  agc 
   1080  1.1  agc 
   1081  1.1  agc 
   1082  1.1  agc 
   1083  1.1  agc 
   1084  1.1  agc Kaliski & Staddon            Informational                     [Page 19]
   1085  1.1  agc 
   1087  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1088  1.1  agc 
   1089  1.1  agc 
   1090  1.1  agc    Assuming that the hash function in EMSA-PKCS1-v1_5 has appropriate
   1091  1.1  agc    properties and the key size is sufficiently large, RSASSA-PKCS1-v1_5
   1092  1.1  agc    provides secure signatures, meaning that it is computationally
   1093  1.1  agc    infeasible to generate a signature without knowing the private key,
   1094  1.1  agc    and computationally infeasible to find a message with a given
   1095  1.1  agc    signature or two messages with the same signature. Also, in the
   1096  1.1  agc    encoding method EMSA-PKCS1-v1_5, a hash function identifier is
   1097  1.1  agc    embedded in the encoding.  Because of this feature, an adversary must
   1098  1.1  agc    invert or find collisions of the particular hash function being used;
   1099  1.1  agc    attacking a different hash function than the one selected by the
   1100  1.1  agc    signer is not useful to the adversary.
   1101  1.1  agc 
   1102  1.1  agc 8.1.1 Signature generation operation
   1103  1.1  agc 
   1104  1.1  agc    RSASSA-PKCS1-V1_5-SIGN (K, M)
   1105  1.1  agc    Input:
   1106  1.1  agc    K         signer's RSA private ke
   1107  1.1  agc    M         message to be signed, an octet string
   1108  1.1  agc 
   1109  1.1  agc    Output:
   1110  1.1  agc    S         signature, an octet string of length k, where k is the
   1111  1.1  agc              length in octets of the modulus n; "message too long" or
   1112  1.1  agc              "modulus too short"
   1113  1.1  agc    Steps:
   1114  1.1  agc 
   1115  1.1  agc    1. Apply the EMSA-PKCS1-v1_5 encoding operation (Section 9.2.1) to
   1116  1.1  agc    the message M to produce an encoded message EM of length k-1 octets:
   1117  1.1  agc 
   1118  1.1  agc    EM = EMSA-PKCS1-V1_5-ENCODE (M, k-1)
   1119  1.1  agc 
   1120  1.1  agc    If the encoding operation outputs "message too long," then output
   1121  1.1  agc    "message too long" and stop. If the encoding operation outputs
   1122  1.1  agc    "intended encoded message length too short" then output "modulus too
   1123  1.1  agc    short".
   1124  1.1  agc 
   1125  1.1  agc    2. Convert the encoded message EM to an integer message
   1126  1.1  agc    representative m: m = OS2IP (EM)
   1127  1.1  agc 
   1128  1.1  agc    3. Apply the RSASP1 signature primitive (Section 5.2.1) to the
   1129  1.1  agc    private key K and the message representative m to produce an integer
   1130  1.1  agc    signature representative s: s = RSASP1 (K, m)
   1131  1.1  agc 
   1132  1.1  agc    4. Convert the signature representative s to a signature S of length
   1133  1.1  agc    k octets: S = I2OSP (s, k)
   1134  1.1  agc 
   1135  1.1  agc    5. Output the signature S.
   1136  1.1  agc 
   1137  1.1  agc 
   1138  1.1  agc 
   1139  1.1  agc 
   1140  1.1  agc 
   1141  1.1  agc Kaliski & Staddon            Informational                     [Page 20]
   1142  1.1  agc 
   1144  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1145  1.1  agc 
   1146  1.1  agc 
   1147  1.1  agc 8.1.2 Signature verification operation
   1148  1.1  agc 
   1149  1.1  agc    RSASSA-PKCS1-V1_5-VERIFY ((n, e), M, S)
   1150  1.1  agc 
   1151  1.1  agc    Input:
   1152  1.1  agc    (n, e)    signer's RSA public key
   1153  1.1  agc    M         message whose signature is to be verified, an octet string
   1154  1.1  agc    S         signature to be verified, an octet string of length k,
   1155  1.1  agc              where k is the length in octets of the modulus n
   1156  1.1  agc 
   1157  1.1  agc    Output: "valid signature," "invalid signature," or "message too
   1158  1.1  agc    long", or "modulus too short"
   1159  1.1  agc 
   1160  1.1  agc    Steps:
   1161  1.1  agc 
   1162  1.1  agc    1. If the length of the signature S is not k octets, output "invalid
   1163  1.1  agc    signature" and stop.
   1164  1.1  agc 
   1165  1.1  agc    2. Convert the signature S to an integer signature representative s:
   1166  1.1  agc 
   1167  1.1  agc    s = OS2IP (S)
   1168  1.1  agc 
   1169  1.1  agc    3. Apply the RSAVP1 verification primitive (Section 5.2.2) to the
   1170  1.1  agc    public key (n, e) and the signature representative s to produce an
   1171  1.1  agc    integer message representative m:
   1172  1.1  agc 
   1173  1.1  agc    m = RSAVP1 ((n, e), s)                  If RSAVP1 outputs "invalid"
   1174  1.1  agc    then output "invalid signature" and stop.
   1175  1.1  agc 
   1176  1.1  agc    4. Convert the message representative m to an encoded message EM of
   1177  1.1  agc    length k-1 octets: EM = I2OSP (m, k-1)
   1178  1.1  agc 
   1179  1.1  agc    If I2OSP outputs "integer too large," then output "invalid signature"
   1180  1.1  agc    and stop.
   1181  1.1  agc 
   1182  1.1  agc    5. Apply the EMSA-PKCS1-v1_5 encoding operation (Section 9.2.1) to
   1183  1.1  agc    the message M to produce a second encoded message EM' of length k-1
   1184  1.1  agc    octets:
   1185  1.1  agc 
   1186  1.1  agc    EM' = EMSA-PKCS1-V1_5-ENCODE (M, k-1)
   1187  1.1  agc 
   1188  1.1  agc    If the encoding operation outputs "message too long," then output
   1189  1.1  agc    "message too long" and stop. If the encoding operation outputs
   1190  1.1  agc    "intended encoded message length too short" then output "modulus too
   1191  1.1  agc    short".
   1192  1.1  agc 
   1193  1.1  agc 
   1194  1.1  agc 
   1195  1.1  agc 
   1196  1.1  agc 
   1197  1.1  agc 
   1198  1.1  agc Kaliski & Staddon            Informational                     [Page 21]
   1199  1.1  agc 
   1201  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1202  1.1  agc 
   1203  1.1  agc 
   1204  1.1  agc    6. Compare the encoded message EM and the second encoded message EM'.
   1205  1.1  agc    If they are the same, output "valid signature"; otherwise, output
   1206  1.1  agc    "invalid signature."
   1207  1.1  agc 
   1208  1.1  agc 9. Encoding methods
   1209  1.1  agc 
   1210  1.1  agc    Encoding methods consist of operations that map between octet string
   1211  1.1  agc    messages and integer message representatives.
   1212  1.1  agc 
   1213  1.1  agc    Two types of encoding method are considered in this document:
   1214  1.1  agc    encoding methods for encryption, encoding methods for signatures with
   1215  1.1  agc    appendix.
   1216  1.1  agc 
   1217  1.1  agc 9.1 Encoding methods for encryption
   1218  1.1  agc 
   1219  1.1  agc    An encoding method for encryption consists of an encoding operation
   1220  1.1  agc    and a decoding operation. An encoding operation maps a message M to a
   1221  1.1  agc    message representative EM of a specified length; the decoding
   1222  1.1  agc    operation maps a message representative EM back to a message. The
   1223  1.1  agc    encoding and decoding operations are inverses.
   1224  1.1  agc 
   1225  1.1  agc    The message representative EM will typically have some structure that
   1226  1.1  agc    can be verified by the decoding operation; the decoding operation
   1227  1.1  agc    will output "decoding error" if the structure is not present. The
   1228  1.1  agc    encoding operation may also introduce some randomness, so that
   1229  1.1  agc    different applications of the encoding operation to the same message
   1230  1.1  agc    will produce different representatives.
   1231  1.1  agc 
   1232  1.1  agc    Two encoding methods for encryption are employed in the encryption
   1233  1.1  agc    schemes and are specified here: EME-OAEP and EME-PKCS1-v1_5.
   1234  1.1  agc 
   1235  1.1  agc 9.1.1 EME-OAEP
   1236  1.1  agc 
   1237  1.1  agc    This encoding method is parameterized by the choice of hash function
   1238  1.1  agc    and mask generation function. Suggested hash and mask generation
   1239  1.1  agc    functions are given in Section 10. This encoding method is based on
   1240  1.1  agc    the method found in [2].
   1241  1.1  agc 
   1242  1.1  agc 9.1.1.1 Encoding operation
   1243  1.1  agc 
   1244  1.1  agc    EME-OAEP-ENCODE (M, P, emLen)
   1245  1.1  agc 
   1246  1.1  agc    Options:
   1247  1.1  agc    Hash      hash function (hLen denotes the length in octet of the
   1248  1.1  agc              hash function output)
   1249  1.1  agc    MGF       mask generation function
   1250  1.1  agc 
   1251  1.1  agc 
   1252  1.1  agc 
   1253  1.1  agc 
   1254  1.1  agc 
   1255  1.1  agc Kaliski & Staddon            Informational                     [Page 22]
   1256  1.1  agc 
   1258  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1259  1.1  agc 
   1260  1.1  agc 
   1261  1.1  agc    Input:
   1262  1.1  agc    M         message to be encoded, an octet string of length at most
   1263  1.1  agc              emLen-1-2hLen
   1264  1.1  agc    P         encoding parameters, an octet string
   1265  1.1  agc    emLen     intended length in octets of the encoded message, at least
   1266  1.1  agc              2hLen+1
   1267  1.1  agc 
   1268  1.1  agc    Output:
   1269  1.1  agc    EM        encoded message, an octet string of length emLen;
   1270  1.1  agc              "message too long" or "parameter string too long"
   1271  1.1  agc 
   1272  1.1  agc    Steps:
   1273  1.1  agc 
   1274  1.1  agc    1. If the length of P is greater than the input limitation for the
   1275  1.1  agc    hash function (2^61-1 octets for SHA-1) then output "parameter string
   1276  1.1  agc    too long" and stop.
   1277  1.1  agc 
   1278  1.1  agc    2. If ||M|| > emLen-2hLen-1 then output "message too long" and stop.
   1279  1.1  agc 
   1280  1.1  agc    3. Generate an octet string PS consisting of emLen-||M||-2hLen-1 zero
   1281  1.1  agc    octets. The length of PS may be 0.
   1282  1.1  agc 
   1283  1.1  agc    4. Let pHash = Hash(P), an octet string of length hLen.
   1284  1.1  agc 
   1285  1.1  agc    5. Concatenate pHash, PS, the message M, and other padding to form a
   1286  1.1  agc    data block DB as: DB = pHash || PS || 01 || M
   1287  1.1  agc 
   1288  1.1  agc    6. Generate a random octet string seed of length hLen.
   1289  1.1  agc 
   1290  1.1  agc    7. Let dbMask = MGF(seed, emLen-hLen).
   1291  1.1  agc 
   1292  1.1  agc    8. Let maskedDB = DB \xor dbMask.
   1293  1.1  agc 
   1294  1.1  agc    9. Let seedMask = MGF(maskedDB, hLen).
   1295  1.1  agc 
   1296  1.1  agc    10. Let maskedSeed = seed \xor seedMask.
   1297  1.1  agc 
   1298  1.1  agc    11. Let EM = maskedSeed || maskedDB.
   1299  1.1  agc 
   1300  1.1  agc    12. Output EM.
   1301  1.1  agc 
   1302  1.1  agc 9.1.1.2 Decoding operation EME-OAEP-DECODE (EM, P)
   1303  1.1  agc 
   1304  1.1  agc    Options:
   1305  1.1  agc    Hash      hash function (hLen denotes the length in octet of the hash
   1306  1.1  agc              function output)
   1307  1.1  agc 
   1308  1.1  agc    MGF       mask generation function
   1309  1.1  agc 
   1310  1.1  agc 
   1311  1.1  agc 
   1312  1.1  agc Kaliski & Staddon            Informational                     [Page 23]
   1313  1.1  agc 
   1315  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1316  1.1  agc 
   1317  1.1  agc 
   1318  1.1  agc    Input:
   1319  1.1  agc 
   1320  1.1  agc    EM        encoded message, an octet string of length at least 2hLen+1
   1321  1.1  agc    P         encoding parameters, an octet string
   1322  1.1  agc 
   1323  1.1  agc    Output:
   1324  1.1  agc    M         recovered message, an octet string of length at most
   1325  1.1  agc              ||EM||-1-2hLen; or "decoding error"
   1326  1.1  agc 
   1327  1.1  agc    Steps:
   1328  1.1  agc 
   1329  1.1  agc    1. If the length of P is greater than the input limitation for the
   1330  1.1  agc    hash function (2^61-1 octets for SHA-1) then output "parameter string
   1331  1.1  agc    too long" and stop.
   1332  1.1  agc 
   1333  1.1  agc    2. If ||EM|| < 2hLen+1, then output "decoding error" and stop.
   1334  1.1  agc 
   1335  1.1  agc    3. Let maskedSeed be the first hLen octets of EM and let maskedDB be
   1336  1.1  agc    the remaining ||EM|| - hLen octets.
   1337  1.1  agc 
   1338  1.1  agc    4. Let seedMask = MGF(maskedDB, hLen).
   1339  1.1  agc 
   1340  1.1  agc    5. Let seed = maskedSeed \xor seedMask.
   1341  1.1  agc 
   1342  1.1  agc    6. Let dbMask = MGF(seed, ||EM|| - hLen).
   1343  1.1  agc 
   1344  1.1  agc    7. Let DB = maskedDB \xor dbMask.
   1345  1.1  agc 
   1346  1.1  agc    8. Let pHash = Hash(P), an octet string of length hLen.
   1347  1.1  agc 
   1348  1.1  agc    9. Separate DB into an octet string pHash' consisting of the first
   1349  1.1  agc    hLen octets of DB, a (possibly empty) octet string PS consisting of
   1350  1.1  agc    consecutive zero octets following pHash', and a message M as:
   1351  1.1  agc 
   1352  1.1  agc    DB = pHash' || PS || 01 || M
   1353  1.1  agc 
   1354  1.1  agc    If there is no 01 octet to separate PS from M, output "decoding
   1355  1.1  agc    error" and stop.
   1356  1.1  agc 
   1357  1.1  agc    10. If pHash' does not equal pHash, output "decoding error" and stop.
   1358  1.1  agc 
   1359  1.1  agc    11. Output M.
   1360  1.1  agc 
   1361  1.1  agc 9.1.2 EME-PKCS1-v1_5
   1362  1.1  agc 
   1363  1.1  agc    This encoding method is the same as in PKCS #1 v1.5, Section 8:
   1364  1.1  agc    Encryption Process.
   1365  1.1  agc 
   1366  1.1  agc 
   1367  1.1  agc 
   1368  1.1  agc 
   1369  1.1  agc Kaliski & Staddon            Informational                     [Page 24]
   1370  1.1  agc 
   1372  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1373  1.1  agc 
   1374  1.1  agc 
   1375  1.1  agc 9.1.2.1 Encoding operation
   1376  1.1  agc 
   1377  1.1  agc    EME-PKCS1-V1_5-ENCODE (M, emLen)
   1378  1.1  agc 
   1379  1.1  agc    Input:
   1380  1.1  agc    M         message to be encoded, an octet string of length at most
   1381  1.1  agc              emLen-10
   1382  1.1  agc    emLen     intended length in octets of the encoded message
   1383  1.1  agc 
   1384  1.1  agc    Output:
   1385  1.1  agc    EM        encoded message, an octet string of length emLen; or
   1386  1.1  agc              "message too long"
   1387  1.1  agc 
   1388  1.1  agc    Steps:
   1389  1.1  agc 
   1390  1.1  agc    1. If the length of the message M is greater than emLen - 10 octets,
   1391  1.1  agc    output "message too long" and stop.
   1392  1.1  agc 
   1393  1.1  agc    2. Generate an octet string PS of length emLen-||M||-2 consisting of
   1394  1.1  agc    pseudorandomly generated nonzero octets. The length of PS will be at
   1395  1.1  agc    least 8 octets.
   1396  1.1  agc 
   1397  1.1  agc    3. Concatenate PS, the message M, and other padding to form the
   1398  1.1  agc    encoded message EM as:
   1399  1.1  agc 
   1400  1.1  agc    EM = 02 || PS || 00 || M
   1401  1.1  agc 
   1402  1.1  agc    4. Output EM.
   1403  1.1  agc 
   1404  1.1  agc 9.1.2.2 Decoding operation
   1405  1.1  agc 
   1406  1.1  agc    EME-PKCS1-V1_5-DECODE (EM)
   1407  1.1  agc 
   1408  1.1  agc    Input:
   1409  1.1  agc    EM      encoded message, an octet string of length at least 10
   1410  1.1  agc 
   1411  1.1  agc    Output:
   1412  1.1  agc    M       recovered message, an octet string of length at most
   1413  1.1  agc            ||EM||-10; or "decoding error"
   1414  1.1  agc 
   1415  1.1  agc    Steps:
   1416  1.1  agc 
   1417  1.1  agc    1. If the length of the encoded message EM is less than 10, output
   1418  1.1  agc    "decoding error" and stop.
   1419  1.1  agc 
   1420  1.1  agc    2. Separate the encoded message EM into an octet string PS consisting
   1421  1.1  agc    of nonzero octets and a message M as: EM = 02 || PS || 00 || M.
   1422  1.1  agc 
   1423  1.1  agc 
   1424  1.1  agc 
   1425  1.1  agc 
   1426  1.1  agc Kaliski & Staddon            Informational                     [Page 25]
   1427  1.1  agc 
   1429  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1430  1.1  agc 
   1431  1.1  agc 
   1432  1.1  agc    If the first octet of EM is not 02, or if there is no 00 octet to
   1433  1.1  agc    separate PS from M, output "decoding error" and stop.
   1434  1.1  agc 
   1435  1.1  agc    3. If the length of PS is less than 8 octets, output "decoding error"
   1436  1.1  agc    and stop.
   1437  1.1  agc 
   1438  1.1  agc    4. Output M.
   1439  1.1  agc 
   1440  1.1  agc 9.2 Encoding methods for signatures with appendix
   1441  1.1  agc 
   1442  1.1  agc    An encoding method for signatures with appendix, for the purposes of
   1443  1.1  agc    this document, consists of an encoding operation. An encoding
   1444  1.1  agc    operation maps a message M to a message representative EM of a
   1445  1.1  agc    specified length. (In future versions of this document, encoding
   1446  1.1  agc    methods may be added that also include a decoding operation.)
   1447  1.1  agc 
   1448  1.1  agc    One encoding method for signatures with appendix is employed in the
   1449  1.1  agc    encryption schemes and is specified here: EMSA-PKCS1-v1_5.
   1450  1.1  agc 
   1451  1.1  agc 9.2.1 EMSA-PKCS1-v1_5
   1452  1.1  agc 
   1453  1.1  agc    This encoding method only has an encoding operation.
   1454  1.1  agc 
   1455  1.1  agc    EMSA-PKCS1-v1_5-ENCODE (M, emLen)
   1456  1.1  agc 
   1457  1.1  agc    Option:
   1458  1.1  agc    Hash      hash function (hLen denotes the length in octet of the hash
   1459  1.1  agc              function output)
   1460  1.1  agc 
   1461  1.1  agc    Input:
   1462  1.1  agc    M         message to be encoded
   1463  1.1  agc    emLen     intended length in octets of the encoded message, at least
   1464  1.1  agc              ||T|| + 10, where T is the DER encoding of a certain value
   1465  1.1  agc              computed during the encoding operation
   1466  1.1  agc 
   1467  1.1  agc    Output:
   1468  1.1  agc    EM        encoded message, an octet string of length emLen; or "message
   1469  1.1  agc              too long" or "intended encoded message length too short"
   1470  1.1  agc 
   1471  1.1  agc    Steps:
   1472  1.1  agc 
   1473  1.1  agc    1. Apply the hash function to the message M to produce a hash value
   1474  1.1  agc    H:
   1475  1.1  agc 
   1476  1.1  agc    H = Hash(M).
   1477  1.1  agc 
   1478  1.1  agc    If the hash function outputs "message too long," then output "message
   1479  1.1  agc    too long".
   1480  1.1  agc 
   1481  1.1  agc 
   1482  1.1  agc 
   1483  1.1  agc Kaliski & Staddon            Informational                     [Page 26]
   1484  1.1  agc 
   1486  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1487  1.1  agc 
   1488  1.1  agc 
   1489  1.1  agc    2. Encode the algorithm ID for the hash function and the hash value
   1490  1.1  agc    into an ASN.1 value of type DigestInfo (see Section 11) with the
   1491  1.1  agc    Distinguished Encoding Rules (DER), where the type DigestInfo has the
   1492  1.1  agc    syntax
   1493  1.1  agc 
   1494  1.1  agc    DigestInfo::=SEQUENCE{
   1495  1.1  agc      digestAlgorithm  AlgorithmIdentifier,
   1496  1.1  agc      digest OCTET STRING }
   1497  1.1  agc 
   1498  1.1  agc    The first field identifies the hash function and the second contains
   1499  1.1  agc    the hash value. Let T be the DER encoding.
   1500  1.1  agc 
   1501  1.1  agc    3. If emLen is less than ||T|| + 10 then output "intended encoded
   1502  1.1  agc    message length too short".
   1503  1.1  agc 
   1504  1.1  agc    4. Generate an octet string PS consisting of emLen-||T||-2 octets
   1505  1.1  agc    with value FF (hexadecimal). The length of PS will be at least 8
   1506  1.1  agc    octets.
   1507  1.1  agc 
   1508  1.1  agc    5. Concatenate PS, the DER encoding T, and other padding to form the
   1509  1.1  agc    encoded message EM as: EM = 01 || PS || 00 || T
   1510  1.1  agc 
   1511  1.1  agc    6. Output EM.
   1512  1.1  agc 
   1513  1.1  agc 10. Auxiliary Functions
   1514  1.1  agc 
   1515  1.1  agc    This section specifies the hash functions and the mask generation
   1516  1.1  agc    functions that are mentioned in the encoding methods (Section 9).
   1517  1.1  agc 
   1518  1.1  agc 10.1 Hash Functions
   1519  1.1  agc 
   1520  1.1  agc    Hash functions are used in the operations contained in Sections 7, 8
   1521  1.1  agc    and 9. Hash functions are deterministic, meaning that the output is
   1522  1.1  agc    completely determined by the input. Hash functions take octet strings
   1523  1.1  agc    of variable length, and generate fixed length octet strings. The hash
   1524  1.1  agc    functions used in the operations contained in Sections 7, 8 and 9
   1525  1.1  agc    should be collision resistant. This means that it is infeasible to
   1526  1.1  agc    find two distinct inputs to the hash function that produce the same
   1527  1.1  agc    output. A collision resistant hash function also has the desirable
   1528  1.1  agc    property of being one-way; this means that given an output, it is
   1529  1.1  agc    infeasible to find an input whose hash is the specified output. The
   1530  1.1  agc    property of collision resistance is especially desirable for RSASSA-
   1531  1.1  agc    PKCS1-v1_5, as it makes it infeasible to forge signatures. In
   1532  1.1  agc    addition to the requirements, the hash function should yield a mask
   1533  1.1  agc    generation function  (Section 10.2) with pseudorandom output.
   1534  1.1  agc 
   1535  1.1  agc 
   1536  1.1  agc 
   1537  1.1  agc 
   1538  1.1  agc 
   1539  1.1  agc 
   1540  1.1  agc Kaliski & Staddon            Informational                     [Page 27]
   1541  1.1  agc 
   1543  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1544  1.1  agc 
   1545  1.1  agc 
   1546  1.1  agc    Three hash functions are recommended for the encoding methods in this
   1547  1.1  agc    document: MD2 [15], MD5 [17], and SHA-1 [16]. For the EME-OAEP
   1548  1.1  agc    encoding method, only SHA-1 is recommended. For the EMSA-PKCS1-v1_5
   1549  1.1  agc    encoding method, SHA-1 is recommended for new applications. MD2 and
   1550  1.1  agc    MD5 are recommended only for compatibility with existing applications
   1551  1.1  agc    based on PKCS #1 v1.5.
   1552  1.1  agc 
   1553  1.1  agc    The hash functions themselves are not defined here; readers are
   1554  1.1  agc    referred to the appropriate references ([15], [17] and [16]).
   1555  1.1  agc 
   1556  1.1  agc    Note. Version 1.5 of this document also allowed for the use of MD4 in
   1557  1.1  agc    signature schemes. The cryptanalysis of MD4 has progressed
   1558  1.1  agc    significantly in the intervening years. For example, Dobbertin [10]
   1559  1.1  agc    demonstrated how to find collisions for MD4 and that the first two
   1560  1.1  agc    rounds of MD4 are not one-way [11]. Because of these results and
   1561  1.1  agc    others (e.g. [9]), MD4 is no longer recommended. There have also been
   1562  1.1  agc    advances in the cryptanalysis of MD2 and MD5, although not enough to
   1563  1.1  agc    warrant removal from existing applications. Rogier and Chauvaud [19]
   1564  1.1  agc    demonstrated how to find collisions in a modified version of MD2. No
   1565  1.1  agc    one has demonstrated how to find collisions for the full MD5
   1566  1.1  agc    algorithm, although partial results have been found (e.g. [8]). For
   1567  1.1  agc    new applications, to address these concerns, SHA-1 is preferred.
   1568  1.1  agc 
   1569  1.1  agc 10.2 Mask Generation Functions
   1570  1.1  agc 
   1571  1.1  agc    A mask generation function takes an octet string of variable length
   1572  1.1  agc    and a desired output length as input, and outputs an octet string of
   1573  1.1  agc    the desired length. There may be restrictions on the length of the
   1574  1.1  agc    input and output octet strings, but such bounds are generally very
   1575  1.1  agc    large. Mask generation functions are deterministic; the octet string
   1576  1.1  agc    output is completely determined by the input octet string. The output
   1577  1.1  agc    of a mask generation function should be pseudorandom, that is, if the
   1578  1.1  agc    seed to the function is unknown, it should be infeasible to
   1579  1.1  agc    distinguish the output from a truly random string. The plaintext-
   1580  1.1  agc    awareness of RSAES-OAEP relies on the random nature of the output of
   1581  1.1  agc    the mask generation function, which in turn relies on the random
   1582  1.1  agc    nature of the underlying hash.
   1583  1.1  agc 
   1584  1.1  agc    One mask generation function is recommended for the encoding methods
   1585  1.1  agc    in this document, and is defined here: MGF1, which is based on a hash
   1586  1.1  agc    function. Future versions of this document may define other mask
   1587  1.1  agc    generation functions.
   1588  1.1  agc 
   1589  1.1  agc 10.2.1 MGF1
   1590  1.1  agc 
   1591  1.1  agc    MGF1 is a Mask Generation Function based on a hash function.
   1592  1.1  agc 
   1593  1.1  agc    MGF1 (Z, l)
   1594  1.1  agc 
   1595  1.1  agc 
   1596  1.1  agc 
   1597  1.1  agc Kaliski & Staddon            Informational                     [Page 28]
   1598  1.1  agc 
   1600  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1601  1.1  agc 
   1602  1.1  agc 
   1603  1.1  agc    Options:
   1604  1.1  agc    Hash    hash function (hLen denotes the length in octets of the hash
   1605  1.1  agc            function output)
   1606  1.1  agc 
   1607  1.1  agc    Input:
   1608  1.1  agc    Z       seed from which mask is generated, an octet string
   1609  1.1  agc    l       intended length in octets of the mask, at most 2^32(hLen)
   1610  1.1  agc 
   1611  1.1  agc    Output:
   1612  1.1  agc    mask    mask, an octet string of length l; or "mask too long"
   1613  1.1  agc 
   1614  1.1  agc    Steps:
   1615  1.1  agc 
   1616  1.1  agc    1.If l > 2^32(hLen), output "mask too long" and stop.
   1617  1.1  agc 
   1618  1.1  agc    2.Let T  be the empty octet string.
   1619  1.1  agc 
   1620  1.1  agc    3.For counter from 0 to \lceil{l / hLen}\rceil-1, do the following:
   1621  1.1  agc 
   1622  1.1  agc    a.Convert counter to an octet string C of length 4 with the primitive
   1623  1.1  agc    I2OSP: C = I2OSP (counter, 4)
   1624  1.1  agc 
   1625  1.1  agc    b.Concatenate the hash of the seed Z and C to the octet string T: T =
   1626  1.1  agc    T || Hash (Z || C)
   1627  1.1  agc 
   1628  1.1  agc    4.Output the leading l octets of T as the octet string mask.
   1629  1.1  agc 
   1630  1.1  agc 11. ASN.1 syntax
   1631  1.1  agc 
   1632  1.1  agc 11.1 Key representation
   1633  1.1  agc 
   1634  1.1  agc    This section defines ASN.1 object identifiers for RSA public and
   1635  1.1  agc    private keys, and defines the types RSAPublicKey and RSAPrivateKey.
   1636  1.1  agc    The intended application of these definitions includes X.509
   1637  1.1  agc    certificates, PKCS #8 [22], and PKCS #12 [23].
   1638  1.1  agc 
   1639  1.1  agc    The object identifier rsaEncryption identifies RSA public and private
   1640  1.1  agc    keys as defined in Sections 11.1.1 and 11.1.2. The parameters field
   1641  1.1  agc    associated with this OID in an AlgorithmIdentifier shall have type
   1642  1.1  agc    NULL.
   1643  1.1  agc 
   1644  1.1  agc    rsaEncryption OBJECT IDENTIFIER ::= {pkcs-1 1}
   1645  1.1  agc 
   1646  1.1  agc    All of the definitions in this section are the same as in PKCS #1
   1647  1.1  agc    v1.5.
   1648  1.1  agc 
   1649  1.1  agc 
   1650  1.1  agc 
   1651  1.1  agc 
   1652  1.1  agc 
   1653  1.1  agc 
   1654  1.1  agc Kaliski & Staddon            Informational                     [Page 29]
   1655  1.1  agc 
   1657  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1658  1.1  agc 
   1659  1.1  agc 
   1660  1.1  agc 11.1.1 Public-key syntax
   1661  1.1  agc 
   1662  1.1  agc    An RSA public key should be represented with the ASN.1 type
   1663  1.1  agc    RSAPublicKey:
   1664  1.1  agc 
   1665  1.1  agc    RSAPublicKey::=SEQUENCE{
   1666  1.1  agc      modulus INTEGER, -- n
   1667  1.1  agc      publicExponent INTEGER -- e }
   1668  1.1  agc 
   1669  1.1  agc    (This type is specified in X.509 and is retained here for
   1670  1.1  agc    compatibility.)
   1671  1.1  agc 
   1672  1.1  agc    The fields of type RSAPublicKey have the following meanings:
   1673  1.1  agc    -modulus is the modulus n.
   1674  1.1  agc    -publicExponent is the public exponent e.
   1675  1.1  agc 
   1676  1.1  agc 11.1.2 Private-key syntax
   1677  1.1  agc 
   1678  1.1  agc    An RSA private key should be represented with ASN.1 type
   1679  1.1  agc    RSAPrivateKey:
   1680  1.1  agc 
   1681  1.1  agc    RSAPrivateKey ::= SEQUENCE {
   1682  1.1  agc      version Version,
   1683  1.1  agc      modulus INTEGER, -- n
   1684  1.1  agc      publicExponent INTEGER, -- e
   1685  1.1  agc      privateExponent INTEGER, -- d
   1686  1.1  agc      prime1 INTEGER, -- p
   1687  1.1  agc      prime2 INTEGER, -- q
   1688  1.1  agc      exponent1 INTEGER, -- d mod (p-1)
   1689  1.1  agc      exponent2 INTEGER, -- d mod (q-1)
   1690  1.1  agc      coefficient INTEGER -- (inverse of q) mod p }
   1691  1.1  agc 
   1692  1.1  agc    Version ::= INTEGER
   1693  1.1  agc 
   1694  1.1  agc    The fields of type RSAPrivateKey have the following meanings:
   1695  1.1  agc 
   1696  1.1  agc    -version is the version number, for compatibility with future
   1697  1.1  agc    revisions of this document. It shall be 0 for this version of the
   1698  1.1  agc    document.
   1699  1.1  agc    -modulus is the modulus n.
   1700  1.1  agc    -publicExponent is the public exponent e.
   1701  1.1  agc    -privateExponent is the private exponent d.
   1702  1.1  agc    -prime1 is the prime factor p of n.
   1703  1.1  agc    -prime2 is the prime factor q of n.
   1704  1.1  agc    -exponent1 is d mod (p-1).
   1705  1.1  agc    -exponent2 is d mod (q-1).
   1706  1.1  agc    -coefficient is the Chinese Remainder Theorem coefficient q-1 mod p.
   1707  1.1  agc 
   1708  1.1  agc 
   1709  1.1  agc 
   1710  1.1  agc 
   1711  1.1  agc Kaliski & Staddon            Informational                     [Page 30]
   1712  1.1  agc 
   1714  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1715  1.1  agc 
   1716  1.1  agc 
   1717  1.1  agc 11.2 Scheme identification
   1718  1.1  agc 
   1719  1.1  agc    This section defines object identifiers for the encryption and
   1720  1.1  agc    signature schemes. The schemes compatible with PKCS #1 v1.5 have the
   1721  1.1  agc    same definitions as in PKCS #1 v1.5. The intended application of
   1722  1.1  agc    these definitions includes X.509 certificates and PKCS #7.
   1723  1.1  agc 
   1724  1.1  agc 11.2.1 Syntax for RSAES-OAEP
   1725  1.1  agc 
   1726  1.1  agc    The object identifier id-RSAES-OAEP identifies the RSAES-OAEP
   1727  1.1  agc    encryption scheme.
   1728  1.1  agc 
   1729  1.1  agc    id-RSAES-OAEP OBJECT IDENTIFIER ::= {pkcs-1 7}
   1730  1.1  agc 
   1731  1.1  agc    The parameters field associated with this OID in an
   1732  1.1  agc    AlgorithmIdentifier shall have type RSAEP-OAEP-params:
   1733  1.1  agc 
   1734  1.1  agc    RSAES-OAEP-params ::=  SEQUENCE {
   1735  1.1  agc      hashFunc [0] AlgorithmIdentifier {{oaepDigestAlgorithms}}
   1736  1.1  agc        DEFAULT sha1Identifier,
   1737  1.1  agc      maskGenFunc [1] AlgorithmIdentifier {{pkcs1MGFAlgorithms}}
   1738  1.1  agc        DEFAULT mgf1SHA1Identifier,
   1739  1.1  agc      pSourceFunc [2] AlgorithmIdentifier
   1740  1.1  agc        {{pkcs1pSourceAlgorithms}}
   1741  1.1  agc        DEFAULT pSpecifiedEmptyIdentifier }
   1742  1.1  agc 
   1743  1.1  agc    The fields of type RSAES-OAEP-params have the following meanings:
   1744  1.1  agc 
   1745  1.1  agc    -hashFunc identifies the hash function. It shall be an algorithm ID
   1746  1.1  agc    with an OID in the set oaepDigestAlgorithms, which for this version
   1747  1.1  agc    shall consist of id-sha1, identifying the SHA-1 hash function. The
   1748  1.1  agc    parameters field for id-sha1 shall have type NULL.
   1749  1.1  agc 
   1750  1.1  agc    oaepDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
   1751  1.1  agc      {NULL IDENTIFIED BY id-sha1} }
   1752  1.1  agc 
   1753  1.1  agc    id-sha1 OBJECT IDENTIFIER ::=
   1754  1.1  agc      {iso(1) identified-organization(3) oiw(14) secsig(3)
   1755  1.1  agc        algorithms(2) 26}
   1756  1.1  agc 
   1757  1.1  agc 
   1758  1.1  agc    The default hash function is SHA-1:
   1759  1.1  agc    sha1Identifier ::= AlgorithmIdentifier {id-sha1, NULL}
   1760  1.1  agc 
   1761  1.1  agc    -maskGenFunc identifies the mask generation function. It shall be an
   1762  1.1  agc    algorithm ID with an OID in the set pkcs1MGFAlgorithms, which for
   1763  1.1  agc    this version shall consist of id-mgf1, identifying the MGF1 mask
   1764  1.1  agc    generation function (see Section 10.2.1). The parameters field for
   1765  1.1  agc 
   1766  1.1  agc 
   1767  1.1  agc 
   1768  1.1  agc Kaliski & Staddon            Informational                     [Page 31]
   1769  1.1  agc 
   1771  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1772  1.1  agc 
   1773  1.1  agc 
   1774  1.1  agc    id-mgf1 shall have type AlgorithmIdentifier, identifying the hash
   1775  1.1  agc    function on which MGF1 is based, where the OID for the hash function
   1776  1.1  agc    shall be in the set oaepDigestAlgorithms.
   1777  1.1  agc 
   1778  1.1  agc    pkcs1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
   1779  1.1  agc      {AlgorithmIdentifier {{oaepDigestAlgorithms}} IDENTIFIED
   1780  1.1  agc        BY id-mgf1} }
   1781  1.1  agc 
   1782  1.1  agc    id-mgf1 OBJECT IDENTIFIER ::= {pkcs-1 8}
   1783  1.1  agc 
   1784  1.1  agc    The default mask generation function is MGF1 with SHA-1:
   1785  1.1  agc 
   1786  1.1  agc    mgf1SHA1Identifier ::= AlgorithmIdentifier {
   1787  1.1  agc      id-mgf1, sha1Identifier }
   1788  1.1  agc 
   1789  1.1  agc    -pSourceFunc identifies the source (and possibly the value) of the
   1790  1.1  agc    encoding parameters P. It shall be an algorithm ID with an OID in the
   1791  1.1  agc    set pkcs1pSourceAlgorithms, which for this version shall consist of
   1792  1.1  agc    id-pSpecified, indicating that the encoding parameters are specified
   1793  1.1  agc    explicitly. The parameters field for id-pSpecified shall have type
   1794  1.1  agc    OCTET STRING, containing the encoding parameters.
   1795  1.1  agc 
   1796  1.1  agc    pkcs1pSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
   1797  1.1  agc      {OCTET STRING IDENTIFIED BY id-pSpecified} }
   1798  1.1  agc 
   1799  1.1  agc    id-pSpecified OBJECT IDENTIFIER ::= {pkcs-1 9}
   1800  1.1  agc 
   1801  1.1  agc    The default encoding parameters is an empty string (so that pHash in
   1802  1.1  agc    EME-OAEP will contain the hash of the empty string):
   1803  1.1  agc 
   1804  1.1  agc    pSpecifiedEmptyIdentifier ::= AlgorithmIdentifier {
   1805  1.1  agc      id-pSpecified, OCTET STRING SIZE (0) }
   1806  1.1  agc 
   1807  1.1  agc    If all of the default values of the fields in RSAES-OAEP-params are
   1808  1.1  agc    used, then the algorithm identifier will have the following value:
   1809  1.1  agc 
   1810  1.1  agc    RSAES-OAEP-Default-Identifier ::= AlgorithmIdentifier {
   1811  1.1  agc      id-RSAES-OAEP,
   1812  1.1  agc      {sha1Identifier,
   1813  1.1  agc       mgf1SHA1Identifier,
   1814  1.1  agc       pSpecifiedEmptyIdentifier } }
   1815  1.1  agc 
   1816  1.1  agc 11.2.2 Syntax for RSAES-PKCS1-v1_5
   1817  1.1  agc 
   1818  1.1  agc    The object identifier rsaEncryption (Section 11.1) identifies the
   1819  1.1  agc    RSAES-PKCS1-v1_5 encryption scheme. The parameters field associated
   1820  1.1  agc    with this OID in an AlgorithmIdentifier shall have type NULL. This is
   1821  1.1  agc    the same as in PKCS #1 v1.5.
   1822  1.1  agc 
   1823  1.1  agc 
   1824  1.1  agc 
   1825  1.1  agc Kaliski & Staddon            Informational                     [Page 32]
   1826  1.1  agc 
   1828  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1829  1.1  agc 
   1830  1.1  agc 
   1831  1.1  agc    RsaEncryption   OBJECT IDENTIFIER ::= {PKCS-1 1}
   1832  1.1  agc 
   1833  1.1  agc 11.2.3 Syntax for RSASSA-PKCS1-v1_5
   1834  1.1  agc 
   1835  1.1  agc    The object identifier for RSASSA-PKCS1-v1_5 shall be one of the
   1836  1.1  agc    following. The choice of OID depends on the choice of hash algorithm:
   1837  1.1  agc    MD2, MD5 or SHA-1. Note that if either MD2 or MD5 is used then the
   1838  1.1  agc    OID is just as in PKCS #1 v1.5. For each OID, the parameters field
   1839  1.1  agc    associated with this OID in an AlgorithmIdentifier shall have type
   1840  1.1  agc    NULL.
   1841  1.1  agc 
   1842  1.1  agc    If the hash function to be used is MD2, then the OID should be:
   1843  1.1  agc 
   1844  1.1  agc    md2WithRSAEncryption ::= {PKCS-1 2}
   1845  1.1  agc 
   1846  1.1  agc    If the hash function to be used is MD5, then the OID should be:
   1847  1.1  agc 
   1848  1.1  agc    md5WithRSAEncryption ::= {PKCS-1 4}
   1849  1.1  agc 
   1850  1.1  agc    If the hash function to be used is SHA-1, then the OID should be:
   1851  1.1  agc 
   1852  1.1  agc    sha1WithRSAEncryption ::= {pkcs-1 5}
   1853  1.1  agc 
   1854  1.1  agc    In the digestInfo type mentioned in Section 9.2.1 the OIDS for the
   1855  1.1  agc    digest algorithm are the following:
   1856  1.1  agc 
   1857  1.1  agc    id-SHA1 OBJECT IDENTIFIER ::=
   1858  1.1  agc            {iso(1) identified-organization(3) oiw(14) secsig(3)
   1859  1.1  agc             algorithms(2) 26 }
   1860  1.1  agc 
   1861  1.1  agc    md2 OBJECT IDENTIFIER ::=
   1862  1.1  agc            {iso(1) member-body(2) US(840) rsadsi(113549)
   1863  1.1  agc             digestAlgorithm(2) 2}
   1864  1.1  agc 
   1865  1.1  agc    md5 OBJECT IDENTIFIER ::=
   1866  1.1  agc            {iso(1) member-body(2) US(840) rsadsi(113549)
   1867  1.1  agc             digestAlgorithm(2) 5}
   1868  1.1  agc 
   1869  1.1  agc    The parameters field of the digest algorithm has ASN.1 type NULL for
   1870  1.1  agc    these OIDs.
   1871  1.1  agc 
   1872  1.1  agc 12. Patent statement
   1873  1.1  agc 
   1874  1.1  agc    The Internet Standards Process as defined in RFC 1310 requires a
   1875  1.1  agc    written statement from the Patent holder that a license will be made
   1876  1.1  agc    available to applicants under reasonable terms and conditions prior
   1877  1.1  agc    to approving a specification as a Proposed, Draft or Internet
   1878  1.1  agc    Standard.
   1879  1.1  agc 
   1880  1.1  agc 
   1881  1.1  agc 
   1882  1.1  agc Kaliski & Staddon            Informational                     [Page 33]
   1883  1.1  agc 
   1885  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1886  1.1  agc 
   1887  1.1  agc 
   1888  1.1  agc    The Internet Society, Internet Architecture Board, Internet
   1889  1.1  agc    Engineering Steering Group and the Corporation for National Research
   1890  1.1  agc    Initiatives take no position on the validity or scope of the
   1891  1.1  agc    following patents and patent applications, nor on the appropriateness
   1892  1.1  agc    of the terms of the assurance. The Internet Society and other groups
   1893  1.1  agc    mentioned above have not made any determination as to any other
   1894  1.1  agc    intellectual property rights which may apply to the practice of this
   1895  1.1  agc    standard.  Any further consideration of these matters is the user's
   1896  1.1  agc    responsibility.
   1897  1.1  agc 
   1898  1.1  agc 12.1 Patent statement for the RSA algorithm
   1899  1.1  agc 
   1900  1.1  agc    The Massachusetts Institute of Technology has granted RSA Data
   1901  1.1  agc    Security, Inc., exclusive sub-licensing rights to the following
   1902  1.1  agc    patent issued in the United States:
   1903  1.1  agc 
   1904  1.1  agc    Cryptographic Communications System and Method ("RSA"), No. 4,405,829
   1905  1.1  agc 
   1906  1.1  agc    RSA Data Security, Inc. has provided the following statement with
   1907  1.1  agc    regard to this patent:
   1908  1.1  agc 
   1909  1.1  agc    It is RSA's business practice to make licenses to its patents
   1910  1.1  agc    available on reasonable and nondiscriminatory terms. Accordingly, RSA
   1911  1.1  agc    is willing, upon request, to grant non-exclusive licenses to such
   1912  1.1  agc    patent on reasonable and non-discriminatory terms and conditions to
   1913  1.1  agc    those who respect RSA's intellectual property rights and subject to
   1914  1.1  agc    RSA's then current royalty rate for the patent licensed. The royalty
   1915  1.1  agc    rate for the RSA patent is presently set at 2% of the licensee's
   1916  1.1  agc    selling price for each product covered by the patent.  Any requests
   1917  1.1  agc    for license information may be directed to:
   1918  1.1  agc 
   1919  1.1  agc             Director of Licensing
   1920  1.1  agc             RSA Data Security, Inc.
   1921  1.1  agc             2955 Campus Drive
   1922  1.1  agc             Suite 400
   1923  1.1  agc             San Mateo, CA 94403
   1924  1.1  agc 
   1925  1.1  agc    A license under RSA's patent(s) does not include any rights to know-
   1926  1.1  agc    how or other technical information or license under other
   1927  1.1  agc    intellectual property rights.  Such license does not extend to any
   1928  1.1  agc    activities which constitute infringement or inducement thereto. A
   1929  1.1  agc    licensee must make his own determination as to whether a license is
   1930  1.1  agc    necessary under patents of others.
   1931  1.1  agc 
   1932  1.1  agc 
   1933  1.1  agc 
   1934  1.1  agc 
   1935  1.1  agc 
   1936  1.1  agc 
   1937  1.1  agc 
   1938  1.1  agc 
   1939  1.1  agc Kaliski & Staddon            Informational                     [Page 34]
   1940  1.1  agc 
   1942  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   1943  1.1  agc 
   1944  1.1  agc 
   1945  1.1  agc 13. Revision history
   1946  1.1  agc 
   1947  1.1  agc    Versions 1.0-1.3
   1948  1.1  agc 
   1949  1.1  agc    Versions 1.0-1.3 were distributed to participants in RSA Data
   1950  1.1  agc    Security, Inc.'s Public-Key Cryptography Standards meetings in
   1951  1.1  agc    February and March 1991.
   1952  1.1  agc 
   1953  1.1  agc 
   1954  1.1  agc    Version 1.4
   1955  1.1  agc 
   1956  1.1  agc    Version 1.4 was part of the June 3, 1991 initial public release of
   1957  1.1  agc    PKCS. Version 1.4 was published as NIST/OSI Implementors' Workshop
   1958  1.1  agc    document SEC-SIG-91-18.
   1959  1.1  agc 
   1960  1.1  agc 
   1961  1.1  agc    Version 1.5
   1962  1.1  agc 
   1963  1.1  agc    Version 1.5 incorporates several editorial changes, including updates
   1964  1.1  agc    to the references and the addition of a revision history. The
   1965  1.1  agc    following substantive changes were made: -Section 10: "MD4 with RSA"
   1966  1.1  agc    signature and verification processes were added.
   1967  1.1  agc 
   1968  1.1  agc    -Section 11: md4WithRSAEncryption object identifier was added.
   1969  1.1  agc 
   1970  1.1  agc    Version 2.0 [DRAFT]
   1971  1.1  agc 
   1972  1.1  agc    Version 2.0 incorporates major editorial changes in terms of the
   1973  1.1  agc    document structure, and introduces the RSAEP-OAEP encryption scheme.
   1974  1.1  agc    This version continues to support the encryption and signature
   1975  1.1  agc    processes in version 1.5, although the hash algorithm MD4 is no
   1976  1.1  agc    longer allowed due to cryptanalytic advances in the intervening
   1977  1.1  agc    years.
   1978  1.1  agc 
   1979  1.1  agc 14. References
   1980  1.1  agc 
   1981  1.1  agc    [1] ANSI, ANSI X9.44: Key Management Using Reversible Public Key
   1982  1.1  agc        Cryptography for the Financial Services Industry. Work in
   1983  1.1  agc        Progress.
   1984  1.1  agc 
   1985  1.1  agc    [2] M. Bellare and P. Rogaway. Optimal Asymmetric Encryption - How to
   1986  1.1  agc        Encrypt with RSA. In Advances in Cryptology-Eurocrypt '94, pp.
   1987  1.1  agc        92-111, Springer-Verlag, 1994.
   1988  1.1  agc 
   1989  1.1  agc    [3] M. Bellare and P. Rogaway. The Exact Security of Digital
   1990  1.1  agc        Signatures - How to Sign with RSA and Rabin. In Advances in
   1991  1.1  agc        Cryptology-Eurocrypt '96, pp. 399-416, Springer-Verlag, 1996.
   1992  1.1  agc 
   1993  1.1  agc 
   1994  1.1  agc 
   1995  1.1  agc 
   1996  1.1  agc Kaliski & Staddon            Informational                     [Page 35]
   1997  1.1  agc 
   1999  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   2000  1.1  agc 
   2001  1.1  agc 
   2002  1.1  agc    [4] D. Bleichenbacher. Chosen Ciphertext Attacks against Protocols
   2003  1.1  agc        Based on the RSA Encryption Standard PKCS #1. To appear in
   2004  1.1  agc        Advances in Cryptology-Crypto '98.
   2005  1.1  agc 
   2006  1.1  agc    [5] D. Bleichenbacher, B. Kaliski and J. Staddon. Recent Results on
   2007  1.1  agc        PKCS #1: RSA Encryption Standard. RSA Laboratories' Bulletin,
   2008  1.1  agc        Number 7, June 24, 1998.
   2009  1.1  agc 
   2010  1.1  agc    [6] CCITT. Recommendation X.509: The Directory-Authentication
   2011  1.1  agc        Framework. 1988.
   2012  1.1  agc 
   2013  1.1  agc    [7] D. Coppersmith, M. Franklin, J. Patarin and M. Reiter. Low-
   2014  1.1  agc        Exponent RSA with Related Messages. In Advances in Cryptology-
   2015  1.1  agc        Eurocrypt '96, pp. 1-9, Springer-Verlag, 1996
   2016  1.1  agc 
   2017  1.1  agc    [8] B. Den Boer and Bosselaers. Collisions for the Compression
   2018  1.1  agc        Function of MD5. In Advances in Cryptology-Eurocrypt '93, pp
   2019  1.1  agc        293-304, Springer-Verlag, 1994.
   2020  1.1  agc 
   2021  1.1  agc    [9] B. den Boer, and A. Bosselaers. An Attack on the Last Two Rounds
   2022  1.1  agc        of MD4. In Advances in Cryptology-Crypto '91, pp.194-203,
   2023  1.1  agc        Springer-Verlag, 1992.
   2024  1.1  agc 
   2025  1.1  agc    [10] H. Dobbertin. Cryptanalysis of MD4. Fast Software Encryption.
   2026  1.1  agc         Lecture Notes in Computer Science, Springer-Verlag 1996, pp.
   2027  1.1  agc         55-72.
   2028  1.1  agc 
   2029  1.1  agc    [11] H. Dobbertin. Cryptanalysis of MD5 Compress. Presented at the
   2030  1.1  agc         rump session of Eurocrypt `96, May 14, 1996
   2031  1.1  agc 
   2032  1.1  agc    [12] H. Dobbertin.The First Two Rounds of MD4 are Not One-Way. Fast
   2033  1.1  agc         Software Encryption. Lecture Notes in Computer Science,
   2034  1.1  agc         Springer-Verlag 1998, pp. 284-292.
   2035  1.1  agc 
   2036  1.1  agc    [13] J. Hastad. Solving Simultaneous Modular Equations of Low Degree.
   2037  1.1  agc         SIAM Journal of Computing, 17, 1988, pp. 336-341.
   2038  1.1  agc 
   2039  1.1  agc    [14] IEEE. IEEE P1363: Standard Specifications for Public Key
   2040  1.1  agc         Cryptography. Draft Version 4.
   2041  1.1  agc 
   2042  1.1  agc    [15] Kaliski, B., "The MD2 Message-Digest Algorithm", RFC 1319, April
   2043  1.1  agc         1992.
   2044  1.1  agc 
   2045  1.1  agc    [16] National Institute of Standards and Technology (NIST). FIPS
   2046  1.1  agc         Publication 180-1: Secure Hash Standard. April 1994.
   2047  1.1  agc 
   2048  1.1  agc    [17] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April
   2049  1.1  agc         1992.
   2050  1.1  agc 
   2051  1.1  agc 
   2052  1.1  agc 
   2053  1.1  agc Kaliski & Staddon            Informational                     [Page 36]
   2054  1.1  agc 
   2056  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   2057  1.1  agc 
   2058  1.1  agc 
   2059  1.1  agc    [18] R. Rivest, A. Shamir and L. Adleman. A Method for Obtaining
   2060  1.1  agc         Digital Signatures and Public-Key Cryptosystems. Communications
   2061  1.1  agc         of the ACM, 21(2), pp. 120-126, February 1978.
   2062  1.1  agc 
   2063  1.1  agc    [19] N. Rogier and P. Chauvaud. The Compression Function of MD2 is
   2064  1.1  agc         not Collision Free. Presented at Selected Areas of Cryptography
   2065  1.1  agc         `95. Carleton University, Ottawa, Canada. May 18-19, 1995.
   2066  1.1  agc 
   2067  1.1  agc    [20] RSA Laboratories. PKCS #1: RSA Encryption Standard. Version 1.5,
   2068  1.1  agc         November 1993.
   2069  1.1  agc 
   2070  1.1  agc    [21] RSA Laboratories. PKCS #7: Cryptographic Message Syntax
   2071  1.1  agc         Standard. Version 1.5, November 1993.
   2072  1.1  agc 
   2073  1.1  agc    [22] RSA  Laboratories. PKCS #8: Private-Key Information Syntax
   2074  1.1  agc         Standard. Version 1.2, November 1993.
   2075  1.1  agc 
   2076  1.1  agc    [23] RSA Laboratories. PKCS #12: Personal Information Exchange Syntax
   2077  1.1  agc         Standard. Version 1.0, Work in Progress, April 1997.
   2078  1.1  agc 
   2079  1.1  agc Security Considerations
   2080  1.1  agc 
   2081  1.1  agc    Security issues are discussed throughout this memo.
   2082  1.1  agc 
   2083  1.1  agc Acknowledgements
   2084  1.1  agc 
   2085  1.1  agc    This document is based on a contribution of RSA Laboratories, a
   2086  1.1  agc    division of RSA Data Security, Inc.  Any substantial use of the text
   2087  1.1  agc    from this document must acknowledge RSA Data Security, Inc. RSA Data
   2088  1.1  agc    Security, Inc. requests that all material mentioning or referencing
   2089  1.1  agc    this document identify this as "RSA Data Security, Inc. PKCS #1
   2090  1.1  agc    v2.0".
   2091  1.1  agc 
   2092  1.1  agc 
   2093  1.1  agc 
   2094  1.1  agc 
   2095  1.1  agc 
   2096  1.1  agc 
   2097  1.1  agc 
   2098  1.1  agc 
   2099  1.1  agc 
   2100  1.1  agc 
   2101  1.1  agc 
   2102  1.1  agc 
   2103  1.1  agc 
   2104  1.1  agc 
   2105  1.1  agc 
   2106  1.1  agc 
   2107  1.1  agc 
   2108  1.1  agc 
   2109  1.1  agc 
   2110  1.1  agc Kaliski & Staddon            Informational                     [Page 37]
   2111  1.1  agc 
   2113  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   2114  1.1  agc 
   2115  1.1  agc 
   2116  1.1  agc Authors' Addresses
   2117  1.1  agc 
   2118  1.1  agc    Burt Kaliski
   2119  1.1  agc    RSA Laboratories East
   2120  1.1  agc    20 Crosby Drive
   2121  1.1  agc    Bedford, MA  01730
   2122  1.1  agc 
   2123  1.1  agc    Phone: (617) 687-7000
   2124  1.1  agc    EMail: burt (a] rsa.com
   2125  1.1  agc 
   2126  1.1  agc 
   2127  1.1  agc    Jessica Staddon
   2128  1.1  agc    RSA Laboratories West
   2129  1.1  agc    2955 Campus Drive
   2130  1.1  agc    Suite 400
   2131  1.1  agc    San Mateo, CA 94403
   2132  1.1  agc 
   2133  1.1  agc    Phone: (650) 295-7600
   2134  1.1  agc    EMail: jstaddon (a] rsa.com
   2135  1.1  agc 
   2136  1.1  agc 
   2137  1.1  agc 
   2138  1.1  agc 
   2139  1.1  agc 
   2140  1.1  agc 
   2141  1.1  agc 
   2142  1.1  agc 
   2143  1.1  agc 
   2144  1.1  agc 
   2145  1.1  agc 
   2146  1.1  agc 
   2147  1.1  agc 
   2148  1.1  agc 
   2149  1.1  agc 
   2150  1.1  agc 
   2151  1.1  agc 
   2152  1.1  agc 
   2153  1.1  agc 
   2154  1.1  agc 
   2155  1.1  agc 
   2156  1.1  agc 
   2157  1.1  agc 
   2158  1.1  agc 
   2159  1.1  agc 
   2160  1.1  agc 
   2161  1.1  agc 
   2162  1.1  agc 
   2163  1.1  agc 
   2164  1.1  agc 
   2165  1.1  agc 
   2166  1.1  agc 
   2167  1.1  agc Kaliski & Staddon            Informational                     [Page 38]
   2168  1.1  agc 
   2170  1.1  agc RFC 2437        PKCS #1: RSA Cryptography Specifications    October 1998
   2171  1.1  agc 
   2172  1.1  agc 
   2173  1.1  agc Full Copyright Statement
   2174  1.1  agc 
   2175  1.1  agc    Copyright (C) The Internet Society (1998).  All Rights Reserved.
   2176  1.1  agc 
   2177  1.1  agc    This document and translations of it may be copied and furnished to
   2178  1.1  agc    others, and derivative works that comment on or otherwise explain it
   2179  1.1  agc    or assist in its implementation may be prepared, copied, published
   2180  1.1  agc    and distributed, in whole or in part, without restriction of any
   2181  1.1  agc    kind, provided that the above copyright notice and this paragraph are
   2182  1.1  agc    included on all such copies and derivative works.  However, this
   2183  1.1  agc    document itself may not be modified in any way, such as by removing
   2184  1.1  agc    the copyright notice or references to the Internet Society or other
   2185  1.1  agc    Internet organizations, except as needed for the purpose of
   2186  1.1  agc    developing Internet standards in which case the procedures for
   2187  1.1  agc    copyrights defined in the Internet Standards process must be
   2188              followed, or as required to translate it into languages other than
   2189              English.
   2190           
   2191              The limited permissions granted above are perpetual and will not be
   2192              revoked by the Internet Society or its successors or assigns.
   2193           
   2194              This document and the information contained herein is provided on an
   2195              "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
   2196              TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
   2197              BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
   2198              HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
   2199              MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   2200           
   2201           
   2202           
   2203           
   2204           
   2205           
   2206           
   2207           
   2208           
   2209           
   2210           
   2211           
   2212           
   2213           
   2214           
   2215           
   2216           
   2217           
   2218           
   2219           
   2220           
   2221           
   2222           
   2223           
   2224           Kaliski & Staddon            Informational                     [Page 39]
   2225           
   2227