timmerk / nfc-tools

Automatically exported from code.google.com/p/nfc-tools
0 stars 0 forks source link

Mifare Classic Key diversification #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Mifare Classic uses two types of diversification, old and new. The new type is 
very very similar to DESFire diversification, actually it is 100% the same, but 
the for DESFire the final key is taken from the last 16 bytes, for the classic 
it is first 6 bytes of the last 16 bytes. Will there be a fn that simply 
returns Classic type keys?

Original issue reported on code.google.com by ma...@unitedtickets.ee on 7 Jun 2012 at 7:02

GoogleCodeExporter commented 9 years ago
Thanks for reporting issue.

Could you provide a patch for this feature ?

If not, we will try to take care at this issue ASAP.

Original comment by romu...@libnfc.org on 8 Jun 2012 at 12:08

GoogleCodeExporter commented 9 years ago
No, unfortunately not due to the time constraints. Perhaps sometime in the fall 
i might get the time, for now i can only provide specifications for 
diversification.

Original comment by ma...@unitedtickets.ee on 8 Jun 2012 at 7:06

GoogleCodeExporter commented 9 years ago
Yes, feel free to let us some references to implement it.
Thanks

Original comment by romu...@libnfc.org on 8 Jun 2012 at 10:09

GoogleCodeExporter commented 9 years ago
Please find the file attached

Original comment by ma...@unitedtickets.ee on 8 Jun 2012 at 4:54

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks for attachement.

As we are quite busy with libnfc and ifdnfc right, I don't think we will 
improve libfreefare next days.
ASAP may be not enough for some users, so if any volunteer want to take this 
issue, feel free to attach patches.

Original comment by romu...@libnfc.org on 8 Jun 2012 at 6:42

GoogleCodeExporter commented 9 years ago
I have been trying to understand the algorithm but I am having some trouble 
understanding key diversification.

If I understand correctly we need to know the master key and the 3des key to 
compute diversified keys for a card ?

Signature should be something like : 

- GetKey(masterKey, 3desKey, uid, blockNumber);

I have some tags that looks like mifare classic but the KeyA from the first 
sector is always the same , the other keys are diversified.
Do you know if the first sector behave differently of maybe my set of tags 
doesn't use that diversification algorithm...

Original comment by olifo...@gmail.com on 13 Aug 2012 at 8:29

GoogleCodeExporter commented 9 years ago
what 3des key? No 3des key is needed. Take a look at the first post and take a 
look at DESFire diversification implementation in the project. You have to have 
master key and diversification input (which is card UID and sector number) from 
the output of desfire diversification take the first 6 bytes of last 16 
bytes(because classic keys are smaller).

Marko

Original comment by ma...@unitedtickets.ee on 13 Aug 2012 at 1:49

GoogleCodeExporter commented 9 years ago
I was talking about the first part of the document (old 2ktdes based key 
diversification).

Anyway I also looked at the second part of the document and the way it is done 
for desfire in libfreefare. 
According to the document there is some padding so that diversification input 
is always 32 bytes but in libfreefare, in cmac method it use key block size 
that is only 16 bytes.
I've made some slight modification to make it work as in the document.

It still doesn't explain why i have always the same key for all my tags but 
only for the first block (sector 0x03). Maybe they used a custom key 
diversification :/

Original comment by olifo...@gmail.com on 13 Aug 2012 at 1:58

GoogleCodeExporter commented 9 years ago
could be custom diversification.

sorry, i cannot help you with older diversification.

Marko

Original comment by ma...@unitedtickets.ee on 13 Aug 2012 at 2:05

GoogleCodeExporter commented 9 years ago
Issue moved to https://code.google.com/p/libfreefare/issues/detail?id=3

Original comment by yob...@gmail.com on 15 Jan 2013 at 8:04