Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SCP03 - KDF in counter mode

jspartan0901Nov 19 2013 — edited Dec 11 2013

Hello,

I am currently implementing SCP03 for a TSM functionality and using BouncyCastle's aescmac implementation for CMAC.

When deriving the card challenge, keys etc., Amendment D says the fields in derivation data can be re-ordered as long as the order, coding and length of each field is unambiguously defined.

Can someone help me understand how do we establish an order so that it matches with what the chip/card generates?

Here's the sample code which I use to generate card challenge. Am I correct in my implementation? Am I missing something? Any help is greatly appreciated.

  private byte[] deriveCardChallenge(byte[] key, int sequenceCounter) {

      try {

        String label = "0000000000000000000000";

        String constant = "02";

        String separationIndicator = "00";

        String LInteger = "0040";

        String counter = "01";

        byte[] sequenceBytes = getSequenceBytes(sequenceCounter);

        String context = Utils.byteArrayToHex(sequenceBytes) + Utils.byteArrayToHex(AID);

        String derivationText = counter + label + constant + separationIndicator + context + LInteger;

        byte[] derivationData = Utils.hexToByteArray(derivationText);

       

        Mac mac = Mac.getInstance("aescmac", PROVIDER);

        SecretKey macKey = new SecretKeySpec(key, "AES");

        mac.init(macKey);

        mac.update(derivationData);

        byte[] macFull = mac.doFinal();

        byte[] cardChallenge = new byte[8];

        System.arraycopy(macFull, 0, cardChallenge, 0, 8);

        return cardChallenge;

      } catch(Exception e){

          e.printStackTrace();

      }

      return null;

  }

Thanks!

Sam

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2014
Added on Nov 19 2013
2 comments
2,742 views