Skip to content

SHORT Cmac calculation #15

Description

@xam8re

HI.
I set all keys as default as this:
`
public KeySet getKeySet() {
KeySet keySet = new KeySet();
keySet.setUsesLrp(false);

    // This is the "master" key
    KeyInfo key0 = new KeyInfo();
    key0.diversifyKeys = false;
    key0.key = Ntag424.FACTORY_KEY;
    keySet.setKey(Permissions.ACCESS_KEY0, key0);

    // No standard usage
    KeyInfo key1 = new KeyInfo();
    key1.diversifyKeys = false;
    key1.key = Ntag424.FACTORY_KEY;
    keySet.setKey(Permissions.ACCESS_KEY1, key1);

    // Usually used as a meta read key for encrypted PICC data
    KeyInfo key2 = new KeyInfo();
    key2.diversifyKeys = false;
    key2.key = Ntag424.FACTORY_KEY;
    keySet.setKey(Permissions.ACCESS_KEY2, key2);

    // Usually used as the MAC and encryption key.
    // The MAC key usually has the diversification information setup.
    // KeyInfo key3 = new KeyInfo();
    // key3.diversifyKeys = false;
    // key3.systemIdentifier = "testing".getBytes(StandardCharsets.UTF_8); // systemIdentifier is usually a hex-encoded string based on the name of your intended use.
    // key3.version = 1; // Since it is not a factory key (it is *based* on a factory key, but underwent diversification), need to set to a version number other than 0.
    // key3.key = Ntag424.FACTORY_KEY;

    KeyInfo key3 = new KeyInfo();
    key3.diversifyKeys = false;
    key3.key = Ntag424.FACTORY_KEY;
    keySet.setKey(Permissions.ACCESS_KEY3, key3);

    // No standard usage
    // keySet.setKey(Permissions.ACCESS_KEY3, key3);
    KeyInfo key4 = new KeyInfo();
    key4.diversifyKeys = false;
    key4.key = Ntag424.FACTORY_KEY;
    keySet.setKey(Permissions.ACCESS_KEY4, key4);

    // This is used for decoding, but documenting that key2/key3 are standard for meta and mac
    keySet.setMetaKey(Permissions.ACCESS_KEY2);
    keySet.setMacFileKey(Permissions.ACCESS_KEY3);

    return keySet;
}

`

Link created is :
https://sdm.nfcdeveloper.com/tagpt?uid=04176AC20A1090&ctr=00006B&cmac=788E828B11B3627E

testing the cmac:
byte[] key = Ntag424.FACTORY_KEY; byte[] uid = ByteUtil.hexToByte("04176AC20A1090"); ctr = 0x6B; PiccData picc = new PiccData(uid, ctr, false); picc.setMacFileKey(key); byte[] calc = picc.performShortCMAC(key); // MAC on PICC-only data

give me a different cmac. Where I'm wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions