rain
rain
CC#
Created by rain on 11/23/2023 in #help
DES implementation (off by one?)
Hi, I need to use CBC-DES with an all zeroes key for the reason of changing key from using DES to AES on Mifare DESFire. Neither Microsoft's implementation or bouncycastle allows this, and since I did not find anyone having done the cbc part in C# online, I am more or less implementing it on my own with the help of auxiliary methods licensed under MIT that I did find on github (no CBC support however) I did get it working this morning for a one block size, but when trying to fix the chaining I made some change that I can't remember and now I get almost-but-not-quite the expected value when encrypting even one block. Unfortunately I had not checked it in either before I started doing that. Maybe I am missing something obvious, either way, a fresh set of eyes would be very helpful. Attached is an MRP. Running it gives this input:
Data is FF-FF-FF-FF-FF-FF-FF-FF with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00
Encrypting FF-FF-FF-FF-FF-FF-FF-FF with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO F1-92-AD-6B-3F-15-A0-AE
Decrypting F1-92-AD-6B-3F-15-A0-AE with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO 3A-AE-EB-91-1B-8B-18-53
Decrypting F2-61-5E-97-3F-2A-50-5D with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO FF-FF-FF-FF-FF-FF-FF-FF
===================================================
Encrypted is F1-92-AD-6B-3F-15-A0-AE
Microsoft is F2-61-5E-97-3F-2A-50-5D
===================================================
===================================================
Decrypted again: [3A-AE-EB-91-1B-8B-18-53]
Microsoft says [FF-FF-FF-FF-FF-FF-FF-FF]
The original was [FF-FF-FF-FF-FF-FF-FF-FF]
Decrypting MS [FF-FF-FF-FF-FF-FF-FF-FF]
===================================================
Data is FF-FF-FF-FF-FF-FF-FF-FF with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00
Encrypting FF-FF-FF-FF-FF-FF-FF-FF with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO F1-92-AD-6B-3F-15-A0-AE
Decrypting F1-92-AD-6B-3F-15-A0-AE with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO 3A-AE-EB-91-1B-8B-18-53
Decrypting F2-61-5E-97-3F-2A-50-5D with key 32-07-63-00-00-C2-D8-39 IV 00-00-00-00-00-00-00-00 TO FF-FF-FF-FF-FF-FF-FF-FF
===================================================
Encrypted is F1-92-AD-6B-3F-15-A0-AE
Microsoft is F2-61-5E-97-3F-2A-50-5D
===================================================
===================================================
Decrypted again: [3A-AE-EB-91-1B-8B-18-53]
Microsoft says [FF-FF-FF-FF-FF-FF-FF-FF]
The original was [FF-FF-FF-FF-FF-FF-FF-FF]
Decrypting MS [FF-FF-FF-FF-FF-FF-FF-FF]
===================================================
I am using a non-zero key for this to be able to compare with MS' implementation. As you can see, decrypting the data encrypted using MS gives the right value, but encrypting seems slightly, increasingly, off. Thanks in advance.
1 replies