This discussion is archived
2 Replies Latest reply: Nov 19, 2012 12:14 PM by 974744 RSS

How to calculate C-MAC  with single DES plus final 3DES?

974744 Newbie
Currently Being Moderated
Hi,

I want to implemante SCP02 i=15, mys problem is how to calculate the c-mac for 2nd command because i calculate the c-mac for the external authenticate command and it works, but when i calculate the c-mac for the next command ( STORE DATA) with the same algorithm it doesn't work.

i think it's problem of ivParamterSpec for the CBC Mode.

I hope that my problem is clair and sorry for my english.

Many Thanks
  • 1. Re: How to calculate C-MAC  with single DES plus final 3DES?
    safarmer Expert
    Currently Being Moderated
    Hi,

    There have been recent posts (last week) with similar problems. The answers given there may help. My first guess is that you are using 0000000000000000 as the ICV? The second guess is that the ICV encryption does not match what your card expects (depending on the i value of your SCP may or may not have an encrypted ICV). You may also be using the MAC from EXT-AUTH as the ICV for your first command which you don't do.

    - Shane
  • 2. Re: How to calculate C-MAC  with single DES plus final 3DES?
    974744 Newbie
    Currently Being Moderated
    Hi Shane,

    I resolved it, i used the a wrong icv,
    the correct icv for DESede encryption of the last block is the result of the DES encryption of the n-1 block.

    there's the code,
                     IvParameterSpec ivSpec = new IvParameterSpec(icv);
                     int bloc = data.length / 8;
              SecretKeySpec deskey = new SecretKeySpec(key,0, 8,"DES");
              for (int i = 0; i < blocks - 1; i++) {
                  desCipher.init(Cipher.ENCRYPT_MODE, deskey, ivSpec);
                  byte[] block = desCipher.doFinal(data, i * 8, 8);
                  ivSpec = new IvParameterSpec(block);
    }          
               
              int offset = (bloc - 1) * 8;
              
              SecretKeySpec sessionCMAC = new SecretKeySpec(key, "DESede");
              desedeCBCCipher.init(Cipher.ENCRYPT_MODE, sessionCMAC, ivSpec);
              
              cmac = desedeCBCCipher.doFinal(data, offset, 8);
               System.out.println(Outil.toHex(mac));
              
    The Initial ICV= "0000000000000000"

    Edited by: 971741 on 19 nov. 2012 12:09

    Edited by: 971741 on 19 nov. 2012 12:10

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points