randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.55k stars 561 forks source link

Problem with CommonCrypto using CBC/PKCS7 padding #1694

Open randombit opened 6 years ago

randombit commented 6 years ago

Found by new tests added in #1693. I cannot figure out the problem from the logs. It affects both DES and AES in CBC with PKCS7 padding when decrypting. https://travis-ci.org/randombit/botan/jobs/435127727

Failure 1: AES-128/CBC/PKCS7 unexpected result for encryption process
Produced: 0CBAF4FA94DF265FE264633A994BC25FC13B613502B81C32D7E4B94D4C6026FB25939E898AD7A66B8DD0C5191B8D1FA246C8CBDB4A582D44CD20C2C768AA698400000000000000000000000000000000
Expected: 0CBAF4FA94DF265FE264633A994BC25FC13B613502B81C32D7E4B94D4C6026FB25939E898AD7A66B8DD0C5191B8D1FA246C8CBDB4A582D44CD20C2C768AA6984573A891BD4E64CB33FCF1F0CF69DD78F
XOR Diff: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000573A891BD4E64CB33FCF1F0CF69DD78F (74 bits different)
Failure 2: AES-128/CBC/PKCS7 correct number of bytes processed produced unexpected result '48' expected '64'
Failure 3: AES-128/CBC/PKCS7 unexpected result for decryption process produced 80 bytes expected 64
Produced: 3A513EB569A503B4413B31FA883DDC88BCD6C62226C44C546B5E79D197159337A74EE109DC6E79B82E7FEC3EFF3BEF2646C8CBDB4A582D44CD20C2C768AA6984D1D50672EF5529A3C18C3E9522FC2097
Expected: 3A513EB569A503B4413B31FA883DDC88BCD6C62226C44C546B5E79D197159337A74EE109DC6E79B82E7FEC3EFF3BEF26D1D50672EF5529A3C18C3E9522FC2097
XOR Diff: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000971DCDA9A50D04E70CACFC524A564913 (60 bits different)

This may well be a simple issue, but it hard to debug not knowing the CommonCrypto API and not having ability to test changes short of guessing and then waiting for CI. I will see if I can borrow a Mac.

For now in #1693 I am disabling CommonCrypto with CBC/PKCS7.

/cc @oNaiPs

oNaiPs commented 6 years ago

@randombit could you point me how to enable the test back to debug? I couldn't figure it out.

randombit commented 6 years ago

@oNaiPs Remove comments around https://github.com/randombit/botan/blob/master/src/lib/prov/commoncrypto/commoncrypto_utils.cpp#L140 and run ./botan-test modes

oNaiPs commented 6 years ago

Got it I can reproduce it now. For some reason the test doesn't run when I do ./botan-test --provider="commoncryto" modes