Desfire Ev1 diverse questions

Forum / MIFARE and NFC Reader IC`s / Desfire Ev1 diverse questions

  • 15. August 2018 at 22:06
    Hi,

    First thing first: I have allready created an account on the NXP docstore, and waiting for my account to be validated (via NDAs probably). I have also notified my local sales rep here in france (which happens to be AVNET).

    Spoiler:
    So, here is the situation. I am working on a project with a kinetis (cortex M0) MCU, and a PN7150 chip. The final aim of this configuration is to read a dozen bytes, encrypted in an DESFIRE EV1 card. I have successfully implemented big parts of the communication protocol. For example, I am able to read NDEF records from a blank MIFARE DESFIRE EV1 card, on which i have written a "Hello World" text record.


    So far, so good.

    Now, I am trying to get the authentication part working, and to say the least, it's painful without any descent documentation. I know, i should probably wait until I get the NDA and more documents from NXP, but I need to get that project up and running ASAP, so i would really appreciate if you bare with me and give any hints that would fall out of the scope of the NDA to get me moving.

    As you may probably know, the code in NXP's SDK (the one available without NDA) does not provide any DESFIRE authentication examples. So, I have built my own code for that, which is inspired from the LibFreeFare.

    As very simple test to begin with, I am trying to authenticate key 0 (master key), with the key {00,00,00,00,00,00,00,00} on a blank mifare DesFire card.

    Here is the full authentication tractions, which leads at the end to an "AE" response, which i've come to understand it means "Authentication Error":

    NCI >> 00 00 02 1a 00
    NCI << 60 06 03 01 00 01
    NCI <> 00 00 11 af 8c a6 4d e9 c1 b1 23 a7 fe bf 9c 9d 25 a3 f6 4b
    NCI << 60 06 03 01 00 01
    NCI << 00 00 01 ae



    Questions:
    1- Is it right to try and authenticate a blank card, and is it supposed to work? I am wondering if the authentication error is normal since no authentication is needed?
    2- How can I know if i should use the command 0x0A, 0x1A or 0xAA to request RNDB ? They seem to represent different encryption algorithms, right? Is there a default command that should be safely used on a blank card?
    3- Is there a tool to which I can feed the number (RNDB) that can calculate the correct "RNDA+RNDB" that need to be sent back to device? I would like to at least know if it's just a cypher error or a protocol error?
    4- Does it seem crazy to anyone here to run such a project on a cortex M0 MCU? Just curious about your point of view.


    Thank you very much for any hints that can get me moving forward!
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    15. August 2018 at 22:08
    oops - now i know what the spoiler does! and I also know i can't edit the messages it seems..!
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 9:18
    I don't know why the authentication transaction below got truncated, here is the full listing:

    NCI >> 00 00 02 1a 00
    NCI << 60 06 03 01 00 01
    NCI <> 00 00 11 af 8c a6 4d e9 c1 b1 23 a7 fe bf 9c 9d 25 a3 f6 4b
    NCI << 60 06 03 01 00 01
    NCI << 00 00 01 ae
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 9:19
    And again it got truncated! let's see if changing the tag character helps:

    NCI --> 00 00 02 1a 00
    NCI <-- 60 06 03 01 00 01
    NCI 00 00 11 af 8c a6 4d e9 c1 b1 23 a7 fe bf 9c 9d 25 a3 f6 4b
    NCI <-- 60 06 03 01 00 01
    NCI <-- 00 00 01 ae

    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 9:21
    Still truncated (if an admin can delete all those messages, please, be my guest!)

    MCU -- 00 00 02 1a 00
    TAG -- 60 06 03 01 00 01
    TAG -- 00 00 09 af 57 d2 fc d6 a2 5f 4f 73
    MCU -- 00 00 11 af 8c a6 4d e9 c1 b1 23 a7 fe bf 9c 9d 25 a3 f6 4b
    TAG -- 60 06 03 01 00 01
    TAG -- 00 00 01 ae

    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 9:45
    Hi Ibrahim

    If you have access to DocStore, I highly recommend reading:

    AN 0945 - MIFARE DESFire EV1 – Features and Hints

    In this application note you will find calculated examples of authentication, change of keys, reading and writing encrypted data etc. It is required (in my point of view) to understand the secured communication.

    To your questions:
    1. Some DESFire commands need an authentication before, some do not. Please refer the native data sheet (available in DocStore).

    2. The commands 0x0A, 0x1A or 0xAA depends on the cipher used in your application. The default cipher for the PICC Master key is 2K3DES (0x0A). It is highly recommended to use AES in your applications and change the PICC Master Key also to AES and use true random values as keys (no series 01234… or FEDC… etc.).

    3. We offer the TapLinx SDK for Android programmers to encapsulate the cipher and the other stuff in methods for an easy usage. For your controller implementation you must implement the cipher by yourself, sorry.

    4. No. A lot of reader stations are implemented with Cortex M0 controllers. It could be an option to use a MIFARE SAM AV2 key store in your reader. The benefit is, the keys are NOT part of your software but reside secure in key store. On the other hand the SAM is able to handle the authentication to the DESFire autonomously (called X mode) or you can hand-over the authentication pricewise to the SAM (non-X mode).

    The TapLinx team



    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 9:49
    Hi!

    Thanks for those answers.

    Unfortunately, i still don't have access to the docstore.

    Any idea how much time it takes (in the middle of august!) to get some response from NXP? :)
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 10:00
    Okay! Thanks to your hints, i was able to concentrate on 2K3DS only, and now, i found a little bug in my cypher and fixed it.

    So, here is the sequence now:

    MCU: 00 00 02 0a 00
    TAG: 60 06 03 01 00 01
    TAG: 00 00 09 af a4 83 00 fb 5e 29 fd 78

    MCU: 00 00 11 af 8c a6 4d e9 c1 b1 23 a7 ed bf ce 53 48 6b 6d 00
    TAG: 60 06 03 01 00 01
    TAG: 00 00 09 00 8c a6 4d e9 c1 b1 23 a7


    As you can see, i no longer "AE" error code.

    Now, I am wondering, is it normal that desfire card replies this "00 8c a6 4d e9 c1 b1 23 a7" ? What does that "00" the beginning mean? I was expecting to get 0xAF, like the for the first answer from the tag..?

    Thanks!
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 10:38
    Hi Ibrahim

    I will ask about your DocStore access state internally. Do you have a legal business address? Unfortunately, hobby enthusiasts and students cannot sign a NDA with NXP.

    To investigate in “binary engineering” is notable! But you really need the above-mentioned AN to implement the methods for the MIFARE DESfire communication. Otherwise you will waste a lot of time.

    The TapLinx team

    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    16. August 2018 at 11:12
    my company, Ikalogic, have existed for almost 10 years now :)

    The company name is IKALOGIC, and our legal address is

    19 Rue Columbia
    87000
    Limoges, France

    Thanks for your help!


    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    17. August 2018 at 17:51
    France's sales rep. are still on vacation, so i am continuing to try and dig my way through this. (till we setup that NDA)

    As funny as it may seem, i was able to get like 90% of it working.

    I can authenticate.
    I can create an AID, and create a file in that AID.
    I can change access settings to make it readable only after authentication.

    So far, so good!

    No the very last bit i am trying to achieve is to encypher the data transfer. For instance, if i am trying to read "Hello World" from the DesFire card, i don't want this string to be "sniffable", if you see what i mean.

    So, In the libFreeFare (from which i am inspired) I fond a option to change communication mode from "PLAIN" (0x00) to "ENCIPHERED" (0x03). I did that, and indeed, now I can't read back the correct data, even with correct key.

    The problem i get is that I can't get a correct CRC from deciphered data.

    My question is more of a programming one: How can start searching for where the problem is? What is the best methodology to try to understand which part is broken?

    I've double checked my CRC algorithm, and it's the same i can find in various project on the web, so i don't suspect it's the problem.

    Thanks,
    + 0  |  - 0

    Re: Desfire Ev1 diverse questions

    20. August 2018 at 9:23
    Hi Ibrahim

    A lot of colleagues currently in vacation. So, it might be take some time until we are through with your access, sorry.

    Reading and writing in communication mode “fully encrypted” is not easy to implement. It is explained in detail in the application note, mentioned above. Unfortunately, I cannot explain it in detail here, in a public forum. I would break the NDA permissions. You should study the AN, when available.

    MIFARE uses a modified CRC16 for DES cipher and CRC32 for AES cipher. For AES you also need a AES-CMAC implementation. I would recommend completing your app in plain mode in the meantime and switch to encrypted mode, when the AN is available.

    The TapLinx team

    + 0  |  - 0
Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.