Optimal asymmetric encryption padding explained

In cryptography, Optimal Asymmetric Encryption Padding (OAEP) is a padding scheme often used together with RSA encryption. OAEP was introduced by Bellare and Rogaway,[1] and subsequently standardized in PKCS#1 v2 and RFC 2437.

f

, this processing is proved in the random oracle model to result in a combined scheme which is semantically secure under chosen plaintext attack (IND-CPA). When implemented with certain trapdoor permutations (e.g., RSA), OAEP is also proven to be secure against chosen ciphertext attack. OAEP can be used to build an all-or-nothing transform.

OAEP satisfies the following two goals:

  1. Add an element of randomness which can be used to convert a deterministic encryption scheme (e.g., traditional RSA) into a probabilistic scheme.

f

.

The original version of OAEP (Bellare/Rogaway, 1994) showed a form of "plaintext awareness" (which they claimed implies security against chosen ciphertext attack) in the random oracle model when OAEP is used with any trapdoor permutation. Subsequent results contradicted this claim, showing that OAEP was only IND-CCA1 secure. However, the original scheme was proved in the random oracle model to be IND-CCA2 secure when OAEP is used with the RSA permutation using standard encryption exponents, as in the case of RSA-OAEP.[2] An improved scheme (called OAEP+) that works with any trapdoor one-way permutation was offered by Victor Shoup to solve this problem.[3] More recent work has shown that in the standard model (that is, when hash functions are not modeled as random oracles) it is impossible to prove the IND-CCA2 security of RSA-OAEP under the assumed hardness of the RSA problem.[4] [5]

Algorithm

In the diagram,

mLen=k-2hLen-2

bytes),

k-mLen-2hLen-2

null-bytes.

Encoding

RFC 8017[6] for PKCS#1 v2.2 specifies the OAEP scheme as follows for encoding:

  1. Hash the label L using the chosen hash function:

lHash=Hash(L)

  1. Generate a padding string PS consisting of

k-mLen-2hLen-2

bytes with the value 0x00.
  1. Concatenate lHash, PS, the single byte 0x01, and the message M to form a data block DB:

DB=lHash||PS||0x01||M

. This data block has length

k-hLen-1

bytes.
  1. Generate a random seed of length hLen.
  2. Use the mask generating function to generate a mask of the appropriate length for the data block:

dbMask=MGF(seed,k-hLen-1)

  1. Mask the data block with the generated mask:

maskedDB=DBdbMask

  1. Use the mask generating function to generate a mask of length hLen for the seed:

seedMask=MGF(maskedDB,hLen)

  1. Mask the seed with the generated mask:

maskedSeed=seedseedMask

  1. The encoded (padded) message is the byte 0x00 concatenated with the maskedSeed and maskedDB:

EM=0x00||maskedSeed||maskedDB

Decoding

Decoding works by reversing the steps taken in the encoding algorithm:

  1. Hash the label L using the chosen hash function:

lHash=Hash(L)

  1. To reverse step 9, split the encoded message EM into the byte 0x00, the maskedSeed (with length hLen) and the maskedDB:

EM=0x00||maskedSeed||maskedDB

  1. Generate the seedMask which was used to mask the seed:

seedMask=MGF(maskedDB,hLen)

  1. To reverse step 8, recover the seed with the seedMask:

seed=maskedSeedseedMask

  1. Generate the dbMask which was used to mask the data block:

dbMask=MGF(seed,k-hLen-1)

  1. To reverse step 6, recover the data block DB:

DB=maskedDBdbMask

  1. To reverse step 3, split the data block into its parts:

DB=lHash'||PS||0x01||M

.
    1. Verify that:
      • lHash is equal to the computed lHash
      • PS only consists of bytes 0x00
      • PS and M are separated by the 0x01 byte and
      • the first byte of EM is the byte 0x00.
    2. If any of these conditions aren't met, then the padding is invalid.

Usage in RSA: The encoded message can then be encrypted with RSA. The deterministic property of RSA is now avoided by using the OAEP encoding because the seed is randomly generated and influences the entire encoded message.

Security

The "all-or-nothing" security is from the fact that to recover M, one must recover the entire maskedDB and the entire maskedSeed; maskedDB is required to recover the seed from the maskedSeed, and the seed is required to recover the data block DB from maskedDB. Since any changed bit of a cryptographic hash completely changes the result, the entire maskedDB, and the entire maskedSeed must both be completely recovered.

Implementation

In the PKCS#1 standard, the random oracles are identical. The PKCS#1 standard further requires that the random oracles be MGF1 with an appropriate hash function.[7]

See also

References

  1. [Mihir Bellare|M. Bellare]
  2. Eiichiro Fujisaki, Tatsuaki Okamoto, David Pointcheval, and Jacques Stern. RSA-- OAEP is secure under the RSA assumption. In J. Kilian, ed., Advances in Cryptology – CRYPTO 2001, vol. 2139 of Lecture Notes in Computer Science, SpringerVerlag, 2001. full version (pdf)
  3. Victor Shoup. OAEP Reconsidered. IBM Zurich Research Lab, Saumerstr. 4, 8803 Ruschlikon, Switzerland. September 18, 2001. full version (pdf)
  4. P. Paillier and J. Villar, Trading One-Wayness against Chosen-Ciphertext Security in Factoring-Based Encryption, Advances in Cryptology – Asiacrypt 2006.
  5. D. Brown, What Hashes Make RSA-OAEP Secure?, IACR ePrint 2006/233.
  6. PKCS #1: RSA Cryptography Specifications Version 2.2. 8017. Encryption Operation. 7.1.1. 22. November 2016. IETF. 2022-06-04. 10.17487/RFC8017.
  7. What Hashes Make RSA-OAEP Secure?. IACR Cryptology ePrint Archive. Brown . Daniel R. L.. 2006. en. 2019-04-03.