libtom / libtomcrypt

LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
https://www.libtom.net
Other
1.51k stars 449 forks source link

fix pkcs_1_v1_5_decode() when empty message #613

Closed SOuajih closed 1 year ago

SOuajih commented 1 year ago

In case of EME-PKCS1-v1_5 decoding, the encoded message format is as follow : EM = 0x00 || 0x02 || PS || 0x00 || M. When using an empty message, the 0x00 octet that separates the padding string and message is located at the end. Thus, update the condition to pass the check in case of empty message.

This fixes the following AOSP cts test: Module: CtsKeystoreTestCases Test: testEmptyPlaintextEncryptsAndDecrypts Link: https://android.googlesource.com/platform/cts/+/refs/tags/android-cts-12.0_r6/tests/tests/keystore/src/android/keystore/cts/CipherTest.java

Checklist

SOuajih commented 1 year ago

I took the liberty to extend your PR a bit and force-push your branch.

Alright! .. Thank you for the review