fis MF3ICD40 (D40) secure channel crypto #2679
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed D40 secure channel auth was broken. The original D40 silicon can only perform encryption operations so any data encryption PCD side must be done with the DES decrypt primitive. MAC calculation still needs to be done with the DES encrypt primitive though.
I added a couple of comments which should help the next person touching the code too.
Due to a weird quirk of DES that I only learnt just now, DES encryption with a key of all zeros is identical to DES decryption with key of all zeros so the issue doesn't exhibit if you're testing with a factory defaulted card using zero'd keys, but it's easy enough to change the keys to test.
Previous broken behaviour shown below, note this is against a DESFire EV2 card, so can use EV1 auth to verify the keys are correct, while the D40 secure channel fails. With this patch both commands succeed. I also tested PCD MAC'd packets and they were already correct (eg doing a
hf mfd write
with the communication mode set to MAC) and indeed swapping the encryption primitive there breaks it (I did add a helpful comment there though)