Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The decryption code is PKCS#1 v1.5 non-compliant - no padding length check #164

tomato42 opened this issue Oct 26, 2020 · 1 comment


Copy link

@tomato42 tomato42 commented Oct 26, 2020

the current code:


Lines 246 to 267 in 6f59ff0

blocksize = common.byte_size(priv_key.n)
encrypted = transform.bytes2int(crypto)
decrypted = priv_key.blinded_decrypt(encrypted)
cleartext = transform.int2bytes(decrypted, blocksize)
# Detect leading zeroes in the crypto. These are not reflected in the
# encrypted value (as leading zeroes do not influence the value of an
# integer). This fixes CVE-2020-13757.
if len(crypto) > blocksize:
raise DecryptionError('Decryption failed')
# If we can't find the cleartext marker, decryption failed.
if cleartext[0:2] != b'\x00\x02':
raise DecryptionError('Decryption failed')
# Find the 00 separator between the padding and the message
sep_idx = cleartext.index(b'\x00', 2)
except ValueError:
raise DecryptionError('Decryption failed')
return cleartext[sep_idx + 1:]

doesn't check that the length of the padding is at least 8 bytes.

See step 3

Copy link

@sybrenstuvel sybrenstuvel commented Nov 11, 2020

Thanks for the report. This is fortunately easy enough to fix after #165 (comment) is implemented. Changing the line

sep_idx_bad = sep_idx < 0


sep_idx_bad = sep_idx < 10

should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants