S/MIME Working Group                                         R. Housley
Internet Draft                                         RSA Laboratories
expires in six months                                        April 2001


             Cryptographic Message Syntax (CMS) Algorithms

                    <draft-ietf-smime-cmsalg-00.txt>


Status of this Memo

   This document is an Internet-Draft and is in full conformance with
   all provisions of Section 10 of RFC2026.  Internet-Drafts are working
   documents of the Internet Engineering Task Force (IETF), its areas,
   and its working groups.  Note that other groups may also distribute
   working documents as Internet-Drafts.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time.  It is inappropriate to use Internet-Drafts as reference
   material or to cite them other than as "work in progress."

     The list of current Internet-Drafts can be accessed at
     http://www.ietf.org/1id-abstracts.html

     The list of Internet-Draft Shadow Directories can be accessed at
     http://www.ietf.org/shadow.html.



   To view the entire list of current Internet-Drafts, please check the
   "1id-abstracts.txt" listing contained in the Internet-Drafts Shadow
   Directories on ftp.is.co.za (Africa), ftp.nordu.net (Northern
   Europe), ftp.nis.garr.it (Southern Europe), munnari.oz.au (Pacific
   Rim), ftp.ietf.org (US East Coast), or ftp.isi.edu (US West Coast).


Abstract

   This document describes cryptographic algorithms for use with the
   Cryptographic Message Syntax (CMS) [CMS].  CMS is used to digitally
   sign, digest, authenticate, or encrypt arbitrary messages.

   Once approved, this draft will obsolete section 12 of RFC 2630.  The
   companion document (draft-ietf-smime-rfc2630bis-00.txt) will obsolete
   the rest of RFC 2630.  Separation of the protocol and algorithm
   specifications allows the IETF to select different mandatory to
   implement algorithms in the future without reissuing the protocol
   document.

   This draft is being discussed on the "ietf-smime" mailing list.  To
   join the list, send a message to <ietf-smime-request@imc.org> with
   the single word "subscribe" in the body of the message.  Also, there
   is a Web site for the mailing list at <http://www.imc.org/ietf-
   smime/>.



Housley                                                         [Page 1]


INTERNET DRAFT                                                April 2001


Table of Contents

   Status of this Memo ..............................................  1
   Abstract .........................................................  1
   Table of Contents ................................................  3
   1   Introduction .................................................  5
   2   Message Digest Algorithms .................................... 35
         2.1  SHA-1 ................................................. 35
         2.2  MD5 ................................................... 35
   3   Signature Algorithms ......................................... 36
         3.1  DSA ................................................... 36
         3.2  RSA ................................................... 36
   4   Key Management Algorithms .................................... 36
         4.1  Key Agreement Algorithms .............................. 36
                4.1.1  X9.42 Ephemeral-Static Diffie-Hellman ........ 37
         4.2  Key Transport Algorithms .............................. 38
                4.2.1  RSA .......................................... 39
         4.3  Symmetric Key-Encryption Key Algorithms ............... 39
                4.3.1  Triple-DES Key Wrap .......................... 40
                4.3.2  RC2 Key Wrap ................................. 41
   5   Content Encryption Algorithms ................................ 41
         5.1  Triple-DES CBC ........................................ 42
         5.2  RC2 CBC ............................................... 42
   6   Message Authentication Code (MAC) Algorithms ................. 42
         6.1  HMAC with SHA-1 ....................................... 43
   7   Triple-DES and RC2 Key Wrap Algorithms ....................... 43
         7.1  Key Checksum .......................................... 44
         7.2  Triple-DES Key Wrap ................................... 44
         7.3  Triple-DES Key Unwrap ................................. 44
         7.4  RC2 Key Wrap .......................................... 45
         7.5  RC2 Key Unwrap ........................................ 46
   Appendix A:  ASN.1 Module ........................................ 47
   References ....................................................... 55
   Security Considerations .......................................... 56
   Acknowledgments .................................................. 58
   Author's Address ................................................. 59
   Full Copyright Statement ......................................... 60














Housley                                                         [Page 2]


INTERNET DRAFT                                                April 2001


1  Introduction

   The Cryptographic Message Syntax (CMS) [CMS] is used to digitally
   sign, digest, authenticate, or encrypt arbitrary messages.  This
   companion specification lists the algorithms that MUST be supported
   by CMS implementations.  It also lists algorithms that SHOULD be
   supported by CMS implementations.  Of course, CMS implementations MAY
   support other algorithms as well.

   Table 1 summarizes the algorithms that CMS implantations MUST support
   and SHOULD support.

   The CMS values are generated using ASN.1 [X.208-88], using BER-
   encoding [X.209-88].  Algorithm are be identified by algorithm
   identifiers (ASN.1 object identifiers), and some algorithms require
   additional parameters.  When needed, parameters are specified with an
   ASN.1 structure.  The algorithm identifiers for each algorithm are
   specified, and, when needed, the parameter structure is specified.
   The fields in the CMS employed by each algorithm are identified.

   In this document, the key words MUST, MUST NOT, REQUIRED, SHOULD,
   SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL are to be interpreted as
   described by Scott Bradner in [STDWORDS].



             Table 1.  CMS Implantation Algorithm Requirements

   Algorithm Type            MUST implement         SHOULD implement
   -----------------------------------------------------------------
   Message Digest            SHA-1                  MD5
   Signature                 DSA and RSA (*)        --
   Key Management
      Key Agreement          --                     X9.42 E-S D-H
      Key Transport          RSA                    --
      Symmetric KEK Wrap     Triple-DES Key Wrap    RC2 Key Wrap
   Content Encryption        Triple-DES CBC         RC2 CBC
   Message Authentication    HMAC with SHA-1        --

   (*) Note:  CMS implementations MUST be able to verify signatures
              with both DSA and RSA, and they MUST be able to
              generate signatures with at least one of them.









Housley                                                         [Page 3]


INTERNET DRAFT                                                April 2001


2  Message Digest Algorithms

   CMS implementations MUST support SHA-1.  CMS implementations SHOULD
   support MD5.

   Digest algorithm identifiers are located in the SignedData
   digestAlgorithms field, the SignerInfo digestAlgorithm field, the
   DigestedData digestAlgorithm field, and the AuthenticatedData
   digestAlgorithm field.

   Digest values are located in the DigestedData digest field, and
   digest values are located in the Message Digest authenticated
   attribute.  In addition, digest values are input to signature
   algorithms.

2.1  SHA-1

   The SHA-1 digest algorithm is defined in FIPS Pub 180-1 [SHA1].  The
   algorithm identifier for SHA-1 is:

      sha-1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
          oiw(14) secsig(3) algorithm(2) 26 }

   The AlgorithmIdentifier parameters field is OPTIONAL.  If present,
   the parameters field MUST contain an ASN.1 NULL.  Implementations
   SHOULD accept SHA-1 AlgorithmIdentifiers with absent parameters as
   well as NULL parameters.  Implementations SHOULD generate SHA-1
   AlgorithmIdentifiers with NULL parameters.

2.2  MD5

   The MD5 digest algorithm is defined in RFC 1321 [MD5].  The algorithm
   identifier for MD5 is:

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

   The AlgorithmIdentifier parameters field MUST be present, and the
   parameters field MUST contain NULL.  Implementations MAY accept the
   MD5 AlgorithmIdentifiers with absent parameters as well as NULL
   parameters.

3  Signature Algorithms

   CMS implementations MUST support both DSA and RSA.  CMS
   implementations MUST be able to verify signatures with both DSA and
   RSA.  CMS implementations MUST be able to generate signatures with
   either DSA or RSA.  CMS implementations MAY be able to generate



Housley                                                         [Page 4]


INTERNET DRAFT                                                April 2001


   signatures with both DSA and RSA.

   Signature algorithm identifiers are located in the SignerInfo
   signatureAlgorithm field.  Also, signature algorithm identifiers are
   located in the SignerInfo signatureAlgorithm field of
   countersignature attributes.

   Signature values are located in the SignerInfo signature field.
   Also, signature values are located in the SignerInfo signature field
   of countersignature attributes.

3.1  DSA

   The DSA signature algorithm is defined in FIPS Pub 186 [DSS].  DSA is
   always used with the SHA-1 message digest algorithm.  The algorithm
   identifier for DSA is:

      id-dsa-with-sha1 OBJECT IDENTIFIER ::=  { iso(1) member-body(2)
          us(840) x9-57 (10040) x9cm(4) 3 }

   The AlgorithmIdentifier parameters field MUST NOT be present.

3.2  RSA

   The RSA signature algorithm is defined in RFC 2437 [NEWPKCS#1].  RFC
   2437 specifies the use of the RSA signature algorithm with the SHA-1
   and MD5 message digest algorithms.  The algorithm identifier for RSA
   is:

      rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
          us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }

   CMS implementations MUST support RSA with SHA-1.  CMS implementations
   SHOULD support RSA with MD5.

4  Key Management Algorithms

   CMS accommodates three general key management techniques: key
   agreement, key transport, and previously distributed symmetric key-
   encryption keys.

4.1  Key Agreement Algorithms

   CMS implementations SHOULD support key agreement using X9.42
   Ephemeral-Static Diffie-Hellman (X9.42 E-S D-H).

   Any symmetric encryption algorithm that a CMS implementation includes
   as a content-encryption algorithm MUST also be included as a key-



Housley                                                         [Page 5]


INTERNET DRAFT                                                April 2001


   encryption algorithm.  CMS implementations SHOULD include key
   agreement of Triple-DES pairwise key-encryption keys.  CMS
   implementations SHOULD include key agreement of RC2 pairwise key-
   encryption keys.  CMS implementations MUST include Triple-DES
   wrapping of Triple-DES content-encryption keys and RC2 wrapping of
   RC2 content-encryption keys.  The key wrap algorithms for Triple-DES
   and RC2 are described in section 7.

   A CMS implementation MAY support mixed key-encryption and content-
   encryption algorithms.  For example, a 128-bit RC2 content-encryption
   key MAY be wrapped with 168-bit Triple-DES key-encryption key.
   Similarly, a 40-bit RC2 content-encryption key MAY be wrapped with
   128-bit RC2 key-encryption key.

   For key agreement of RC2 key-encryption keys, 128 bits MUST be
   generated as input to the key expansion process used to compute the
   RC2 effective key [RC2].

   Key agreement algorithm identifiers are located in the EnvelopedData
   RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm and
   AuthenticatedData RecipientInfos KeyAgreeRecipientInfo
   keyEncryptionAlgorithm fields.

   Key wrap algorithm identifiers are located in the KeyWrapAlgorithm
   parameters within the EnvelopedData RecipientInfos
   KeyAgreeRecipientInfo keyEncryptionAlgorithm and AuthenticatedData
   RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm fields.

   Wrapped content-encryption keys are located in the EnvelopedData
   RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys
   encryptedKey field.  Wrapped message-authentication keys are located
   in the AuthenticatedData RecipientInfos KeyAgreeRecipientInfo
   RecipientEncryptedKeys encryptedKey field.

4.1.1  X9.42 Ephemeral-Static Diffie-Hellman

   Ephemeral-Static Diffie-Hellman key agreement is defined in RFC 2631
   [DH-X9.42].  When using Ephemeral-Static Diffie-Hellman, the
   EnvelopedData RecipientInfos KeyAgreeRecipientInfo and
   AuthenticatedData RecipientInfos KeyAgreeRecipientInfo fields are
   used as follows:

      version MUST be 3.

      originator MUST be the originatorKey alternative.  The
      originatorKey algorithm field MUST contain the dh-public-number
      object identifier with absent parameters.  The originatorKey
      publicKey field MUST contain the sender's ephemeral public key.



Housley                                                         [Page 6]


INTERNET DRAFT                                                April 2001


      The dh-public-number object identifier is:

         dh-public-number OBJECT IDENTIFIER ::= { iso(1) member-body(2)
             us(840) ansi-x942(10046) number-type(2) 1 }

      ukm MAY be absent.  When present, the ukm is used to ensure that a
      different key-encryption key is generated when the ephemeral
      private key might be used more than once.

      keyEncryptionAlgorithm MUST be the id-alg-ESDH algorithm
      identifier.  The algorithm identifier parameter field for id-alg-
      ESDH is KeyWrapAlgorihtm, and this parameter MUST be present.  The
      KeyWrapAlgorithm denotes the symmetric encryption algorithm used
      to encrypt the content-encryption key with the pairwise key-
      encryption key generated using the X9.42 Ephemeral-Static Diffie-
      Hellman key agreement algorithm.  Triple-DES and RC2 key wrap
      algorithms are discussed in section 7.  The id-alg-ESDH algorithm
      identifier and parameter syntax is:

         id-alg-ESDH OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
             rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 5 }

         KeyWrapAlgorithm ::= AlgorithmIdentifier

      recipientEncryptedKeys contains an identifier and an encrypted key
      for each recipient.  The RecipientEncryptedKey
      KeyAgreeRecipientIdentifier MUST contain either the
      issuerAndSerialNumber identifying the recipient's certificate or
      the RecipientKeyIdentifier containing the subject key identifier
      from the recipient's certificate.  In both cases, the recipient's
      certificate contains the recipient's static public key.
      RecipientEncryptedKey EncryptedKey MUST contain the content-
      encryption key encrypted with the X9.42 Ephemeral-Static Diffie-
      Hellman generated pairwise key-encryption key using the algorithm
      specified by the KeyWrapAlgortihm.

4.2  Key Transport Algorithms

   CMS implementations MUST support key transport using RSA.  RSA
   implementations MUST support key transport of Triple-DES content-
   encryption keys.  RSA implementations SHOULD support key transport of
   RC2 content-encryption keys.

   Key transport algorithm identifiers are located in the EnvelopedData
   RecipientInfos KeyTransRecipientInfo keyEncryptionAlgorithm and
   AuthenticatedData RecipientInfos KeyTransRecipientInfo
   keyEncryptionAlgorithm fields.




Housley                                                         [Page 7]


INTERNET DRAFT                                                April 2001


   Key transport encrypted content-encryption keys are located in the
   EnvelopedData RecipientInfos KeyTransRecipientInfo encryptedKey
   field.  Key transport encrypted message-authentication keys are
   located in the AuthenticatedData RecipientInfos KeyTransRecipientInfo
   encryptedKey field.

4.2.1  RSA

   The RSA key transport algorithm is the RSA encryption scheme defined
   in RFC 2313 [PKCS#1], block type is 02, where the message to be
   encrypted is the content-encryption key.  The algorithm identifier
   for RSA is:

      rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
          us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }

   The AlgorithmIdentifier parameters field must be present, and the
   parameters field must contain NULL.

   When using a Triple-DES content-encryption key, CMS implementations
   MUST adjust the parity bits for each DES key comprising the Triple-
   DES key prior to RSA encryption.

   The use of RSA encryption, as defined in RFC 2313 [PKCS#1], to
   provide confidentiality has a known vulnerability.  The vulnerability
   is primarily relevant to usage in interactive applications rather
   than to store-and-forward environments.  Further information and
   proposed countermeasures are discussed in the Security Considerations
   section of this document and RFC <TBD> [MMA].

   Note that the same encryption scheme is also defined in RFC 2437
   [NEWPKCS#1].  Within RFC 2437, this scheme is called RSAES-
   PKCS1-v1_5.

4.3  Symmetric Key-Encryption Key Algorithms

   CMS implementations MUST support symmetric key-encryption key
   management.  CMS implementations MUST include Triple-DES key-
   encryption keys wrapping Triple-DES content-encryption keys.  CMS
   implementations SHOULD include RC2 key-encryption keys wrapping RC2
   content-encryption keys.  RC2 128-bit keys MUST be used as key-
   encryption keys, and they MUST be used with the RC2ParameterVersion
   parameter set to 58.  A CMS implementation MAY support mixed key-
   encryption and content-encryption algorithms.  For example, a 40-bit
   RC2 content-encryption key MAY be wrapped with 168-bit Triple-DES
   key-encryption key or with a 128-bit RC2 key-encryption key.

   Key wrap algorithm identifiers are located in the EnvelopedData



Housley                                                         [Page 8]


INTERNET DRAFT                                                April 2001


   RecipientInfos KEKRecipientInfo keyEncryptionAlgorithm and
   AuthenticatedData RecipientInfos KEKRecipientInfo
   keyEncryptionAlgorithm fields.

   Wrapped content-encryption keys are located in the EnvelopedData
   RecipientInfos KEKRecipientInfo encryptedKey field.  Wrapped message-
   authentication keys are located in the AuthenticatedData
   RecipientInfos KEKRecipientInfo encryptedKey field.

   The output of a key agreement algorithm is a key-encryption key, and
   this key-encryption key is used to encrypt the content-encryption
   key.  In conjunction with key agreement algorithms, CMS
   implementations MUST include encryption of content-encryption keys
   with the pairwise key-encryption key generated using a key agreement
   algorithm.  To support key agreement, key wrap algorithm identifiers
   are located in the KeyWrapAlgorithm parameter of the EnvelopedData
   RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm and
   AuthenticatedData RecipientInfos KeyAgreeRecipientInfo
   keyEncryptionAlgorithm fields.  Wrapped content-encryption keys are
   located in the EnvelopedData RecipientInfos KeyAgreeRecipientInfo
   RecipientEncryptedKeys encryptedKey field, wrapped message-
   authentication keys are located in the AuthenticatedData
   RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys
   encryptedKey field.

4.3.1  Triple-DES Key Wrap

   Triple-DES key encryption has the algorithm identifier:

      id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
          us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 6 }

   The AlgorithmIdentifier parameter field MUST be NULL.

   The key wrap algorithm used to encrypt a Triple-DES content-
   encryption key with a Triple-DES key-encryption key is specified in
   section 7.2.  The corresponding key unwrap algorithm is specified in
   section 7.3.

   Out-of-band distribution of the Triple-DES key-encryption key used to
   encrypt the Triple-DES content-encryption key is beyond of the scope
   of this document.









Housley                                                         [Page 9]


INTERNET DRAFT                                                April 2001


4.3.2  RC2 Key Wrap

   RC2 key encryption has the algorithm identifier:

      id-alg-CMSRC2wrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
          us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 7 }

   The AlgorithmIdentifier parameter field must be RC2wrapParameter:

      RC2wrapParameter ::= RC2ParameterVersion

      RC2ParameterVersion ::= INTEGER

   The RC2 effective-key-bits (key size) greater than 32 and less than
   256 is encoded in the RC2ParameterVersion.  For the effective-key-
   bits of 40, 64, and 128, the rc2ParameterVersion values are 160, 120,
   and 58 respectively.  These values are not simply the RC2 key length.
   Note that the value 160 must be encoded as two octets (00 A0),
   because the one octet (A0) encoding represents a negative number.

   RC2 128-bit keys MUST be used as key-encryption keys, and they MUST
   be used with the RC2ParameterVersion parameter set to 58.

   The key wrap algorithm used to encrypt a RC2 content-encryption key
   with a RC2 key-encryption key is specified in section 7.4.  The
   corresponding key unwrap algorithm is specified in section 7.5.

   Out-of-band distribution of the RC2 key-encryption key used to
   encrypt the RC2 content-encryption key is beyond of the scope of this
   document.

5  Content Encryption Algorithms

   CMS implementations MUST support Three-Key Triple-DES in CBC mode.
   MS implementations SHOULD support Two-Key Triple-DES in CBC mode.
   CMS implementations SHOULD support RC2 in CBC mode.

   Content encryption algorithms identifiers are located in the
   EnvelopedData EncryptedContentInfo contentEncryptionAlgorithm and the
   EncryptedData EncryptedContentInfo contentEncryptionAlgorithm fields.

   Content encryption algorithms are used to encipher the content
   located in the EnvelopedData EncryptedContentInfo encryptedContent
   field and the EncryptedData EncryptedContentInfo encryptedContent
   field.






Housley                                                        [Page 10]


INTERNET DRAFT                                                April 2001


5.1  Triple-DES CBC

   The Triple-DES algorithm is described in ANSI X9.52 [3DES].  The
   Triple-DES is composed from three sequential DES [DES] operations:
   encrypt, decrypt, and encrypt.  Three-Key Triple-DES uses a different
   key for each DES operation.  Two-Key Triple-DES uses one key for the
   two encrypt operations and different key for the decrypt operation.
   The same algorithm identifiers are used for Three-Key Triple-DES and
   Two-Key Triple-DES.  The algorithm identifier for Triple-DES in
   Cipher Block Chaining (CBC) mode is:

      des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2)
          us(840) rsadsi(113549) encryptionAlgorithm(3) 7 }

   The AlgorithmIdentifier parameters field MUST be present, and the
   parameters field must contain a CBCParameter:

      CBCParameter ::= IV

      IV ::= OCTET STRING  -- exactly 8 octets

5.2  RC2 CBC

   The RC2 algorithm is described in RFC 2268 [RC2].  The algorithm
   identifier for RC2 in CBC mode is:

      rc2-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
          rsadsi(113549) encryptionAlgorithm(3) 2 }

   The AlgorithmIdentifier parameters field MUST be present, and the
   parameters field MUST contain a RC2CBCParameter:

      RC2CBCParameter ::= SEQUENCE {
        rc2ParameterVersion INTEGER,
        iv OCTET STRING  }  -- exactly 8 octets

   The RC2 effective-key-bits (key size) greater than 32 and less than
   256 is encoded in the rc2ParameterVersion.  For the effective-key-
   bits of 40, 64, and 128, the rc2ParameterVersion values are 160, 120,
   and 58 respectively.  These values are not simply the RC2 key length.
   Note that the value 160 must be encoded as two octets (00 A0), since
   the one octet (A0) encoding represents a negative number.

6  Message Authentication Code Algorithms

   CMS implementations that support authenticatedData MUST support HMAC
   with SHA-1.




Housley                                                        [Page 11]


INTERNET DRAFT                                                April 2001


   MAC algorithm identifiers are located in the AuthenticatedData
   macAlgorithm field.

   MAC values are located in the AuthenticatedData mac field.

6.1  HMAC with SHA-1

   The HMAC with SHA-1 algorithm is described in RFC 2104 [HMAC].  The
   algorithm identifier for HMAC with SHA-1 is:

      hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
          dod(6) internet(1) security(5) mechanisms(5) 8 1 2 }

   The AlgorithmIdentifier parameters field must be absent.

7  Triple-DES and RC2 Key Wrap Algorithms

   CMS implementations MUST include encryption of a Triple-DES content-
   encryption key with a Triple-DES key-encryption key using the
   algorithm specified in Sections 7.2 and 7.3.  CMS implementations
   SHOULD include encryption of a RC2 content-encryption key with a RC2
   key-encryption key using the algorithm specified in Sections 7.4 and
   7.5.  Triple-DES and RC2 content-encryption keys are encrypted in
   Cipher Block Chaining (CBC) mode [MODES].

   Key Transport algorithms allow for the content-encryption key to be
   directly encrypted; however, key agreement and symmetric key-
   encryption key algorithms encrypt the content-encryption key with a
   second symmetric encryption algorithm.  This section describes how
   the Triple-DES or RC2 content-encryption key is formatted and
   encrypted.

   Key agreement algorithms generate a pairwise key-encryption key, and
   a key wrap algorithm is used to encrypt the content-encryption key
   with the pairwise key-encryption key.  Similarly, a key wrap
   algorithm is used to encrypt the content-encryption key in a
   previously distributed key-encryption key.

   The key-encryption key is generated by the key agreement algorithm or
   distributed out of band.  For key agreement of RC2 key-encryption
   keys, 128 bits MUST be generated as input to the key expansion
   process used to compute the RC2 effective key [RC2].

   The same algorithm identifier is used for both Two-key Triple-DES and
   Three-key Triple-DES.  When the length of the content-encryption key
   to be wrapped is a Two-key Triple-DES key, a third key with the same
   value as the first key is created.  Thus, all Triple-DES content-
   encryption keys are wrapped like Three-key Triple-DES keys.  However,



Housley                                                        [Page 12]


INTERNET DRAFT                                                April 2001


   a Two-key Triple-DES key MUST NOT be used to wrap a Three-key Triple-
   DES key.

7.1  Key Checksum

   The CMS Checksum Algorithm is used to provide a content-encryption
   key integrity check value.  The algorithm is:

   1.  Compute a 20 octet SHA-1 [SHA1] message digest on the
       content-encryption key.
   2.  Use the most significant (first) eight octets of the message
       digest value as the checksum value.

7.2  Triple-DES Key Wrap

   The Triple-DES key wrap algorithm encrypts a Triple-DES content-
   encryption key with a Triple-DES key-encryption key.  The Triple-DES
   key wrap algorithm is:

   1.  Set odd parity for each of the DES key octets comprising
       the content-encryption key, call the result CEK.
   2.  Compute an 8 octet key checksum value on CEK as described above
       in Section 12.6.1, call the result ICV.
   3.  Let CEKICV = CEK || ICV.
   4.  Generate 8 octets at random, call the result IV.
   5.  Encrypt CEKICV in CBC mode using the key-encryption key.  Use
       the random value generated in the previous step as the
       initialization vector (IV).  Call the ciphertext TEMP1.
   6.  Let TEMP2 = IV || TEMP1.
   7.  Reverse the order of the octets in TEMP2.  That is, the most
       significant (first) octet is swapped with the least significant
       (last) octet, and so on.  Call the result TEMP3.
   8.  Encrypt TEMP3 in CBC mode using the key-encryption key.  Use
       an initialization vector (IV) of 0x4adda22c79e82105.
       The ciphertext is 40 octets long.

   Note:  When the same content-encryption key is wrapped in different
   key-encryption keys, a fresh initialization vector (IV) must be
   generated for each invocation of the key wrap algorithm.












Housley                                                        [Page 13]


INTERNET DRAFT                                                April 2001


7.3  Triple-DES Key Unwrap

   The Triple-DES key unwrap algorithm decrypts a Triple-DES content-
   encryption key using a Triple-DES key-encryption key.  The Triple-DES
   key unwrap algorithm is:

   1.  If the wrapped content-encryption key is not 40 octets, then
       error.
   2.  Decrypt the wrapped content-encryption key in CBC mode using
       the key-encryption key.  Use an initialization vector (IV)
       of 0x4adda22c79e82105.  Call the output TEMP3.
   3.  Reverse the order of the octets in TEMP3.  That is, the most
       significant (first) octet is swapped with the least significant
       (last) octet, and so on.  Call the result TEMP2.
   4.  Decompose the TEMP2 into IV and TEMP1.  IV is the most
       significant (first) 8 octets, and TEMP1 is the least significant
       (last) 32 octets.
   5.  Decrypt TEMP1 in CBC mode using the key-encryption key.  Use
       the IV value from the previous step as the initialization vector.
       Call the ciphertext CEKICV.
   6.  Decompose the CEKICV into CEK and ICV. CEK is the most significant
       (first) 24 octets, and ICV is the least significant (last) 8 octets.
   7.  Compute an 8 octet key checksum value on CEK as described above
       in Section 12.6.1.  If the computed key checksum value does not
       match the decrypted key checksum value, ICV, then error.
   8.  Check for odd parity each of the DES key octets comprising CEK.
       If parity is incorrect, then there is an error.
   9.  Use CEK as the content-encryption key.

7.4  RC2 Key Wrap

   The RC2 key wrap algorithm encrypts a RC2 content-encryption key with
   a RC2 key-encryption key.  The RC2 key wrap algorithm is:

   1.  Let the content-encryption key be called CEK, and let the length
       of the content-encryption key in octets be called LENGTH.  LENGTH
       is a single octet.
   2.  Let LCEK = LENGTH || CEK.
   3.  Let LCEKPAD = LCEK || PAD.  If the length of LCEK is a multiple
       of 8, the PAD has a length of zero.  If the length of LCEK is
       not a multiple of 8, then PAD contains the fewest number of
       random octets to make the length of LCEKPAD a multiple of 8.
   4.  Compute an 8 octet key checksum value on LCEKPAD as described
       above in Section 12.6.1, call the result ICV.
   5.  Let LCEKPADICV = LCEKPAD || ICV.
   6.  Generate 8 octets at random, call the result IV.
   7.  Encrypt LCEKPADICV in CBC mode using the key-encryption key.
       Use the random value generated in the previous step as the



Housley                                                        [Page 14]


INTERNET DRAFT                                                April 2001


       initialization vector (IV).  Call the ciphertext TEMP1.
   8.  Let TEMP2 = IV || TEMP1.
   9.  Reverse the order of the octets in TEMP2.  That is, the most
       significant (first) octet is swapped with the least significant
       (last) octet, and so on.  Call the result TEMP3.
   10. Encrypt TEMP3 in CBC mode using the key-encryption key.  Use
       an initialization vector (IV) of 0x4adda22c79e82105.

   Note:  When the same content-encryption key is wrapped in different
   key-encryption keys, a fresh initialization vector (IV) must be
   generated for each invocation of the key wrap algorithm.

7.5  RC2 Key Unwrap

   The RC2 key unwrap algorithm decrypts a RC2 content-encryption key
   using a RC2 key-encryption key.  The RC2 key unwrap algorithm is:

   1.  If the wrapped content-encryption key is not a multiple of 8
       octets, then error.
   2.  Decrypt the wrapped content-encryption key in CBC mode using
       the key-encryption key.  Use an initialization vector (IV)
       of 0x4adda22c79e82105.  Call the output TEMP3.
   3.  Reverse the order of the octets in TEMP3.  That is, the most
       significant (first) octet is swapped with the least significant
       (last) octet, and so on.  Call the result TEMP2.
   4.  Decompose the TEMP2 into IV and TEMP1.  IV is the most
       significant (first) 8 octets, and TEMP1 is the remaining octets.
   5.  Decrypt TEMP1 in CBC mode using the key-encryption key.  Use
       the IV value from the previous step as the initialization vector.
       Call the plaintext LCEKPADICV.
   6.  Decompose the LCEKPADICV into LCEKPAD, and ICV.  ICV is the
       least significant (last) octet 8 octets.  LCEKPAD is the
       remaining octets.
   7.  Compute an 8 octet key checksum value on LCEKPAD as described
       above in Section 12.6.1.  If the computed key checksum value
       does not match the decrypted key checksum value, ICV, then error.
   8.  Decompose the LCEKPAD into LENGTH, CEK, and PAD.  LENGTH is the
       most significant (first) octet.  CEK is the following LENGTH
       octets.  PAD is the remaining octets, if any.
   9.  If the length of PAD is more than 7 octets, then error.
   10. Use CEK as the content-encryption key.










Housley                                                        [Page 15]


INTERNET DRAFT                                                April 2001


Appendix A:  ASN.1 Module

   CryptographicMessageSyntaxAlgorithms
       { iso(1) member-body(2) us(840) rsadsi(113549)
         pkcs(1) pkcs-9(9) smime(16) modules(0) cmsalg-2001(16) }

   DEFINITIONS IMPLICIT TAGS ::=
   BEGIN

   -- EXPORTS All
   -- The types and values defined in this module are exported for use in
   -- the other ASN.1 modules.  Other applications may use them for their
   -- own purposes.

   -- IMPORTS None


   -- Algorithm Identifiers

   sha-1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
       oiw(14) secsig(3) algorithm(2) 26 }

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

   id-dsa-with-sha1 OBJECT IDENTIFIER ::=  { iso(1) member-body(2)
       us(840) x9-57 (10040) x9cm(4) 3 }

   rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
       us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }

   dh-public-number OBJECT IDENTIFIER ::= { iso(1) member-body(2)
       us(840) ansi-x942(10046) number-type(2) 1 }

   id-alg-ESDH OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
       rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 5 }

   id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
       us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 6 }

   id-alg-CMSRC2wrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
       us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 7 }

   des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2)
       us(840) rsadsi(113549) encryptionAlgorithm(3) 7 }

   rc2-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
       rsadsi(113549) encryptionAlgorithm(3) 2 }



Housley                                                        [Page 16]


INTERNET DRAFT                                                April 2001


   hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
       dod(6) internet(1) security(5) mechanisms(5) 8 1 2 }


   -- Algorithm Parameters

   KeyWrapAlgorithm ::= AlgorithmIdentifier

   RC2wrapParameter ::= RC2ParameterVersion

   RC2ParameterVersion ::= INTEGER

   CBCParameter ::= IV

   IV ::= OCTET STRING  -- exactly 8 octets

   RC2CBCParameter ::= SEQUENCE {
     rc2ParameterVersion INTEGER,
     iv OCTET STRING  }  -- exactly 8 octets

   END -- of CryptographicMessageSyntaxAlgorithms



References

   3DES       American National Standards Institute.  ANSI X9.52-1998,
              Triple Data Encryption Algorithm Modes of Operation.  1998.

   CMS        Housley, R.  Cryptographic Message Syntax.  RFC <TBD>.  <Date>.
              {draft-ietf-smime-rfc2630bis-*.txt}

   DES        American National Standards Institute.  ANSI X3.106,
              "American National Standard for Information Systems - Data
              Link Encryption".  1983.

   DH-X9.42   Rescorla, E.  Diffie-Hellman Key Agreement Method.
              RFC 2631.  June 1999.

   DSS        National Institute of Standards and Technology.
              FIPS Pub 186: Digital Signature Standard.  19 May 1994.

   HMAC       Krawczyk, H.  HMAC: Keyed-Hashing for Message Authentication.
              RFC 2104.  February 1997.

   MD5        Rivest, R.  The MD5 Message-Digest Algorithm.  RFC 1321.
              April 1992.




Housley                                                        [Page 17]


INTERNET DRAFT                                                April 2001


   MMA        Rescorla, E.  Preventing the Million Message Attack on CMS.
              RFC <TBD>.  <Date>.  {draft-ietf-smime-pkcs1-*.txt}

   MODES      National Institute of Standards and Technology.
              FIPS Pub 81: DES Modes of Operation.  2 December 1980.

   NEWPKCS#1  Kaliski, B., and J. Staddon.  PKCS #1: RSA Encryption,
              Version 2.0.  RFC 2437.  October 1998.

   PKCS#1     Kaliski, B.  PKCS #1: RSA Encryption, Version 1.5.
              RFC 2313.  March 1998.

   RANDOM     Eastlake, D., S. Crocker, and J. Schiller.  Randomness
              Recommendations for Security.  RFC 1750.  December 1994.

   RC2        Rivest, R.  A Description of the RC2 (r) Encryption Algorithm.
              RFC 2268.  March 1998.

   SHA1       National Institute of Standards and Technology.
              FIPS Pub 180-1: Secure Hash Standard.  17 April 1995.

   STDWORDS   Bradner, S.  Key Words for Use in RFCs to Indicate
              Requirement Levels.  RFC2119.  March 1997.

   X.208-88   CCITT.  Recommendation X.208: Specification of Abstract
              Syntax Notation One (ASN.1).  1988.

   X.209-88   CCITT.  Recommendation X.209: Specification of Basic Encoding
              Rules for Abstract Syntax Notation One (ASN.1).  1988.

Security Considerations

   The CMS provides a method for digitally signing data, digesting data,
   encrypting data, and authenticating data.  This document identifies
   the cryptographic algorithms for use with CMS.

   Implementations must protect the signer's private key.  Compromise of
   the signer's private key permits masquerade.

   Implementations must protect the key management private key, the key-
   encryption key, and the content-encryption key.  Compromise of the
   key management private key or the key-encryption key may result in
   the disclosure of all messages protected with that key.  Similarly,
   compromise of the content-encryption key may result in disclosure of
   the associated encrypted content.

   Implementations must protect the key management private key and the
   message-authentication key.  Compromise of the key management private



Housley                                                        [Page 18]


INTERNET DRAFT                                                April 2001


   key permits masquerade of authenticated data.  Similarly, compromise
   of the message-authentication key may result in undetectable
   modification of the authenticated content.

   The key management technique employed to distribute message-
   authentication keys must itself provide data origin authentication,
   otherwise the message content is delivered with integrity from an
   unknown source.  Neither RSA [PKCS#1, NEWPKCS#1] nor Ephemeral-Static
   Diffie-Hellman [DH-X9.42] provide the necessary data origin
   authentication.  Static-Static Diffie-Hellman [DH-X9.42] does provide
   the necessary data origin authentication when both the originator and
   recipient public keys are bound to appropriate identities in X.509
   certificates.

   When more than two parties share the same message-authentication key,
   data origin authentication is not provided.  Any party that knows the
   message-authentication key can compute a valid MAC, therefore the
   message could originate from any one of the parties.

   Implementations must randomly generate content-encryption keys,
   message-authentication keys, initialization vectors (IVs), and
   padding.  Also, the generation of public/private key pairs relies on
   a random numbers.  The use of inadequate pseudo-random number
   generators (PRNGs) to generate cryptographic keys can result in
   little or no security.  An attacker may find it much easier to
   reproduce the PRNG environment that produced the keys, searching the
   resulting small set of possibilities, rather than brute force
   searching the whole key space.  The generation of quality random
   numbers is difficult.  RFC 1750 [RANDOM] offers important guidance in
   this area, and Appendix 3 of FIPS Pub 186 [DSS] provides one quality
   PRNG technique.

   When using key agreement algorithms or previously distributed
   symmetric key-encryption keys, a key-encryption key is used to
   encrypt the content-encryption key.  If the key-encryption and
   content-encryption algorithms are different, the effective security
   is determined by the weaker of the two algorithms.  If, for example,
   a message content is encrypted with 168-bit Triple-DES and the
   Triple-DES content-encryption key is wrapped with a 40-bit RC2 key,
   then at most 40 bits of protection is provided.  A trivial search to
   determine the value of the 40-bit RC2 key can recover Triple-DES key,
   and then the Triple-DES key can be used to decrypt the content.
   Therefore, implementers must ensure that key-encryption algorithms
   are as strong or stronger than content-encryption algorithms.

   Section 7 specifies key wrap algorithms used to encrypt a Triple-DES
   [3DES] content-encryption key with a Triple-DES key-encryption key or
   to encrypt a RC2 [RC2] content-encryption key with a RC2 key-



Housley                                                        [Page 19]


INTERNET DRAFT                                                April 2001


   encryption key.  The key wrap algorithms make use of CBC mode
   [MODES].  These key wrap algorithms have been reviewed for use with
   Triple-DES and RC2.  They have not been reviewed for use with other
   cryptographic modes or other encryption algorithms.  Therefore, if a
   CMS implementation wishes to support ciphers in addition to Triple-
   DES or RC2, then additional key wrap algorithms need to be defined to
   support the additional ciphers.

   Implementers should be aware that cryptographic algorithms become
   weaker with time.  As new cryptoanalysis techniques are developed and
   computing performance improves, the work factor to break a particular
   cryptographic algorithm will reduce.  Therefore, cryptographic
   algorithm implementations should be modular allowing new algorithms
   to be readily inserted.  That is, implementers should be prepared for
   the set of mandatory to implement algorithms to change over time.

   The countersignature unauthenticated attribute includes a digital
   signature that is computed on the content signature value, thus the
   countersigning process need not know the original signed content.
   This structure permits implementation efficiency advantages; however,
   this structure may also permit the countersigning of an inappropriate
   signature value.  Therefore, implementations that perform
   countersignatures should either verify the original signature value
   prior to countersigning it (this verification requires processing of
   the original content), or implementations should perform
   countersigning in a context that ensures that only appropriate
   signature values are countersigned.

   Users of CMS, particularly those employing CMS to support interactive
   applications, should be aware that PKCS #1 Version 1.5 as specified
   in RFC 2313 [PKCS#1] is vulnerable to adaptive chosen ciphertext
   attacks when applied for encryption purposes.  Exploitation of this
   identified vulnerability, revealing the result of a particular RSA
   decryption, requires access to an oracle which will respond to a
   large number of ciphertexts (based on currently available results,
   hundreds of thousands or more), which are constructed adaptively in
   response to previously-received replies providing information on the
   successes or failures of attempted decryption operations.  As a
   result, the attack appears significantly less feasible to perpetrate
   for store-and-forward S/MIME environments than for directly
   interactive protocols.  Where CMS constructs are applied as an
   intermediate encryption layer within an interactive request-response
   communications environment, exploitation could be more feasible.

   An updated version of PKCS #1 has been published, PKCS #1 Version 2.0
   [NEWPKCS#1].  This new document supersedes RFC 2313.  PKCS #1 Version
   2.0 preserves support for the encryption padding format defined in
   PKCS #1 Version 1.5 [PKCS#1], and it also defines a new alternative.



Housley                                                        [Page 20]


INTERNET DRAFT                                                April 2001


   To resolve the adaptive chosen ciphertext vulnerability, the PKCS #1
   Version 2.0 specifies and recommends use of Optimal Asymmetric
   Encryption Padding (OAEP) when RSA encryption is used to provide
   confidentiality.  Designers of protocols and systems employing CMS
   for interactive environments should either consider usage of OAEP, or
   should ensure that information which could reveal the success or
   failure of attempted PKCS #1 Version 1.5 decryption operations is not
   provided.  Support for OAEP will likely be added to a future version
   of the CMS algorithm specification.

   See RFC <TBD> [MMA] for more information about thwarting the adaptive
   chosen ciphertext vulnerability in PKCS #1 Version 1.5
   implementations.

Acknowledgments

   This document is the result of contributions from many professionals.
   I appreciate the hard work of all members of the IETF S/MIME Working
   Group.  I extend a special thanks to Rich Ankney, Simon Blake-Wilson,
   Tim Dean, Steve Dusse, Carl Ellison, Peter Gutmann, Bob Jueneman,
   Stephen Henson, Paul Hoffman, Scott Hollenbeck, Don Johnson, Burt
   Kaliski, John Linn, John Pawling, Blake Ramsdell, Francois Rousseau,
   Jim Schaad, and Dave Solo for their efforts and support.

Author Address

   Russell Housley
   RSA Laboratories
   918 Spring Knoll Drive
   Herndon, VA 20170
   USA

   rhousley@rsasecurity.com



Full Copyright Statement

   Copyright (C) The Internet Society (2001).  All Rights Reserved.

   This document and translations of it may be copied and furnished to
   others, and derivative works that comment on or otherwise explain it
   or assist in its implementation may be prepared, copied, published
   and distributed, in whole or in part, without restriction of any
   kind, provided that the above copyright notice and this paragraph are
   included on all such copies and derivative works.  In addition, the
   ASN.1 module presented in Appendix A may be used in whole or in part
   without inclusion of the copyright notice.  However, this document



Housley                                                        [Page 21]


INTERNET DRAFT                                                April 2001


   itself may not be modified in any way, such as by removing the
   copyright notice or references to the Internet Society or other
   Internet organizations, except as needed for the purpose of
   developing Internet standards in which case the procedures for
   copyrights defined in the Internet Standards process shall be
   followed, or as required to translate it into languages other than
   English.

   The limited permissions granted above are perpetual and will not be
   revoked by the Internet Society or its successors or assigns.  This
   document and the information contained herein is provided on an "AS
   IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK
   FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
   LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL
   NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY
   OR FITNESS FOR A PARTICULAR PURPOSE.



































Housley                                                        [Page 22]