Optimal asymmetric encryption padding
In
The OAEP algorithm is a form of
OAEP satisfies the following two goals:
- Add an element of randomness which can be used to convert a RSA) into a probabilisticscheme.
- Prevent partial decryption of ciphertexts (or other information leakage) by ensuring that an adversary cannot recover any portion of the plaintext without being able to invert the trapdoor one-way permutation.
The original version of OAEP (Bellare/Rogaway, 1994) showed a form of "
Algorithm

In the diagram,
- MGF is the mask generating function, usually MGF1,
- Hash is the chosen hash function,
- hLen is the length of the output of the hash function in bytes,
- k is the length of the RSAmodulus n in bytes,
- M is the message to be padded, with length mLen (at most bytes),
- L is an optional label to be associated with the message (the label is the empty string by default and can be used to authenticate data without requiring encryption),
- PS is a byte string of null-bytes.
- ⊕ is an XOR-Operation.
Encoding
RFC 8017[6] for PKCS#1 v2.2 specifies the OAEP scheme as follows for encoding:
- Hash the label L using the chosen hash function:
- Generate a padding string PS consisting of bytes with the value 0x00.
- Concatenate lHash, PS, the single byte 0x01, and the message M to form a data block DB: . This data block has length bytes.
- Generate a random seed of length hLen.
- Use the mask generating function to generate a mask of the appropriate length for the data block:
- Mask the data block with the generated mask:
- Use the mask generating function to generate a mask of length hLen for the seed:
- Mask the seed with the generated mask:
- The encoded (padded) message is the byte 0x00 concatenated with the maskedSeed and maskedDB:
Decoding
Decoding works by reversing the steps taken in the encoding algorithm:
- Hash the label L using the chosen hash function:
- To reverse step 9, split the encoded message EM into the byte 0x00, the maskedSeed (with length hLen) and the maskedDB:
- Generate the seedMask which was used to mask the seed:
- To reverse step 8, recover the seed with the seedMask:
- Generate the dbMask which was used to mask the data block:
- To reverse step 6, recover the data block DB:
- To reverse step 3, split the data block into its parts: .
- 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.
- If any of these conditions aren't met, then the padding is invalid.
- Verify that:
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
See also
- Key encapsulation
References
- Springer-Verlag, 1995. full version (pdf)
- ^
Eiichiro Fujisaki, Tatsuaki Okamoto, David Pointcheval, and CRYPTO 2001, vol. 2139 of Lecture Notes in Computer Science, SpringerVerlag, 2001. full version (pdf)
- ^ Victor Shoup. OAEP Reconsidered. IBM Zurich Research Lab, Saumerstr. 4, 8803 Ruschlikon, Switzerland. September 18, 2001. full version (pdf)
- ^
P. Paillier and J. Villar, Trading One-Wayness against Chosen-Ciphertext Security in Factoring-Based Encryption, Advances in Cryptology – Asiacrypt2006.
- ^ D. Brown, What Hashes Make RSA-OAEP Secure?, IACR ePrint 2006/233.
- . Retrieved 2022-06-04.
- ^ Brown, Daniel R. L. (2006). "What Hashes Make RSA-OAEP Secure?" (PDF). IACR Cryptology ePrint Archive. Retrieved 2019-04-03.