Network Working Group E. Rescorla Request for Comments: 3218 RTFM, Inc. Category: Informational January 2002Preventing the Million Message Attack on Cryptographic Message Syntax
1. Introduction
When data is encrypted using RSA it must be padded out to the length of the modulus -- typically 512 to 2048 bits. The most popular technique for doing this is described in [PKCS-1-v1.5]. However, in 1998 Bleichenbacher described an adaptive chosen ciphertext attack on SSL [MMA]. This attack, called the Million Message Attack, allowed the recovery of a single PKCS-1 encrypted block, provided that the attacker could convince the receiver to act as a particular kind of oracle. (An oracle is a program which answers queries based on information unavailable to the requester (in this case the private key)). The MMA is also possible against [CMS]. Mail list agents are the most likely CMS implementations to be targets for the MMA, since mail list agents are automated servers that automatically respond to a large number of messages. This document describes a strategy for resisting such attacks.
Rescorla Informational [Page 1]
RFC 3218 Preventing the Million Message Attack on CMS January 2002 2. Overview of PKCS-1The first stage in RSA encryption is to map the message to be encrypted (in CMS a symmetric content-encryption key (CEK)) into an integer the same length as (but numerically less than) the RSA modulus of the recipient's public key (typically somewhere between 512 and 2048 bits). PKCS-1 describes the most common procedure for this transformation.
+---+---+----------------------+---+---------------------+
| 0 | 2 | Nonzero random bytes | 0 | Message |
+---+---+----------------------+---+---------------------+
Once the block has been formatted, the sender must then convert the block into an integer. This is done by treating the block as an integer in big-endian form. Thus, the resulting number is less than the modulus (because the first byte is zero), but within a factor of 2^16 (because the second byte is 2).
Rescorla Informational [Page 2]
RFC 3218 Preventing the Million Message Attack on CMS January 2002 2.1. The Million Message AttackThe purpose of the Million Message Attack (MMA) is to recover a single plaintext (formatted block) given the ciphertext (encrypted block). The attacker first captures the ciphertext in transit and then uses the recipient as an oracle to recover the plaintext by sending transformed versions of the ciphertext and observing the recipient's response.
2.2. Applicability
Since the MMA requires so many messages, it must be mounted against a victim who is willing to process a large number of messages. In practice, no human is willing to read this many messages and so the MMA can only be mounted against an automated victim.
Rescorla Informational [Page 3]
RFC 3218 Preventing the Million Message Attack on CMS January 2002
5. M' is properly formatted and the resulting CEK is correct. This is extremely improbable but not impossible.
2.2.1. Note on Block Cipher Padding
[CMS] specifies a particular kind of block cipher padding in which the final cipher block is padded with bytes containing the length of the padding. For instance, a 5-byte block would be padded with three bytes of value 03, as in:2.3. Countermeasures 2.3.1. Careful CheckingEven without countermeasures, sufficiently careful checking can go quite a long way to mitigating the success of the MMA. If the receiving implementation also checks the length of the CEK and the parity bits (if available) AND responds identically to all such errors, the chances of a given M' being properly formatted are substantially decreased. This increases the number of probe messages required to recover M. However, this sort of checking only increases the workfactor and does not eliminate the attack entirely because some messages will still be properly formatted up to the point of keylength. However, the combination of all three kinds of checking (padding, length, parity bits) increases the number of messages to the point where the attack is impractical.
Rescorla Informational [Page 4]
RFC 3218 Preventing the Million Message Attack on CMS January 2002 2.3.2. Random FillingThe simplest countermeasure is to treat misformatted messages as if they were properly PKCS-1 formatted. When the victim detects an improperly formatted message, instead of returning an error he substitutes a randomly generated message. In CMS, since the message is always a wrapped content-encryption key (CEK) the victim should simply substitute a randomly generated CEK of appropriate length and continue. Eventually this will result in a decryption or signature verification error but this is exactly what would have happened if M' happened to be properly formatted but contained an incorrect CEK. Note that this approach also prevents the attacker from distinguishing various failure cases via timing since all failures return roughly the same timing behavior. (The time required to generate the random-padding is negligible in almost all cases. If an implementation has a very slow PRNG it can generate random padding for every message and simply discard it if the CEK decrypts correctly).
2.3.3. OAEP
Optimal Asymmetric Encryption Padding (OAEP) [OAEP, PKCS-1-v2] is another technique for padding a message into an RSA encryption block. Implementations using OAEP are not susceptible to the MMA. However, OAEP is incompatible with PKCS-1. Implementations of S/MIME and CMS must therefore continue to use PKCS-1 for the foreseeable future if they wish to communicate with current widely deployed implementations. OAEP is being specified for use with AES keys in CMS so this provides an upgrade path to OAEP.
Rescorla Informational [Page 5]
RFC 3218 Preventing the Million Message Attack on CMS January 2002 2.4. Security ConsiderationsThis entire document describes how to avoid a certain class of attacks when performing PKCS-1 decryption with RSA.
3. Acknowledgments
Thanks to Burt Kaliski and Russ Housley for their extensive and helpful comments.
4. References
[CMS] Housley, R., "Cryptographic Message Syntax", RFC 2630,
5. Author's Address
Eric Rescorla RTFM, Inc. 2064 Edgewood Drive Palo Alto, CA 94303
Rescorla Informational [Page 6]
RFC 3218 Preventing the Million Message Attack on CMS January 2002 6. Full Copyright StatementCopyright (C) The Internet Society (2002). All Rights Reserved.