Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,12 @@ public void process(APDU apdu) {
processSetBootParamsCmd(apdu);
break;

case INS_SET_BOOT_ENDED_CMD:
//set the flag to mark boot ended
kmDataStore.setBootEndedStatus(true);
sendError(apdu, KMError.OK);
break;

case INS_PROVISION_RKP_DEVICE_UNIQUE_KEYPAIR_CMD:
processProvisionRkpDeviceUniqueKeyPair(apdu);
break;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -352,8 +352,12 @@ public static void add(byte[] buf, short op1, short op2, short result) {
byte index = 7;
byte carry = 0;
short tmp;
short val1 = 0;
short val2 = 0;
while (index >= 0) {
tmp = (short) (buf[(short) (op1 + index)] + buf[(short) (op2 + index)] + carry);
val1 = (short) (buf[(short) (op1 + index)] & 0x00FF);
val2 = (short) (buf[(short) (op2 + index)] & 0x00FF);
tmp = (short) (val1 + val2 + carry);
carry = 0;
if (tmp > 255) {
carry = 1; // max unsigned byte value is 255
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,6 +143,12 @@ public void process(APDU apdu) {
processSetBootParamsCmd(apdu);
break;

case INS_SET_BOOT_ENDED_CMD:
//set the flag to mark boot ended
kmDataStore.setBootEndedStatus(true);
sendError(apdu, KMError.OK);
break;

case INS_PROVISION_RKP_DEVICE_UNIQUE_KEYPAIR_CMD:
processProvisionRkpDeviceUniqueKeyPair(apdu);
break;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -352,8 +352,12 @@ public static void add(byte[] buf, short op1, short op2, short result) {
byte index = 7;
byte carry = 0;
short tmp;
short val1 = 0;
short val2 = 0;
while (index >= 0) {
tmp = (short) (buf[(short) (op1 + index)] + buf[(short) (op2 + index)] + carry);
val1 = (short) (buf[(short) (op1 + index)] & 0x00FF);
val2 = (short) (buf[(short) (op2 + index)] & 0x00FF);
tmp = (short) (val1 + val2 + carry);
carry = 0;
if (tmp > 255) {
carry = 1; // max unsigned byte value is 255
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -621,9 +621,9 @@ public short hmacSign(Object key, byte[] data, short dataStart, short dataLength
@Override
public boolean hmacVerify(KMComputedHmacKey key, byte[] data, short dataStart,
short dataLength, byte[] mac, short macStart, short macLength) {
KMHmacKey hmacKey = (KMHmacKey) key;
hmacSignature.init(hmacKey.getKey(), Signature.MODE_VERIFY);
return hmacSignature.verify(data, dataStart, dataLength, mac, macStart, macLength);
KMHmacKey hmacKey = (KMHmacKey) key;
hmacSignature.init(hmacKey.getKey(), Signature.MODE_VERIFY);
return hmacSignature.verify(data, dataStart, dataLength, mac, macStart, macLength);
}

@Override
Expand Down
69 changes: 5 additions & 64 deletions Applet/src/com/android/javacard/keymaster/KMKeyParameters.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,64 +235,6 @@ public static short makeSbEnforced(short keyParamsPtr, byte origin,
return createKeyParameters(scratchPad, (short) (arrInd / 2));
}

public static short makeSbEnforced(short keyParamsPtr, byte[] scratchPad) {
final short[] hwEnforcedTagArr = {
// HW Enforced
KMType.ENUM_TAG, KMType.ORIGIN,
KMType.UINT_TAG, KMType.OS_VERSION,
KMType.UINT_TAG, KMType.OS_PATCH_LEVEL,
KMType.UINT_TAG, KMType.VENDOR_PATCH_LEVEL,
KMType.UINT_TAG, KMType.BOOT_PATCH_LEVEL,
KMType.ENUM_ARRAY_TAG, KMType.PURPOSE,
KMType.ENUM_TAG, KMType.ALGORITHM,
KMType.UINT_TAG, KMType.KEYSIZE,
KMType.ULONG_TAG, KMType.RSA_PUBLIC_EXPONENT,
KMType.ENUM_TAG, KMType.BLOB_USAGE_REQ,
KMType.ENUM_ARRAY_TAG, KMType.DIGEST,
KMType.ENUM_ARRAY_TAG, KMType.PADDING,
KMType.ENUM_ARRAY_TAG, KMType.BLOCK_MODE,
KMType.ENUM_ARRAY_TAG, KMType.RSA_OAEP_MGF_DIGEST,
KMType.BOOL_TAG, KMType.NO_AUTH_REQUIRED,
KMType.BOOL_TAG, KMType.CALLER_NONCE,
KMType.UINT_TAG, KMType.MIN_MAC_LENGTH,
KMType.ENUM_TAG, KMType.ECCURVE,
KMType.BOOL_TAG, KMType.INCLUDE_UNIQUE_ID,
KMType.BOOL_TAG, KMType.ROLLBACK_RESISTANCE,
KMType.BOOL_TAG, KMType.UNLOCKED_DEVICE_REQUIRED,
KMType.BOOL_TAG, KMType.EARLY_BOOT_ONLY,
KMType.BOOL_TAG, KMType.BOOTLOADER_ONLY,
KMType.BOOL_TAG, KMType.TRUSTED_CONFIRMATION_REQUIRED,
};
byte index = 0;
short tagInd;
short arrInd = 0;
short tagPtr;
short tagKey;
short tagType;
short arrPtr = KMKeyParameters.cast(keyParamsPtr).getVals();
short len = KMArray.cast(arrPtr).length();
while (index < len) {
tagInd = 0;
tagPtr = KMArray.cast(arrPtr).get(index);
tagKey = KMTag.getKey(tagPtr);
tagType = KMTag.getTagType(tagPtr);
if (!isValidTag(tagType, tagKey)) {
KMException.throwIt(KMError.INVALID_KEY_BLOB);
}
while (tagInd < (short) hwEnforcedTagArr.length) {
if ((hwEnforcedTagArr[tagInd] == tagType)
&& (hwEnforcedTagArr[(short) (tagInd + 1)] == tagKey)) {
Util.setShort(scratchPad, arrInd, tagPtr);
arrInd += 2;
break;
}
tagInd += 2;
}
index++;
}
return createKeyParameters(scratchPad, (short) (arrInd / 2));
}

public static short makeHwEnforced(short sb, short tee){
short len = KMKeyParameters.cast(sb).length();
len += KMKeyParameters.cast(tee).length();
Expand DownExpand Up@@ -328,7 +270,8 @@ public static short makeKeystoreEnforced(short keyParamsPtr, byte[] scratchPad)
KMType.UINT_TAG, KMType.USERID,
KMType.DATE_TAG, KMType.CREATION_DATETIME,
KMType.UINT_TAG, KMType.USAGE_COUNT_LIMIT,
KMType.BOOL_TAG, KMType.ALLOW_WHILE_ON_BODY
KMType.BOOL_TAG, KMType.ALLOW_WHILE_ON_BODY,
KMType.UINT_TAG, KMType.MAX_BOOT_LEVEL,
};
byte index = 0;
short tagInd;
Expand DownExpand Up@@ -393,9 +336,6 @@ public static short makeTeeEnforced(short keyParamsPtr, byte[] scratchPad) {
}
index++;
}
// Add custom tags at the end of the array. So it becomes easy to
// delete them when sending key characteristics back to HAL.
arrInd = addCustomTags(keyParamsPtr, scratchPad, arrInd);
return createKeyParameters(scratchPad, (short) (arrInd / 2));
}

Expand DownExpand Up@@ -471,9 +411,10 @@ public static short createKeyParameters(byte[] ptrArr, short len) {
return KMKeyParameters.instance(arrPtr);
}

public static short addCustomTags(short keyParams, byte[] scratchPad, short offset) {
public static short makeCustomTags(short keyParams, byte[] scratchPad) {
short index = 0;
short tagPtr;
short offset = 0;
short len = (short) customTags.length;
short tagType;
while (index < len) {
Expand All@@ -493,7 +434,7 @@ public static short addCustomTags(short keyParams, byte[] scratchPad, short offs
}
index += 2;
}
return offset;
return createKeyParameters(scratchPad, (short) (offset / 2));
}

public void deleteCustomTags() {
Expand Down
Loading