home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / rfc / 3 / rfc2313.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  36.9 KB  |  1,068 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                      B. Kaliski
  8. Request for Comments: 2313                      RSA Laboratories East
  9. Category: Informational                                    March 1998
  10.  
  11.  
  12.                         PKCS #1: RSA Encryption
  13.                               Version 1.5
  14.  
  15. Status of this Memo
  16.  
  17.    This memo provides information for the Internet community.  It does
  18.    not specify an Internet standard of any kind.  Distribution of this
  19.    memo is unlimited.
  20.  
  21. Copyright Notice
  22.  
  23.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  24.  
  25. Overview
  26.  
  27.    This document describes a method for encrypting data using the RSA
  28.    public-key cryptosystem.
  29.  
  30. 1. Scope
  31.  
  32.    This document describes a method for encrypting data using the RSA
  33.    public-key cryptosystem. Its intended use is in the construction of
  34.    digital signatures and digital envelopes, as described in PKCS #7:
  35.  
  36.         o    For digital signatures, the content to be signed
  37.              is first reduced to a message digest with a
  38.              message-digest algorithm (such as MD5), and then
  39.              an octet string containing the message digest is
  40.              encrypted with the RSA private key of the signer
  41.              of the content. The content and the encrypted
  42.              message digest are represented together according
  43.              to the syntax in PKCS #7 to yield a digital
  44.              signature. This application is compatible with
  45.              Privacy-Enhanced Mail (PEM) methods.
  46.  
  47.         o    For digital envelopes, the content to be enveloped
  48.              is first encrypted under a content-encryption key
  49.              with a content-encryption algorithm (such as DES),
  50.              and then the content-encryption key is encrypted
  51.              with the RSA public keys of the recipients of the
  52.              content. The encrypted content and the encrypted
  53.  
  54.  
  55.  
  56.  
  57.  
  58. Kaliski                      Informational                      [Page 1]
  59.  
  60. RFC 2313                PKCS #1: RSA Encryption               March 1998
  61.  
  62.  
  63.              content-encryption key are represented together
  64.              according to the syntax in PKCS #7 to yield a
  65.              digital envelope. This application is also
  66.              compatible with PEM methods.
  67.  
  68.    The document also describes a syntax for RSA public keys and private
  69.    keys. The public-key syntax would be used in certificates; the
  70.    private-key syntax would be used typically in PKCS #8 private-key
  71.    information. The public-key syntax is identical to that in both X.509
  72.    and Privacy-Enhanced Mail.  Thus X.509/PEM RSA keys can be used in
  73.    this document.
  74.  
  75.    The document also defines three signature algorithms for use in
  76.    signing X.509/PEM certificates and certificate-revocation lists, PKCS
  77.    #6 extended certificates, and other objects employing digital
  78.    signatures such as X.401 message tokens.
  79.  
  80.    Details on message-digest and content-encryption algorithms are
  81.    outside the scope of this document, as are details on sources of the
  82.    pseudorandom bits required by certain methods in this document.
  83.  
  84. 2. References
  85.  
  86.    FIPS PUB 46-1  National Bureau of Standards. FIPS PUB 46-1:
  87.              Data Encryption Standard. January 1988.
  88.  
  89.    PKCS #6   RSA Laboratories. PKCS #6: Extended-Certificate
  90.              Syntax. Version 1.5, November 1993.
  91.  
  92.    PKCS #7   RSA Laboratories. PKCS #7: Cryptographic Message
  93.              Syntax. Version 1.5, November 1993.
  94.  
  95.    PKCS #8   RSA Laboratories. PKCS #8: Private-Key Information
  96.              Syntax. Version 1.2, November 1993.
  97.  
  98.    RFC 1319  Kaliski, B., "The MD2 Message-Digest
  99.              Algorithm," RFC 1319, April 1992.
  100.  
  101.    RFC 1320  Rivest, R., "The MD4 Message-Digest
  102.              Algorithm," RFC 1320, April 1992.
  103.  
  104.    RFC 1321  Rivest, R., "The MD5 Message-Digest
  105.              Algorithm," RFC 1321, April 1992.
  106.  
  107.    RFC 1423  Balenson, D., "Privacy Enhancement for
  108.              Internet Electronic Mail: Part III: Algorithms,
  109.              Modes, and Identifiers," RFC 1423, February 1993.
  110.  
  111.  
  112.  
  113.  
  114. Kaliski                      Informational                      [Page 2]
  115.  
  116. RFC 2313                PKCS #1: RSA Encryption               March 1998
  117.  
  118.  
  119.    X.208     CCITT. Recommendation X.208: Specification of
  120.              Abstract Syntax Notation One (ASN.1). 1988.
  121.  
  122.    X.209     CCITT. Recommendation X.209: Specification of
  123.              Basic Encoding Rules for Abstract Syntax Notation
  124.              One (ASN.1). 1988.
  125.  
  126.    X.411     CCITT. Recommendation X.411: Message Handling
  127.              Systems: Message Transfer System: Abstract Service
  128.              Definition and Procedures.1988.
  129.  
  130.    X.509     CCITT. Recommendation X.509: The Directory--
  131.              Authentication Framework. 1988.
  132.  
  133.    [dBB92]   B. den Boer and A. Bosselaers. An attack on the
  134.              last two rounds of MD4. In J. Feigenbaum, editor,
  135.              Advances in Cryptology---CRYPTO '91 Proceedings,
  136.              volume 576 of Lecture Notes in Computer Science,
  137.              pages 194-203. Springer-Verlag, New York, 1992.
  138.  
  139.    [dBB93]   B. den Boer  and A. Bosselaers. Collisions for the
  140.              compression function of MD5. Presented at
  141.              EUROCRYPT '93 (Lofthus, Norway, May 24-27, 1993).
  142.  
  143.    [DO86]    Y. Desmedt and A.M. Odlyzko. A chosen text attack
  144.              on the RSA cryptosystem and some discrete
  145.              logarithm schemes. In H.C. Williams, editor,
  146.              Advances in Cryptology---CRYPTO '85 Proceedings,
  147.              volume 218 of Lecture Notes in Computer Science,
  148.              pages 516-521. Springer-Verlag, New York, 1986.
  149.  
  150.    [Has88]   Johan Hastad. Solving simultaneous modular
  151.              equations. SIAM Journal on Computing,
  152.              17(2):336-341, April 1988.
  153.  
  154.    [IM90]    Colin I'Anson and Chris Mitchell. Security defects
  155.              in CCITT Recommendation X.509--The directory
  156.              authentication framework. Computer Communications
  157.              Review, :30-34, April 1990.
  158.  
  159.    [Mer90]   R.C. Merkle. Note on MD4. Unpublished manuscript,
  160.              1990.
  161.  
  162.    [Mil76]   G.L. Miller. Riemann's hypothesis and tests for
  163.              primality. Journal of Computer and Systems
  164.              Sciences, 13(3):300-307, 1976.
  165.  
  166.  
  167.  
  168.  
  169.  
  170. Kaliski                      Informational                      [Page 3]
  171.  
  172. RFC 2313                PKCS #1: RSA Encryption               March 1998
  173.  
  174.  
  175.    [QC82]    J.-J. Quisquater and C. Couvreur. Fast
  176.              decipherment algorithm for RSA public-key
  177.              cryptosystem. Electronics Letters, 18(21):905-907,
  178.              October 1982.
  179.  
  180.    [RSA78]   R.L. Rivest, A. Shamir, and L. Adleman. A method
  181.              for obtaining digital signatures and public-key
  182.              cryptosystems. Communications of the ACM,
  183.              21(2):120-126, February 1978.
  184.  
  185. 3. Definitions
  186.  
  187.    For the purposes of this document, the following definitions apply.
  188.  
  189.    AlgorithmIdentifier: A type that identifies an algorithm (by object
  190.    identifier) and associated parameters. This type is defined in X.509.
  191.  
  192.    ASN.1: Abstract Syntax Notation One, as defined in X.208.
  193.  
  194.    BER: Basic Encoding Rules, as defined in X.209.
  195.  
  196.    DES: Data Encryption Standard, as defined in FIPS PUB 46-1.
  197.  
  198.    MD2: RSA Data Security, Inc.'s MD2 message-digest algorithm, as
  199.    defined in RFC 1319.
  200.  
  201.    MD4: RSA Data Security, Inc.'s MD4 message-digest algorithm, as
  202.    defined in RFC 1320.
  203.  
  204.    MD5: RSA Data Security, Inc.'s MD5 message-digest algorithm, as
  205.    defined in RFC 1321.
  206.  
  207.    modulus: Integer constructed as the product of two primes.
  208.  
  209.    PEM: Internet Privacy-Enhanced Mail, as defined in RFC 1423 and
  210.    related documents.
  211.  
  212.    RSA: The RSA public-key cryptosystem, as defined in [RSA78].
  213.  
  214.    private key: Modulus and private exponent.
  215.  
  216.    public key: Modulus and public exponent.
  217.  
  218. 4. Symbols and abbreviations
  219.  
  220.    Upper-case symbols (e.g., BT) denote octet strings and bit strings
  221.    (in the case of the signature S); lower-case symbols (e.g., c) denote
  222.    integers.
  223.  
  224.  
  225.  
  226. Kaliski                      Informational                      [Page 4]
  227.  
  228. RFC 2313                PKCS #1: RSA Encryption               March 1998
  229.  
  230.  
  231.    ab   hexadecimal octet value  c    exponent
  232.    BT   block type               d    private exponent
  233.    D    data                     e    public exponent
  234.    EB   encryption block         k    length of modulus in
  235.                                         octets
  236.    ED   encrypted data           n    modulus
  237.    M    message                  p, q  prime factors of modulus
  238.    MD   message digest           x    integer encryption block
  239.    MD'  comparative message      y    integer encrypted data
  240.           digest
  241.    PS   padding string           mod n  modulo n
  242.    S    signature                X || Y  concatenation of X, Y
  243.                                  ||X||  length in octets of X
  244. 5. General overview
  245.  
  246.    The next six sections specify key generation, key syntax, the
  247.    encryption process, the decryption process, signature algorithms, and
  248.    object identifiers.
  249.  
  250.    Each entity shall generate a pair of keys: a public key and a private
  251.    key. The encryption process shall be performed with one of the keys
  252.    and the decryption process shall be performed with the other key.
  253.    Thus the encryption process can be either a public-key operation or a
  254.    private-key operation, and so can the decryption process. Both
  255.    processes transform an octet string to another octet string. The
  256.    processes are inverses of each other if one process uses an entity's
  257.    public key and the other process uses the same entity's private key.
  258.  
  259.    The encryption and decryption processes can implement either the
  260.    classic RSA transformations, or variations with padding.
  261.  
  262. 6. Key generation
  263.  
  264.    This section describes RSA key generation.
  265.  
  266.    Each entity shall select a positive integer e as its public exponent.
  267.  
  268.    Each entity shall privately and randomly select two distinct odd
  269.    primes p and q such that (p-1) and e have no common divisors, and
  270.    (q-1) and e have no common divisors.
  271.  
  272.    The public modulus n shall be the product of the private prime
  273.    factors p and q:
  274.  
  275.                                  n = pq .
  276.  
  277.    The private exponent shall be a positive integer d such that de-1 is
  278.    divisible by both p-1 and q-1.
  279.  
  280.  
  281.  
  282. Kaliski                      Informational                      [Page 5]
  283.  
  284. RFC 2313                PKCS #1: RSA Encryption               March 1998
  285.  
  286.  
  287.    The length of the modulus n in octets is the integer k satisfying
  288.  
  289.                         2^(8(k-1)) <= n < 2^(8k) .
  290.  
  291.    The length k of the modulus must be at least 12 octets to accommodate
  292.    the block formats in this document (see Section 8).
  293.  
  294.    Notes.
  295.  
  296.         1.   The public exponent may be standardized in
  297.              specific applications. The values 3 and F4 (65537) may have
  298.              some practical advantages, as noted in X.509 Annex C.
  299.  
  300.         2.   Some additional conditions on the choice of primes
  301.              may well be taken into account in order to deter
  302.              factorization of the modulus. These security conditions
  303.              fall outside the scope of this document. The lower bound on
  304.              the length k is to accommodate the block formats, not for
  305.              security.
  306.  
  307. 7. Key syntax
  308.  
  309.    This section gives the syntax for RSA public and private keys.
  310.  
  311. 7.1 Public-key syntax
  312.  
  313.    An RSA public key shall have ASN.1 type RSAPublicKey:
  314.  
  315.    RSAPublicKey ::= SEQUENCE {
  316.      modulus INTEGER, -- n
  317.      publicExponent INTEGER -- e }
  318.  
  319.    (This type is specified in X.509 and is retained here for
  320.    compatibility.)
  321.  
  322.    The fields of type RSAPublicKey have the following meanings:
  323.  
  324.         o    modulus is the modulus n.
  325.  
  326.         o    publicExponent is the public exponent e.
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Kaliski                      Informational                      [Page 6]
  339.  
  340. RFC 2313                PKCS #1: RSA Encryption               March 1998
  341.  
  342.  
  343. 7.2 Private-key syntax
  344.  
  345.    An RSA private key shall have ASN.1 type RSAPrivateKey:
  346.  
  347.    RSAPrivateKey ::= SEQUENCE {
  348.      version Version,
  349.      modulus INTEGER, -- n
  350.      publicExponent INTEGER, -- e
  351.      privateExponent INTEGER, -- d
  352.      prime1 INTEGER, -- p
  353.      prime2 INTEGER, -- q
  354.      exponent1 INTEGER, -- d mod (p-1)
  355.      exponent2 INTEGER, -- d mod (q-1)
  356.      coefficient INTEGER -- (inverse of q) mod p }
  357.  
  358.    Version ::= INTEGER
  359.  
  360.    The fields of type RSAPrivateKey have the following meanings:
  361.  
  362.         o    version is the version number, for compatibility
  363.              with future revisions of this document. It shall
  364.              be 0 for this version of the document.
  365.  
  366.         o    modulus is the modulus n.
  367.  
  368.         o    publicExponent is the public exponent e.
  369.  
  370.         o    privateExponent is the private exponent d.
  371.  
  372.         o    prime1 is the prime factor p of n.
  373.  
  374.         o    prime2 is the prime factor q of n.
  375.  
  376.         o    exponent1 is d mod (p-1).
  377.  
  378.         o    exponent2 is d mod (q-1).
  379.  
  380.         o    coefficient is the Chinese Remainder Theorem
  381.              coefficient q-1 mod p.
  382.  
  383.    Notes.
  384.  
  385.         1.   An RSA private key logically consists of only the
  386.              modulus n and the private exponent d. The presence of the
  387.              values p, q, d mod (p-1), d mod (p-1), and q-1 mod p is
  388.              intended for efficiency, as Quisquater and Couvreur have
  389.              shown [QC82]. A private-key syntax that does not include
  390.  
  391.  
  392.  
  393.  
  394. Kaliski                      Informational                      [Page 7]
  395.  
  396. RFC 2313                PKCS #1: RSA Encryption               March 1998
  397.  
  398.  
  399.              all the extra values can be converted readily to the syntax
  400.              defined here, provided the public key is known, according
  401.              to a result by Miller [Mil76].
  402.  
  403.         2.   The presence of the public exponent e is intended
  404.              to make it straightforward to derive a public key from the
  405.              private key.
  406.  
  407. 8. Encryption process
  408.  
  409.    This section describes the RSA encryption process.
  410.  
  411.    The encryption process consists of four steps: encryption- block
  412.    formatting, octet-string-to-integer conversion, RSA computation, and
  413.    integer-to-octet-string conversion. The input to the encryption
  414.    process shall be an octet string D, the data; an integer n, the
  415.    modulus; and an integer c, the exponent. For a public-key operation,
  416.    the integer c shall be an entity's public exponent e; for a private-
  417.    key operation, it shall be an entity's private exponent d. The output
  418.    from the encryption process shall be an octet string ED, the
  419.    encrypted data.
  420.  
  421.    The length of the data D shall not be more than k-11 octets, which is
  422.    positive since the length k of the modulus is at least 12 octets.
  423.    This limitation guarantees that the length of the padding string PS
  424.    is at least eight octets, which is a security condition.
  425.  
  426.    Notes.
  427.  
  428.         1.   In typical applications of this document to
  429.              encrypt content-encryption keys and message digests, one
  430.              would have ||D|| <= 30. Thus the length of the RSA modulus
  431.              will need to be at least 328 bits (41 octets), which is
  432.              reasonable and consistent with security recommendations.
  433.  
  434.         2.   The encryption process does not provide an
  435.              explicit integrity check to facilitate error detection
  436.              should the encrypted data be corrupted in transmission.
  437.              However, the structure of the encryption block guarantees
  438.              that the probability that corruption is undetected is less
  439.              than 2-16, which is an upper bound on the probability that
  440.              a random encryption block looks like block type 02.
  441.  
  442.         3.   Application of private-key operations as defined
  443.              here to data other than an octet string containing a
  444.              message digest is not recommended and is subject to further
  445.              study.
  446.  
  447.  
  448.  
  449.  
  450. Kaliski                      Informational                      [Page 8]
  451.  
  452. RFC 2313                PKCS #1: RSA Encryption               March 1998
  453.  
  454.  
  455.         4.   This document may be extended to handle data of
  456.              length more than k-11 octets.
  457.  
  458. 8.1 Encryption-block formatting
  459.  
  460.    A block type BT, a padding string PS, and the data D shall be
  461.    formatted into an octet string EB, the encryption block.
  462.  
  463.               EB = 00 || BT || PS || 00 || D .           (1)
  464.  
  465.    The block type BT shall be a single octet indicating the structure of
  466.    the encryption block. For this version of the document it shall have
  467.    value 00, 01, or 02. For a private- key operation, the block type
  468.    shall be 00 or 01. For a public-key operation, it shall be 02.
  469.  
  470.    The padding string PS shall consist of k-3-||D|| octets. For block
  471.    type 00, the octets shall have value 00; for block type 01, they
  472.    shall have value FF; and for block type 02, they shall be
  473.    pseudorandomly generated and nonzero. This makes the length of the
  474.    encryption block EB equal to k.
  475.  
  476.    Notes.
  477.  
  478.         1.   The leading 00 octet ensures that the encryption
  479.              block, converted to an integer, is less than the modulus.
  480.  
  481.         2.   For block type 00, the data D must begin with a
  482.              nonzero octet or have known length so that the encryption
  483.              block can be parsed unambiguously. For block types 01 and
  484.              02, the encryption block can be parsed unambiguously since
  485.              the padding string PS contains no octets with value 00 and
  486.              the padding string is separated from the data D by an octet
  487.              with value 00.
  488.  
  489.         3.   Block type 01 is recommended for private-key
  490.              operations. Block type 01 has the property that the
  491.              encryption block, converted to an integer, is guaranteed to
  492.              be large, which prevents certain attacks of the kind
  493.              proposed by Desmedt and Odlyzko [DO86].
  494.  
  495.         4.   Block types 01 and 02 are compatible with PEM RSA
  496.              encryption of content-encryption keys and message digests
  497.              as described in RFC 1423.
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506. Kaliski                      Informational                      [Page 9]
  507.  
  508. RFC 2313                PKCS #1: RSA Encryption               March 1998
  509.  
  510.  
  511.         5.   For block type 02, it is recommended that the
  512.              pseudorandom octets be generated independently for each
  513.              encryption process, especially if the same data is input to
  514.              more than one encryption process.  Hastad's results [Has88]
  515.              motivate this recommendation.
  516.  
  517.         6.   For block type 02, the padding string is at least
  518.              eight octets long, which is a security condition for
  519.              public-key operations that prevents an attacker from
  520.              recoving data by trying all possible encryption blocks. For
  521.              simplicity, the minimum length is the same for block type
  522.              01.
  523.  
  524.         7.   This document may be extended in the future to
  525.              include other block types.
  526.  
  527. 8.2 Octet-string-to-integer conversion
  528.  
  529.    The encryption block EB shall be converted to an integer x, the
  530.    integer encryption block. Let EB1, ..., EBk be the octets of EB from
  531.    first to last. Then the integer x shall satisfy
  532.  
  533.                                      k
  534.                 x =  SUM  2^(8(k-i)) EBi .              (2)
  535.                                    i = 1
  536.  
  537.    In other words, the first octet of EB has the most significance in
  538.    the integer and the last octet of EB has the least significance.
  539.  
  540.    Note. The integer encryption block x satisfies 0 <= x <  n since EB1
  541.    = 00 and 2^(8(k-1)) <= n.
  542.  
  543. 8.3 RSA computation
  544.  
  545.    The integer encryption block x shall be raised to the power c modulo
  546.    n to give an integer y, the integer encrypted data.
  547.  
  548.                        y = x^c mod n,  0 <= y < n .
  549.  
  550.    This is the classic RSA computation.
  551.  
  552. 8.4 Integer-to-octet-string conversion
  553.  
  554.    The integer encrypted data y shall be converted to an octet string ED
  555.    of length k, the encrypted data. The encrypted data ED shall satisfy
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562. Kaliski                      Informational                     [Page 10]
  563.  
  564. RFC 2313                PKCS #1: RSA Encryption               March 1998
  565.  
  566.  
  567.                                      k
  568.                 y =  SUM  2^(8(k-i)) EDi .              (3)
  569.                                    i = 1
  570.  
  571.    where ED1, ..., EDk are the octets of ED from first to last.
  572.  
  573.    In other words, the first octet of ED has the most significance in
  574.    the integer and the last octet of ED has the least significance.
  575.  
  576. 9. Decryption process
  577.  
  578.    This section describes the RSA decryption process.
  579.  
  580.    The decryption process consists of four steps: octet-string-to-
  581.    integer conversion, RSA computation, integer-to-octet-string
  582.    conversion, and encryption-block parsing. The input to the decryption
  583.    process shall be an octet string ED, the encrypted data; an integer
  584.    n, the modulus; and an integer c, the exponent. For a public-key
  585.    operation, the integer c shall be an entity's public exponent e; for
  586.    a private-key operation, it shall be an entity's private exponent d.
  587.    The output from the decryption process shall be an octet string D,
  588.    the data.
  589.  
  590.    It is an error if the length of the encrypted data ED is not k.
  591.  
  592.    For brevity, the decryption process is described in terms of the
  593.    encryption process.
  594.  
  595. 9.1 Octet-string-to-integer conversion
  596.  
  597.    The encrypted data ED shall be converted to an integer y, the integer
  598.    encrypted data, according to Equation (3).
  599.  
  600.    It is an error if the integer encrypted data y does not satisfy 0 <=
  601.    y < n.
  602.  
  603. 9.2 RSA computation
  604.  
  605.    The integer encrypted data y shall be raised to the power c modulo n
  606.    to give an integer x, the integer encryption block.
  607.  
  608.                        x = y^c mod n,  0 <= x < n .
  609.  
  610.    This is the classic RSA computation.
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. Kaliski                      Informational                     [Page 11]
  619.  
  620. RFC 2313                PKCS #1: RSA Encryption               March 1998
  621.  
  622.  
  623. 9.3 Integer-to-octet-string conversion
  624.  
  625.    The integer encryption block x shall be converted to an octet string
  626.    EB of length k, the encryption block, according to Equation (2).
  627.  
  628. 9.4 Encryption-block parsing
  629.  
  630.    The encryption block EB shall be parsed into a block type BT, a
  631.    padding string PS, and the data D according to Equation (1).
  632.  
  633.    It is an error if any of the following conditions occurs:
  634.  
  635.         o    The encryption block EB cannot be parsed
  636.              unambiguously (see notes to Section 8.1).
  637.  
  638.         o    The padding string PS consists of fewer than eight
  639.              octets, or is inconsistent with the block type BT.
  640.  
  641.         o    The decryption process is a public-key operation
  642.              and the block type BT is not 00 or 01, or the decryption
  643.              process is a private-key operation and the block type is
  644.              not 02.
  645.  
  646. 10. Signature algorithms
  647.  
  648.    This section defines three signature algorithms based on the RSA
  649.    encryption process described in Sections 8 and 9. The intended use of
  650.    the signature algorithms is in signing X.509/PEM certificates and
  651.    certificate-revocation lists, PKCS #6 extended certificates, and
  652.    other objects employing digital signatures such as X.401 message
  653.    tokens. The algorithms are not intended for use in constructing
  654.    digital signatures in PKCS #7. The first signature algorithm
  655.    (informally, "MD2 with RSA") combines the MD2 message-digest
  656.    algorithm with RSA, the second (informally, "MD4 with RSA") combines
  657.    the MD4 message-digest algorithm with RSA, and the third (informally,
  658.    "MD5 with RSA") combines the MD5 message-digest algorithm with RSA.
  659.  
  660.    This section describes the signature process and the verification
  661.    process for the two algorithms. The "selected" message-digest
  662.    algorithm shall be either MD2 or MD5, depending on the signature
  663.    algorithm. The signature process shall be performed with an entity's
  664.    private key and the verification process shall be performed with an
  665.    entity's public key. The signature process transforms an octet string
  666.    (the message) to a bit string (the signature); the verification
  667.    process determines whether a bit string (the signature) is the
  668.    signature of an octet string (the message).
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Kaliski                      Informational                     [Page 12]
  675.  
  676. RFC 2313                PKCS #1: RSA Encryption               March 1998
  677.  
  678.  
  679.    Note. The only difference between the signature algorithms defined
  680.    here and one of the the methods by which signatures (encrypted
  681.    message digests) are constructed in PKCS #7 is that signatures here
  682.    are represented here as bit strings, for consistency with the X.509
  683.    SIGNED macro. In PKCS #7 encrypted message digests are octet strings.
  684.  
  685. 10.1 Signature process
  686.  
  687.    The signature process consists of four steps: message digesting, data
  688.    encoding, RSA encryption, and octet-string-to-bit-string conversion.
  689.    The input to the signature process shall be an octet string M, the
  690.    message; and a signer's private key. The output from the signature
  691.    process shall be a bit string S, the signature.
  692.  
  693. 10.1.1 Message digesting
  694.  
  695.    The message M shall be digested with the selected message- digest
  696.    algorithm to give an octet string MD, the message digest.
  697.  
  698. 10.1.2 Data encoding
  699.  
  700.    The message digest MD and a message-digest algorithm identifier shall
  701.    be combined into an ASN.1 value of type DigestInfo, described below,
  702.    which shall be BER-encoded to give an octet string D, the data.
  703.  
  704.    DigestInfo ::= SEQUENCE {
  705.      digestAlgorithm DigestAlgorithmIdentifier,
  706.      digest Digest }
  707.  
  708.    DigestAlgorithmIdentifier ::= AlgorithmIdentifier
  709.  
  710.    Digest ::= OCTET STRING
  711.  
  712.    The fields of type DigestInfo have the following meanings:
  713.  
  714.         o    digestAlgorithm identifies the message-digest
  715.              algorithm (and any associated parameters). For
  716.              this application, it should identify the selected
  717.              message-digest algorithm, MD2, MD4 or MD5. For
  718.              reference, the relevant object identifiers are the
  719.              following:
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. Kaliski                      Informational                     [Page 13]
  731.  
  732. RFC 2313                PKCS #1: RSA Encryption               March 1998
  733.  
  734.  
  735.    md2 OBJECT IDENTIFIER ::=
  736.  
  737.      { iso(1) member-body(2) US(840) rsadsi(113549)
  738.          digestAlgorithm(2) 2 } md4 OBJECT IDENTIFIER ::=
  739.      { iso(1) member-body(2) US(840) rsadsi(113549)
  740.          digestAlgorithm(2) 4 } md5 OBJECT IDENTIFIER ::=
  741.      { iso(1) member-body(2) US(840) rsadsi(113549)
  742.          digestAlgorithm(2) 5 }
  743.  
  744.              For these object identifiers, the parameters field of the
  745.              digestAlgorithm value should be NULL.
  746.  
  747.         o    digest is the result of the message-digesting
  748.              process, i.e., the message digest MD.
  749.  
  750.    Notes.
  751.  
  752.         1.   A message-digest algorithm identifier is included
  753.              in the DigestInfo value to limit the damage resulting from
  754.              the compromise of one message-digest algorithm. For
  755.              instance, suppose an adversary were able to find messages
  756.              with a given MD2 message digest.  That adversary might try
  757.              to forge a signature on a message by finding an innocuous-
  758.              looking message with the same MD2 message digest, and
  759.              coercing a signer to sign the innocuous-looking message.
  760.              This attack would succeed only if the signer used MD2. If
  761.              the DigestInfo value contained only the message digest,
  762.              however, an adversary could attack signers that use any
  763.              message digest.
  764.  
  765.         2.   Although it may be claimed that the use of a
  766.              SEQUENCE type violates the literal statement in the X.509
  767.              SIGNED and SIGNATURE macros that a signature is an
  768.              ENCRYPTED OCTET STRING (as opposed to ENCRYPTED SEQUENCE),
  769.              such a literal interpretation need not be required, as
  770.              I'Anson and Mitchell point out [IM90].
  771.  
  772.         3.  No reason is known that MD4 would not be
  773.              for very high security digital signature schemes, but
  774.              because MD4 was designed to be exceptionally fast, it is
  775.              "at the edge" in terms of risking successful cryptanalytic
  776.              attack.  A message-digest algorithm can be considered
  777.              "broken" if someone can find a collision: two messages with
  778.              the same digest. While collisions have been found in
  779.              variants of MD4 with only two digesting "rounds"
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786. Kaliski                      Informational                     [Page 14]
  787.  
  788. RFC 2313                PKCS #1: RSA Encryption               March 1998
  789.  
  790.  
  791.              [Mer90][dBB92], none have been found in MD4 itself, which
  792.              has three rounds. After further critical review, it may be
  793.              appropriate to consider MD4 for very high security
  794.              applications.
  795.  
  796.              MD5, which has four rounds and is proportionally slower
  797.              than MD4, is recommended until the completion of MD4's
  798.              review. The reported "pseudocollisions" in MD5's internal
  799.              compression function [dBB93] do not appear to have any
  800.              practical impact on  MD5's security.
  801.  
  802.              MD2, the slowest of the three, has the most conservative
  803.              design. No attacks on MD2 have been published.
  804.  
  805. 10.1.3 RSA encryption
  806.  
  807.    The data D shall be encrypted with the signer's RSA private key as
  808.    described in Section 7 to give an octet string ED, the encrypted
  809.    data. The block type shall be 01. (See Section 8.1.)
  810.  
  811. 10.1.4 Octet-string-to-bit-string conversion
  812.  
  813.    The encrypted data ED shall be converted into a bit string S, the
  814.    signature. Specifically, the most significant bit of the first octet
  815.    of the encrypted data shall become the first bit of the signature,
  816.    and so on through the least significant bit of the last octet of the
  817.    encrypted data, which shall become the last bit of the signature.
  818.  
  819.    Note. The length in bits of the signature S is a multiple of eight.
  820.  
  821. 10.2 Verification process
  822.  
  823.    The verification process for both signature algorithms consists of
  824.    four steps: bit-string-to-octet-string conversion, RSA decryption,
  825.    data decoding, and message digesting and comparison. The input to the
  826.    verification process shall be an octet string M, the message; a
  827.    signer's public key; and a bit string S, the signature. The output
  828.    from the verification process shall be an indication of success or
  829.    failure.
  830.  
  831. 10.2.1 Bit-string-to-octet-string conversion
  832.  
  833.    The signature S shall be converted into an octet string ED, the
  834.    encrypted data. Specifically, assuming that the length in bits of the
  835.    signature S is a multiple of eight, the first bit of the signature
  836.    shall become the most significant bit of the first octet of the
  837.  
  838.  
  839.  
  840.  
  841.  
  842. Kaliski                      Informational                     [Page 15]
  843.  
  844. RFC 2313                PKCS #1: RSA Encryption               March 1998
  845.  
  846.  
  847.    encrypted data, and so on through the last bit of the signature,
  848.    which shall become the least significant bit of the last octet of the
  849.    encrypted data.
  850.  
  851.    It is an error if the length in bits of the signature S is not a
  852.    multiple of eight.
  853.  
  854. 10.2.2 RSA decryption
  855.  
  856.    The encrypted data ED shall be decrypted with the signer's RSA public
  857.    key as described in Section 8 to give an octet string D, the data.
  858.  
  859.    It is an error if the block type recovered in the decryption process
  860.    is not 01. (See Section 9.4.)
  861.  
  862. 10.2.3 Data decoding
  863.  
  864.    The data D shall be BER-decoded to give an ASN.1 value of type
  865.    DigestInfo, which shall be separated into a message digest MD and a
  866.    message-digest algorithm identifier. The message-digest algorithm
  867.    identifier shall determine the "selected" message-digest algorithm
  868.    for the next step.
  869.  
  870.    It is an error if the message-digest algorithm identifier does not
  871.    identify the MD2, MD4 or MD5 message-digest algorithm.
  872.  
  873. 10.2.4 Message digesting and comparison
  874.  
  875.    The message M shall be digested with the selected message-digest
  876.    algorithm to give an octet string MD', the comparative message
  877.    digest. The verification process shall succeed if the comparative
  878.    message digest MD' is the same as the message digest MD, and the
  879.    verification process shall fail otherwise.
  880.  
  881. 11. Object identifiers
  882.  
  883.    This document defines five object identifiers: pkcs-1, rsaEncryption,
  884.    md2WithRSAEncryption, md4WithRSAEncryption, and md5WithRSAEncryption.
  885.  
  886.    The object identifier pkcs-1 identifies this document.
  887.  
  888.    pkcs-1 OBJECT IDENTIFIER ::=
  889.  
  890.      { iso(1) member-body(2) US(840) rsadsi(113549)
  891.          pkcs(1) 1 }
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898. Kaliski                      Informational                     [Page 16]
  899.  
  900. RFC 2313                PKCS #1: RSA Encryption               March 1998
  901.  
  902.  
  903.    The object identifier rsaEncryption identifies RSA public and private
  904.    keys as defined in Section 7 and the RSA encryption and decryption
  905.    processes defined in Sections 8 and 9.
  906.  
  907.    rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
  908.  
  909.    The rsaEncryption object identifier is intended to be used in the
  910.    algorithm field of a value of type AlgorithmIdentifier. The
  911.    parameters field of that type, which has the algorithm-specific
  912.    syntax ANY DEFINED BY algorithm, would have ASN.1 type NULL for this
  913.    algorithm.
  914.  
  915.    The object identifiers md2WithRSAEncryption, md4WithRSAEncryption,
  916.    md5WithRSAEncryption, identify, respectively, the "MD2 with RSA,"
  917.    "MD4 with RSA," and "MD5 with RSA" signature and verification
  918.    processes defined in Section 10.
  919.  
  920.    md2WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 2 }
  921.    md4WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 3 }
  922.    md5WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 }
  923.  
  924.    These object identifiers are intended to be used in the algorithm
  925.    field of a value of type AlgorithmIdentifier. The parameters field of
  926.    that type, which has the algorithm-specific syntax ANY DEFINED BY
  927.    algorithm, would have ASN.1 type NULL for these algorithms.
  928.  
  929.    Note. X.509's object identifier rsa also identifies RSA public keys
  930.    as defined in Section 7, but does not identify private keys, and
  931.    identifies different encryption and decryption processes. It is
  932.    expected that some applications will identify public keys by rsa.
  933.    Such public keys are compatible with this document; an rsaEncryption
  934.    process under an rsa public key is the same as the rsaEncryption
  935.    process under an rsaEncryption public key.
  936.  
  937. Security Considerations
  938.  
  939.    Security issues are discussed throughout this memo.
  940.  
  941. Revision history
  942.  
  943.    Versions 1.0-1.3
  944.  
  945.    Versions 1.0-1.3 were distributed to participants in RSA Data
  946.    Security, Inc.'s Public-Key Cryptography Standards meetings in
  947.    February and March 1991.
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954. Kaliski                      Informational                     [Page 17]
  955.  
  956. RFC 2313                PKCS #1: RSA Encryption               March 1998
  957.  
  958.  
  959.    Version 1.4
  960.  
  961.    Version 1.4 is part of the June 3, 1991 initial public release of
  962.    PKCS. Version 1.4 was published as NIST/OSI Implementors' Workshop
  963.    document SEC-SIG-91-18.
  964.  
  965.    Version 1.5
  966.  
  967.    Version 1.5 incorporates several editorial changes, including updates
  968.    to the references and the addition of a revision history. The
  969.    following substantive changes were made:
  970.  
  971.         o    Section 10: "MD4 with RSA" signature and
  972.              verification processes are added.
  973.  
  974.         o    Section 11: md4WithRSAEncryption object identifier
  975.              is added.
  976.  
  977.    Supersedes June 3, 1991 version, which was also published as NIST/OSI
  978.    Implementors' Workshop document SEC-SIG-91-18.
  979.  
  980. Acknowledgements
  981.  
  982.    This document is based on a contribution of RSA Laboratories, a
  983.    division of RSA Data Security, Inc.  Any substantial use of the text
  984.    from this document must acknowledge RSA Data Security, Inc. RSA Data
  985.    Security, Inc.  requests that all material mentioning or referencing
  986.    this document identify this as "RSA Data Security, Inc. PKCS #1".
  987.  
  988. Author's Address
  989.  
  990.    Burt Kaliski
  991.    RSA Laboratories East
  992.    20 Crosby Drive
  993.    Bedford, MA  01730
  994.  
  995.    Phone: (617) 687-7000
  996.    EMail: burt@rsa.com
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010. Kaliski                      Informational                     [Page 18]
  1011.  
  1012. RFC 2313                PKCS #1: RSA Encryption               March 1998
  1013.  
  1014.  
  1015. Full Copyright Statement
  1016.  
  1017.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  1018.  
  1019.    This document and translations of it may be copied and furnished to
  1020.    others, and derivative works that comment on or otherwise explain it
  1021.    or assist in its implementation may be prepared, copied, published
  1022.    and distributed, in whole or in part, without restriction of any
  1023.    kind, provided that the above copyright notice and this paragraph are
  1024.    included on all such copies and derivative works.  However, this
  1025.    document itself may not be modified in any way, such as by removing
  1026.    the copyright notice or references to the Internet Society or other
  1027.    Internet organizations, except as needed for the purpose of
  1028.    developing Internet standards in which case the procedures for
  1029.    copyrights defined in the Internet Standards process must be
  1030.    followed, or as required to translate it into languages other than
  1031.    English.
  1032.  
  1033.    The limited permissions granted above are perpetual and will not be
  1034.    revoked by the Internet Society or its successors or assigns.
  1035.  
  1036.    This document and the information contained herein is provided on an
  1037.    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
  1038.    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  1039.    BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
  1040.    HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
  1041.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066. Kaliski                      Informational                     [Page 19]
  1067.  
  1068.