RSA-OAEP decoder accepts nonzero bytes inside the zero padding string
Testing, NormalPublic

Assigned To
Authored By
werner
Tue, Aug 4, 5:04 PM
Subscribers

Description

RSA-OAEP decoder accepts nonzero bytes inside the zero padding string

After unmasking OAEP's data block, the decoder verifies lHash and searches for the first 0x01 delimiter. It does not verify that every byte between lHash and that delimiter is zero. A data block containing arbitrary nonzero padding bytes is therefore accepted and its suffix returned as plaintext.

Vulnerable code

In cipher/rsa-common.c, function _gcry_rsa_oaep_decode:

failed |= ct_not_memequal (lhash, db, hlen);
for (n = n1 = hlen; n < db_len; n++)
  {
    not_found &= ct_not_equal_byte (db[n], 0x01);
    n1 += not_found;
  }
failed |= not_found;

Why it matters

OAEP requires DB to be lHash || PS || 0x01 || M with PS entirely zero. Accepting a larger language of encodings weakens strict ciphertext validation and can become useful if a protocol reveals success through output, errors, or timing. Constructing such an RSA ciphertext without the private key is not established here, so this finding is a decoder correctness flaw rather than a standalone decryption oracle.

Proposed fix

During the existing full-length scan, accumulate a constant-time failure bit for any byte that is neither zero while still before the first 0x01. Preserve the uniform scan and delayed error return. Add OAEP decode vectors with a nonzero byte at the start, middle, and end of PS, plus empty and valid PS cases, and check identical public error behavior for all malformed encodings.

Revisions and Commits

Related Objects

StatusAssignedTask
Testing gniibe

Event Timeline

werner triaged this task as Normal priority.Tue, Aug 4, 5:04 PM
werner created this task.
werner created this object with visibility "Public (No Login Required)".
werner created this object with edit policy "Contributor (Project)".
werner shifted this object from the Restricted Space space to the S1 Public space.Wed, Aug 26, 10:58 AM
gniibe changed the task status from Open to Testing.Thu, Aug 27, 7:03 AM
gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Aug 31, 2:58 AM