Skip to content
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@@ -70,17 +70,17 @@ public static short convertToDate(short time, byte[] scratchPad,
(short) (8 - KMInteger.cast(time).length()), KMInteger.cast(time)
.length());
// If the time is less then 1 Jan 2020 then it is an error
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2020, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2020, (short) 0,
(short) 8) < 0) {
KMException.throwIt(KMError.INVALID_ARGUMENT);
}
if (utcFlag
&& KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2051,
&& unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2051,
(short) 0, (short) 8) >= 0) {
KMException.throwIt(KMError.INVALID_ARGUMENT);
}

if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2051, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, firstJan2051, (short) 0,
(short) 8) < 0) {
Util.arrayCopyNonAtomic(firstJan2020, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -96,7 +96,7 @@ public static short convertToDate(short time, byte[] scratchPad,
(short) 8);
}
// divide the given time with four yrs msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, fourYrsMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, fourYrsMsec, (short) 0,
(short) 8) >= 0) {
Util.arrayCopyNonAtomic(fourYrsMsec, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -116,9 +116,9 @@ public static short convertToDate(short time, byte[] scratchPad,
// if leap year index is 0, then the number of days for the 1st year will be 366 days.
// if leap year index is not 0, then the number of days for the 1st year will be 365 days.
if (((leapYrIdx == 0) &&
(KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, leapYearMsec, (short) 0,(short) 8) >= 0)) ||
(unsignedByteArrayCompare(scratchPad, (short) 0, leapYearMsec, (short) 0,(short) 8) >= 0)) ||
((leapYrIdx != 0) &&
(KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, yearMsec, (short) 0,(short) 8) >= 0))) {
(unsignedByteArrayCompare(scratchPad, (short) 0, yearMsec, (short) 0,(short) 8) >= 0))) {
for (short i = 0; i < 4; i++) {
yrsCount++;
if (i == leapYrIdx) {
Expand All@@ -132,12 +132,12 @@ public static short convertToDate(short time, byte[] scratchPad,
Util.arrayCopyNonAtomic(scratchPad, (short) 16, scratchPad, (short) 0,
(short) 8);
if (((short) (i + 1) == leapYrIdx)) {
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, leapYearMsec,
if (unsignedByteArrayCompare(scratchPad, (short) 0, leapYearMsec,
(short) 0, (short) 8) < 0) {
break;
}
} else {
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, yearMsec,
if (unsignedByteArrayCompare(scratchPad, (short) 0, yearMsec,
(short) 0, (short) 8) < 0) {
break;
}
Expand All@@ -152,7 +152,7 @@ public static short convertToDate(short time, byte[] scratchPad,
yrsCount = (short) (year2051 + yrsCount);

// divide the given time with one month msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, oneMonthMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, oneMonthMsec, (short) 0,
(short) 8) >= 0) {
for (short i = 0; i < 12; i++) {
if (i == 1) {
Expand All@@ -175,7 +175,7 @@ public static short convertToDate(short time, byte[] scratchPad,
(short) 8, (short) 8);
}

if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, scratchPad, (short) 8,
if (unsignedByteArrayCompare(scratchPad, (short) 0, scratchPad, (short) 8,
(short) 8) >= 0) {
subtract(scratchPad, (short) 0, (short) 8, (short) 16);
Util.arrayCopyNonAtomic(scratchPad, (short) 16, scratchPad, (short) 0,
Expand All@@ -188,7 +188,7 @@ public static short convertToDate(short time, byte[] scratchPad,
}

// divide the given time with one day msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, oneDayMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, oneDayMsec, (short) 0,
(short) 8) >= 0) {
Util.arrayCopyNonAtomic(oneDayMsec, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -199,7 +199,7 @@ public static short convertToDate(short time, byte[] scratchPad,
}

// divide the given time with one hour msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, oneHourMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, oneHourMsec, (short) 0,
(short) 8) >= 0) {
Util.arrayCopyNonAtomic(oneHourMsec, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -209,7 +209,7 @@ public static short convertToDate(short time, byte[] scratchPad,
}

// divide the given time with one minute msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, oneMinMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, oneMinMsec, (short) 0,
(short) 8) >= 0) {
Util.arrayCopyNonAtomic(oneMinMsec, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -219,7 +219,7 @@ public static short convertToDate(short time, byte[] scratchPad,
}

// divide the given time with one second msec count
if (KMInteger.unsignedByteArrayCompare(scratchPad, (short) 0, oneSecMsec, (short) 0,
if (unsignedByteArrayCompare(scratchPad, (short) 0, oneSecMsec, (short) 0,
(short) 8) >= 0) {
Util.arrayCopyNonAtomic(oneSecMsec, (short) 0, scratchPad, (short) 8,
(short) 8);
Expand All@@ -244,7 +244,24 @@ public static short convertToDate(short time, byte[] scratchPad,
return KMByteBlob.instance(scratchPad, (short) 0, len); // YYYY
}

public static byte unsignedByteArrayCompare(byte[] a1, short offset1, byte[] a2, short offset2, short length) {
byte count = (byte) 0;
short val1 = (short)0;
short val2 = (short)0;

for (; count < length; count++) {
val1 = (short) (a1[(short) (count + offset1)] & 0x00FF);
val2 = (short) (a2[(short) (count + offset2)] & 0x00FF);

if (val1 < val2) {
return -1;
}
if (val1 > val2) {
return 1;
}
}
return 0;
}

public static short numberToString(short number, byte[] scratchPad,
short offset) {
Expand DownExpand Up@@ -294,7 +311,7 @@ public static void copy(byte[] buf, short from, short to) {
}

public static byte compare(byte[] buf, short lhs, short rhs) {
return KMInteger.unsignedByteArrayCompare(buf, lhs, buf, rhs, (short) 8);
return unsignedByteArrayCompare(buf, lhs, buf, rhs, (short) 8);
}

public static void shiftLeft(byte[] buf, short start) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,6 +90,7 @@ public class KMAttestationCertImpl implements KMAttestationCert {
private static byte[] stack;
private static short start;
private static short length;
// private static KMRepository repo;
private static short uniqueId;
private static short attChallenge;
private static short notBefore;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,11 +24,19 @@ public abstract class KMCipher {

public abstract void updateAAD(byte[] buffer, short startOff, short length);

public abstract short getBlockMode();

public abstract void setBlockMode(short mode);

public abstract short getPaddingAlgorithm();

public abstract short getCipherAlgorithm();

public abstract void setPaddingAlgorithm(short alg);

public abstract void setCipherAlgorithm(short alg);

public abstract short getCipherProvider();

public abstract short getAesGcmOutputSize(short len, short macLength);
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,12 +85,18 @@ public KMEcdsa256NoDigestSignature(byte mode, byte[] key, short keyStart, short
ECPublicKey pubkey = (ECPublicKey) kf.generatePublic(pubkeyspec);
sunSigner.initVerify(pubkey);
}
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
} catch (NoSuchAlgorithmException e) {
CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM);
} catch(InvalidParameterSpecException | InvalidKeySpecException | InvalidKeyException e) {
} catch (NoSuchProviderException e) {
CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM);
} catch(InvalidParameterSpecException e) {
CryptoException.throwIt(CryptoException.INVALID_INIT);
} catch(InvalidKeySpecException e) {
CryptoException.throwIt(CryptoException.INVALID_INIT);
} catch(InvalidKeyException e) {
CryptoException.throwIt(CryptoException.INVALID_INIT);
}
}
}

@Override
public void init(Key key, byte b) throws CryptoException {
Expand Down
Loading