none
Mifare desfire 91 1E error with C#

    Question

  • Hi all,

    I'm new with desfire and I'm sorry if it's not the good forum. I can authenticate me without any problem. But, I have a 0x1E error with ChangeKey command (and the same error with change key settings command).

    Here is what I do in detail :

    MASTER KEY = 00 00 00 00 00 00 00 00
    INIT VECTOR = 00 00 00 00 00 00 00 00

    Authenticate : (with key number 0x00)

    --> 90 0A 00 00 01 00 00
    <-- 91 AF 57 B0 C3 5A 08 0A E6 08

    RndB = D6 F7 79 68 D2 76 7E A3
    RndB' = F7 79 68 D2 76 7E A3 D6

    Generated RndA = B0 A6 40 5F 57 79 4A 93

    After cipher operations :

    --> 90 AF 00 00 10 5B D8 9F 65 31 76 AE 3A 7A 11 28 C9 D4 03 51 29 00
    <-- 90 00 B5 3B F4 99 FE AC 13 E4

    After cipher operations :
    Received datas = A6 40 5F 57 79 4A 93 B0

    Session key : B0 A6 40 5F D6 F7 79 68

    AUTHENTICATION OK!

    After this I try to send the change key settings command (for example) :

    New setting value : 0F

    CRC = 70 F7

    After cipher operations :

    --> 90 54 00 00 08 C5 E6 52 C9 D6 D0 F4 39 00
    <-- 91 1E

    I think the problem is my CRC or my session key but I don't known what is wrong in my procedure.


    In addition, here is my crc calulation code (in C#) :

    public static byte[] ComputeCrc16(byte[] data, int len)
    {
        ushort polynomial = 0x8408;
        ushort preset = 0xFFFF;
    
        int i, j;
        int current_crc_value = preset;
    
        for (i = 0; i < len; i++)
        {
            current_crc_value = current_crc_value ^ data[i];
    
            for (j = 0; j < 8; j++)
            {
                if ((current_crc_value & 0x0001) != 0)
                {
                    current_crc_value = (current_crc_value >> 1) ^ polynomial;
                }
                else
                {
                    current_crc_value = (current_crc_value >> 1);
                }
            }
        }
    
        data[i++] = (byte)(current_crc_value & 0x00ff);
        data[i] = (byte)((current_crc_value >> 8) & 0x00ff);
    
        return data;
    }


    • Moved by litdev Monday, August 03, 2015 6:35 PM
    Monday, August 03, 2015 4:07 PM

Answers

All replies

  • Hello,

    I'd ask mifare:

    https://www.mifare.net/en/support/micommunity/

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Monday, August 03, 2015 7:39 PM
    Moderator
  • Thanks Karl, but I have posted this topic in this forum because it's possible that the problem is known by another .net developer.
    Tuesday, August 04, 2015 7:16 AM
  • Thanks Karl, but I have posted this topic in this forum because it's possible that the problem is known by another .net developer.

    You've posted this question in the 'Where is the Forum For...?' forum, where we direct people to the appropriate forum to post in.

    You likely will not get any real help here.


    Tuesday, August 04, 2015 12:18 PM
  • Okay, Mike, I'm sorry.

    My post isn't in the good forum... For any people who has the same problem, the error is in my CRC algorithm. The preset value has to be 0x6363.

    Tuesday, August 04, 2015 3:19 PM
  • Okay, Mike, I'm sorry.

    My post isn't in the good forum... For any people who has the same problem, the error is in my CRC algorithm. The preset value has to be 0x6363.

    No worries, I just wanted to make sure you knew where this post had actually landed. The forum structure here can sometimes be a bit confusing.

    Glad to hear that you found a solution.


    Tuesday, August 04, 2015 3:20 PM