<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Integrity Error on ChangeKey desfire ev3 in Other NXP Products</title>
    <link>https://community.nxp.com/t5/Other-NXP-Products/Integrity-Error-on-ChangeKey-desfire-ev3/m-p/1864587#M22594</link>
    <description>&lt;P&gt;Hi, I'm trying to change default aes key on keyNo = 0, to a different aes key. However, I keep getting&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;0x1E integrity error on sending the command, which i think indicates wrong crc.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I wrote in javascript. This is my crc32 calculation function&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;static crc32 = (input) =&amp;gt; {
        const crcTable = new Array(256);
        for (let i = 0; i &amp;lt; 256; i++) {
          let c = i;
          for (let j = 0; j &amp;lt; 8; j++) {
            c = ((c &amp;amp; 1) ? (0xEDB88320 ^ (c &amp;gt;&amp;gt;&amp;gt; 1)) : (c &amp;gt;&amp;gt;&amp;gt; 1));
          }
          crcTable[i] = c &amp;gt;&amp;gt;&amp;gt; 0;
        }
      
        let crc = 0 ^ (-1);
      
        for (let i = 0; i &amp;lt; input.length; i++) {
          crc = (crc &amp;gt;&amp;gt;&amp;gt; &lt;LI-EMOJI id="lia_smiling-face-with-sunglasses" title=":smiling_face_with_sunglasses:"&gt;&lt;/LI-EMOJI&gt; ^ crcTable[(crc ^ input.charCodeAt(i)) &amp;amp; 0xFF];
        }
      
        crc = crc ^ (-1);  
        // Convert the integer to an array of bytes  
        const crcBytes = [];  for (let i = 0; i &amp;lt; 4; i++) { 
            crcBytes.push((crc &amp;gt;&amp;gt;&amp;gt; (i * 8)) &amp;amp; 0xFF);  
        }  
        
        return crcBytes.reverse();
    }​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;From my understanding, CRC is calculated on Cmd + keyNo + (newKey xor oldkey) + keyversion. Something like this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let data_to_crc = cmd.concat(_keyNo).concat(_newKey).concat(_keyVersion);
let data_to_crc_string = DesfireUtils.getHexFromDecArray(data_to_crc);
let crc_data = DesfireUtils.crc32(data_to_crc_string);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;If I run my crc32 function on the data, i'd get the same result when using&amp;nbsp;&lt;A href="https://crccalc.com/" target="_self"&gt;this online crc32 calculator&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Then cryptogram = newkey + keyversion + crc_data + padding&lt;/DIV&gt;&lt;DIV&gt;Then i send over &amp;lt;C4 00 Cryptogram&amp;gt;&lt;BR /&gt;Sending over encrypted cryptogram yields same result as not encrypted, 0x1E. encryption key is session key, iv = 0&lt;/DIV&gt;</description>
    <pubDate>Mon, 13 May 2024 15:39:36 GMT</pubDate>
    <dc:creator>amrin-hexondata</dc:creator>
    <dc:date>2024-05-13T15:39:36Z</dc:date>
    <item>
      <title>Integrity Error on ChangeKey desfire ev3</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/Integrity-Error-on-ChangeKey-desfire-ev3/m-p/1864587#M22594</link>
      <description>&lt;P&gt;Hi, I'm trying to change default aes key on keyNo = 0, to a different aes key. However, I keep getting&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;0x1E integrity error on sending the command, which i think indicates wrong crc.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I wrote in javascript. This is my crc32 calculation function&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;static crc32 = (input) =&amp;gt; {
        const crcTable = new Array(256);
        for (let i = 0; i &amp;lt; 256; i++) {
          let c = i;
          for (let j = 0; j &amp;lt; 8; j++) {
            c = ((c &amp;amp; 1) ? (0xEDB88320 ^ (c &amp;gt;&amp;gt;&amp;gt; 1)) : (c &amp;gt;&amp;gt;&amp;gt; 1));
          }
          crcTable[i] = c &amp;gt;&amp;gt;&amp;gt; 0;
        }
      
        let crc = 0 ^ (-1);
      
        for (let i = 0; i &amp;lt; input.length; i++) {
          crc = (crc &amp;gt;&amp;gt;&amp;gt; &lt;LI-EMOJI id="lia_smiling-face-with-sunglasses" title=":smiling_face_with_sunglasses:"&gt;&lt;/LI-EMOJI&gt; ^ crcTable[(crc ^ input.charCodeAt(i)) &amp;amp; 0xFF];
        }
      
        crc = crc ^ (-1);  
        // Convert the integer to an array of bytes  
        const crcBytes = [];  for (let i = 0; i &amp;lt; 4; i++) { 
            crcBytes.push((crc &amp;gt;&amp;gt;&amp;gt; (i * 8)) &amp;amp; 0xFF);  
        }  
        
        return crcBytes.reverse();
    }​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;From my understanding, CRC is calculated on Cmd + keyNo + (newKey xor oldkey) + keyversion. Something like this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let data_to_crc = cmd.concat(_keyNo).concat(_newKey).concat(_keyVersion);
let data_to_crc_string = DesfireUtils.getHexFromDecArray(data_to_crc);
let crc_data = DesfireUtils.crc32(data_to_crc_string);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;If I run my crc32 function on the data, i'd get the same result when using&amp;nbsp;&lt;A href="https://crccalc.com/" target="_self"&gt;this online crc32 calculator&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Then cryptogram = newkey + keyversion + crc_data + padding&lt;/DIV&gt;&lt;DIV&gt;Then i send over &amp;lt;C4 00 Cryptogram&amp;gt;&lt;BR /&gt;Sending over encrypted cryptogram yields same result as not encrypted, 0x1E. encryption key is session key, iv = 0&lt;/DIV&gt;</description>
      <pubDate>Mon, 13 May 2024 15:39:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/Integrity-Error-on-ChangeKey-desfire-ev3/m-p/1864587#M22594</guid>
      <dc:creator>amrin-hexondata</dc:creator>
      <dc:date>2024-05-13T15:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Integrity Error on ChangeKey desfire ev3</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/Integrity-Error-on-ChangeKey-desfire-ev3/m-p/1864913#M22603</link>
      <description>Fixed the issue. The problem lies in CRC32 algorithm.&lt;BR /&gt;I used this C code and transcribed / implement it in javascript&lt;BR /&gt;&lt;A href="http://www.rfidiot.org/crc32.c" target="_blank"&gt;http://www.rfidiot.org/crc32.c&lt;/A&gt;</description>
      <pubDate>Tue, 14 May 2024 03:56:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/Integrity-Error-on-ChangeKey-desfire-ev3/m-p/1864913#M22603</guid>
      <dc:creator>amrin-hexondata</dc:creator>
      <dc:date>2024-05-14T03:56:44Z</dc:date>
    </item>
  </channel>
</rss>

