Merge "Track rename of INT and LONG Keymaster tag types." into mnc-dev

This commit is contained in:
Alex Klyubin
2015-06-25 15:06:47 +00:00
committed by Android (Google) Code Review
5 changed files with 28 additions and 28 deletions

View File

@@ -39,11 +39,11 @@ abstract class KeymasterArgument implements Parcelable {
switch (KeymasterDefs.getTagType(tag)) {
case KeymasterDefs.KM_ENUM:
case KeymasterDefs.KM_ENUM_REP:
case KeymasterDefs.KM_INT:
case KeymasterDefs.KM_INT_REP:
case KeymasterDefs.KM_UINT:
case KeymasterDefs.KM_UINT_REP:
return new KeymasterIntArgument(tag, in);
case KeymasterDefs.KM_LONG:
case KeymasterDefs.KM_LONG_REP:
case KeymasterDefs.KM_ULONG:
case KeymasterDefs.KM_ULONG_REP:
return new KeymasterLongArgument(tag, in);
case KeymasterDefs.KM_DATE:
return new KeymasterDateArgument(tag, in);

View File

@@ -139,10 +139,10 @@ public class KeymasterArguments implements Parcelable {
*/
public void addUnsignedInt(int tag, long value) {
int tagType = KeymasterDefs.getTagType(tag);
if ((tagType != KeymasterDefs.KM_INT) && (tagType != KeymasterDefs.KM_INT_REP)) {
if ((tagType != KeymasterDefs.KM_UINT) && (tagType != KeymasterDefs.KM_UINT_REP)) {
throw new IllegalArgumentException("Not an int or repeating int tag: " + tag);
}
// Keymaster's KM_INT is unsigned 32 bit.
// Keymaster's KM_UINT is unsigned 32 bit.
if ((value < 0) || (value > UINT32_MAX_VALUE)) {
throw new IllegalArgumentException("Int tag value out of range: " + value);
}
@@ -156,14 +156,14 @@ public class KeymasterArguments implements Parcelable {
* @throws IllegalArgumentException if {@code tag} is not an unsigned 32-bit int tag.
*/
public long getUnsignedInt(int tag, long defaultValue) {
if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_INT) {
if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_UINT) {
throw new IllegalArgumentException("Not an int tag: " + tag);
}
KeymasterArgument arg = getArgumentByTag(tag);
if (arg == null) {
return defaultValue;
}
// Keymaster's KM_INT is unsigned 32 bit.
// Keymaster's KM_UINT is unsigned 32 bit.
return ((KeymasterIntArgument) arg).value & 0xffffffffL;
}
@@ -175,7 +175,7 @@ public class KeymasterArguments implements Parcelable {
*/
public void addUnsignedLong(int tag, BigInteger value) {
int tagType = KeymasterDefs.getTagType(tag);
if ((tagType != KeymasterDefs.KM_LONG) && (tagType != KeymasterDefs.KM_LONG_REP)) {
if ((tagType != KeymasterDefs.KM_ULONG) && (tagType != KeymasterDefs.KM_ULONG_REP)) {
throw new IllegalArgumentException("Not a long or repeating long tag: " + tag);
}
addLongTag(tag, value);
@@ -187,7 +187,7 @@ public class KeymasterArguments implements Parcelable {
* @throws IllegalArgumentException if {@code tag} is not a repeating unsigned 64-bit long tag.
*/
public List<BigInteger> getUnsignedLongs(int tag) {
if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_LONG_REP) {
if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_ULONG_REP) {
throw new IllegalArgumentException("Tag is not a repeating long: " + tag);
}
List<BigInteger> values = new ArrayList<BigInteger>();
@@ -200,7 +200,7 @@ public class KeymasterArguments implements Parcelable {
}
private void addLongTag(int tag, BigInteger value) {
// Keymaster's KM_LONG is unsigned 64 bit.
// Keymaster's KM_ULONG is unsigned 64 bit.
if ((value.signum() == -1) || (value.compareTo(UINT64_MAX_VALUE) > 0)) {
throw new IllegalArgumentException("Long tag value out of range: " + value);
}
@@ -208,7 +208,7 @@ public class KeymasterArguments implements Parcelable {
}
private BigInteger getLongTagValue(KeymasterArgument arg) {
// Keymaster's KM_LONG is unsigned 64 bit. We're forced to use BigInteger for type safety
// Keymaster's KM_ULONG is unsigned 64 bit. We're forced to use BigInteger for type safety
// because there's no unsigned long type.
return toUint64(((KeymasterLongArgument) arg).value);
}

View File

@@ -33,20 +33,20 @@ public final class KeymasterDefs {
public static final int KM_INVALID = 0 << 28;
public static final int KM_ENUM = 1 << 28;
public static final int KM_ENUM_REP = 2 << 28;
public static final int KM_INT = 3 << 28;
public static final int KM_INT_REP = 4 << 28;
public static final int KM_LONG = 5 << 28;
public static final int KM_UINT = 3 << 28;
public static final int KM_UINT_REP = 4 << 28;
public static final int KM_ULONG = 5 << 28;
public static final int KM_DATE = 6 << 28;
public static final int KM_BOOL = 7 << 28;
public static final int KM_BIGNUM = 8 << 28;
public static final int KM_BYTES = 9 << 28;
public static final int KM_LONG_REP = 10 << 28;
public static final int KM_ULONG_REP = 10 << 28;
// Tag values.
public static final int KM_TAG_INVALID = KM_INVALID | 0;
public static final int KM_TAG_PURPOSE = KM_ENUM_REP | 1;
public static final int KM_TAG_ALGORITHM = KM_ENUM | 2;
public static final int KM_TAG_KEY_SIZE = KM_INT | 3;
public static final int KM_TAG_KEY_SIZE = KM_UINT | 3;
public static final int KM_TAG_BLOCK_MODE = KM_ENUM_REP | 4;
public static final int KM_TAG_DIGEST = KM_ENUM_REP | 5;
public static final int KM_TAG_PADDING = KM_ENUM_REP | 6;
@@ -56,19 +56,19 @@ public final class KeymasterDefs {
public static final int KM_TAG_RESCOPING_DEL = KM_ENUM_REP | 102;
public static final int KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 705;
public static final int KM_TAG_RSA_PUBLIC_EXPONENT = KM_LONG | 200;
public static final int KM_TAG_RSA_PUBLIC_EXPONENT = KM_ULONG | 200;
public static final int KM_TAG_ACTIVE_DATETIME = KM_DATE | 400;
public static final int KM_TAG_ORIGINATION_EXPIRE_DATETIME = KM_DATE | 401;
public static final int KM_TAG_USAGE_EXPIRE_DATETIME = KM_DATE | 402;
public static final int KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_INT | 403;
public static final int KM_TAG_MAX_USES_PER_BOOT = KM_INT | 404;
public static final int KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_UINT | 403;
public static final int KM_TAG_MAX_USES_PER_BOOT = KM_UINT | 404;
public static final int KM_TAG_ALL_USERS = KM_BOOL | 500;
public static final int KM_TAG_USER_ID = KM_INT | 501;
public static final int KM_TAG_USER_SECURE_ID = KM_LONG_REP | 502;
public static final int KM_TAG_USER_ID = KM_UINT | 501;
public static final int KM_TAG_USER_SECURE_ID = KM_ULONG_REP | 502;
public static final int KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 503;
public static final int KM_TAG_USER_AUTH_TYPE = KM_ENUM | 504;
public static final int KM_TAG_AUTH_TIMEOUT = KM_INT | 505;
public static final int KM_TAG_AUTH_TIMEOUT = KM_UINT | 505;
public static final int KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600;
public static final int KM_TAG_APPLICATION_ID = KM_BYTES | 601;
@@ -82,7 +82,7 @@ public final class KeymasterDefs {
public static final int KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000;
public static final int KM_TAG_NONCE = KM_BYTES | 1001;
public static final int KM_TAG_AUTH_TOKEN = KM_BYTES | 1002;
public static final int KM_TAG_MAC_LENGTH = KM_INT | 1003;
public static final int KM_TAG_MAC_LENGTH = KM_UINT | 1003;
// Algorithm values.
public static final int KM_ALGORITHM_RSA = 1;

View File

@@ -27,8 +27,8 @@ class KeymasterIntArgument extends KeymasterArgument {
public KeymasterIntArgument(int tag, int value) {
super(tag);
switch (KeymasterDefs.getTagType(tag)) {
case KeymasterDefs.KM_INT:
case KeymasterDefs.KM_INT_REP:
case KeymasterDefs.KM_UINT:
case KeymasterDefs.KM_UINT_REP:
case KeymasterDefs.KM_ENUM:
case KeymasterDefs.KM_ENUM_REP:
break; // OK.

View File

@@ -27,8 +27,8 @@ class KeymasterLongArgument extends KeymasterArgument {
public KeymasterLongArgument(int tag, long value) {
super(tag);
switch (KeymasterDefs.getTagType(tag)) {
case KeymasterDefs.KM_LONG:
case KeymasterDefs.KM_LONG_REP:
case KeymasterDefs.KM_ULONG:
case KeymasterDefs.KM_ULONG_REP:
break; // OK.
default:
throw new IllegalArgumentException("Bad long tag " + tag);