#🔒 Two AES (CBC) decryption, with same Key, IV and Data returns different plaintexts using pycryptodo

12 messages · Page 1 of 1 (latest)

dense juniper
#

As the title says I'm trying to find out why python gives me different plaintexts, I'm using these values:
Key: 6ec23692ce90428e421bf68a5e1f64a3
Iv: 00000000000000000000000000000000
Encrypted data: 51a8c42907e251a2d5bbea21d290bd709a726e9a7502a34a4ad3e8df6cabeb5bab3056623fd48ab731407d59ada795327db050dcc1db06a5df3fe1aba695a33b64d91d946beb8c031aef793c1e015037c9aaaf3244d2e1c82a599507401f91b7096e77506c5f91a3c60b756de4b9357c5dddbbffd7eed5dc7689263196ac8f843181382d2058c891e8a7d5d19f6a730f5a27de19727316ac4f982e9b9f6cd591624bf89157b33282f91981692945225cc5000f4bf78dacbe7efdeec93cb5805e4bbf70e15890ac0fc6b3f3043e68fc4566172b037c2b35130cb530ab7c16ca06e15baba03c609fd98e2f4bab998a6d558b0d230a9abcb43f824d809b891ad5cb9a6064fea1ab7058fb1abfef71db1086d2fddeeb9ea31ea9efa1d1021bccf1932a90dea1366dd2c4ca97d1b48e36a3c8c4b4b7a40430fae994d5a932ff030fc1b3f310157a76f659d0b74022c4312c3d369f74a074cf377ba2e384dce79b379a554d0894153d5017984e90ccd65ca8887a3eafd0e3bb6b60f1fddb3ef9e720d626f262d24920a44ae9ca17a352e22b9fba988784db96f426cce6b56ad6dc2a26641853ba777682ccf40f42ba02aea77486a1325263198ccac1f761ca721624c1bae2322cbd48a20e6f5abbb27c61d8023c44efaebc9d3ae80de3fca0bcba7825cb9156fc9d69bb503e7edfe39913ed25944f5086308cc521c3538f1dcee0d98d
(data contains 512 bytes, so it is already fixed and padding is not needed)

The first plaintext block (16 bytes) is different:

  1. First decryption returns: 2e455bb228e3201d8cd466051852f418
  2. Second decryption returns: ba0a0b34186fe53c4f87e918d6b22d95
    The plaintext is equal after the first block (so others blocks are decrypted correctly).

I'm using python 3.9.6 (but I also tested it with 3.10.1).

Github script reference: https://github.com/shijimasoft/cia-unix/blob/experimental/decrypt.py
Decryption is executed at: https://github.com/shijimasoft/cia-unix/blob/4fc736101f8c936f31ddb5efe435ce903821bea4/decrypt.py#L139

GitHub

Decrypt CIA/3DS roms in UNIX environments (Linux and macOS) - shijimasoft/cia-unix

GitHub

Decrypt CIA/3DS roms in UNIX environments (Linux and macOS) - shijimasoft/cia-unix

trim notchBOT
#

@dense juniper

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

thick viper
#

did u use the same iv for both encryption as well as decryption?

dense juniper
#

An yes, I used the same IV (that is a 16 * 0x00)

#

I tried to xor the IV with the first decrypted block (in the first attempt) but it doesn't return the first decrypted block (in the second attempt)

thick viper
#

u said that padding is not needed, but what if the encryption/decryption process added padding?

dense juniper
#

I thinked the same things, but after trying with a C AES library I discovered that the first block remain the same in two sequential decryption

#

So the first block was 2e455bb228e3201d8cd466051852f418 each time

#

(I tried with tinyAES in C and aes from RustCrypto in Rust)

trim notchBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.