本文整理汇总了Java中javacard.framework.Util.arrayCompare方法的典型用法代码示例。如果您正苦于以下问题:Java Util.arrayCompare方法的具体用法?Java Util.arrayCompare怎么用?Java Util.arrayCompare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.Util
的用法示例。
在下文中一共展示了Util.arrayCompare方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isEqual
import javacard.framework.Util; //导入方法依赖的package包/类
/**
* Compares this and provided point for equality. The comparison is made using hash of both values to prevent leak of position of mismatching byte.
* @param other second point for comparison
* @return true if both point are exactly equal (same length, same value), false otherwise
*/
public boolean isEqual(ECPoint other) {
boolean bResult = false;
if (this.length() != other.length()) {
return false;
}
else {
// The comparison is made with hash of point values instead of directly values.
// This way, offset of first mismatching byte is not leaked via timing side-channel.
// Additionally, only single array is required for storage of plain point values thus saving some RAM.
ech.lock(ech.uncompressed_point_arr1);
ech.lock(ech.fnc_isEqual_hashArray);
//ech.lock(ech.fnc_isEqual_hashEngine);
short len = this.getW(ech.uncompressed_point_arr1, (short) 0);
ech.fnc_isEqual_hashEngine.doFinal(ech.uncompressed_point_arr1, (short) 0, len, ech.fnc_isEqual_hashArray, (short) 0);
len = other.getW(ech.uncompressed_point_arr1, (short) 0);
len = ech.fnc_isEqual_hashEngine.doFinal(ech.uncompressed_point_arr1, (short) 0, len, ech.uncompressed_point_arr1, (short) 0);
bResult = Util.arrayCompare(ech.fnc_isEqual_hashArray, (short) 0, ech.uncompressed_point_arr1, (short) 0, len) == 0;
//ech.unlock(ech.fnc_isEqual_hashEngine);
ech.unlock(ech.fnc_isEqual_hashArray);
ech.unlock(ech.uncompressed_point_arr1);
}
return bResult;
}
示例2: unwrap
import javacard.framework.Util; //导入方法依赖的package包/类
public boolean unwrap(byte[] keyHandle, short keyHandleOffset, short keyHandleLength, byte[] applicationParameter, short applicationParameterOffset, ECPrivateKey unwrappedPrivateKey) {
calcMAC(applicationParameter, applicationParameterOffset, keyHandle, keyHandleOffset);
//Compare MAC
if (Util.arrayCompare(scratch, (short) 0, keyHandle, (short)(keyHandleOffset+32), (short)32)!=0) {
return false;
}
//only get key if signing is required
if (unwrappedPrivateKey != null) {
//Regenerate PrivKey
generatePrivateKey(applicationParameter, applicationParameterOffset, keyHandle, keyHandleOffset);
unwrappedPrivateKey.setS(scratch, (short)0, (short)32);
}
Util.arrayFillNonAtomic(scratch, (short)0, (short)32, (byte)0x00);
return true;
}
示例3: isEqual
import javacard.framework.Util; //导入方法依赖的package包/类
/**
* Compares this and provided point for equality. The comparison is made using hash of both values to prevent leak of position of mismatching byte.
* @param other second point for comparison
* @return true if both point are exactly equal (same length, same value), false otherwise
*/
public boolean isEqual(ECPoint other) {
boolean bResult = false;
if (this.length() != other.length()) {
return false;
}
else {
// The comparison is made with hash of point values instead of directly values.
// This way, offset of first mismatching byte is not leaked via timing side-channel.
// Additionally, only single array is required for storage of plain point values thus saving some RAM.
ech.lock(ech.uncompressed_point_arr1);
ech.lock(ech.fnc_isEqual_hashArray);
//ech.lock(ech.fnc_isEqual_hashEngine);
short len = this.getW(ech.uncompressed_point_arr1, (short) 0);
ech.fnc_isEqual_hashEngine.doFinal(ech.uncompressed_point_arr1, (short) 0, len, ech.fnc_isEqual_hashArray, (short) 0);
len = other.getW(ech.uncompressed_point_arr1, (short) 0);
len = ech.fnc_isEqual_hashEngine.doFinal(ech.uncompressed_point_arr1, (short) 0, len, ech.uncompressed_point_arr1, (short) 0);
bResult = Util.arrayCompare(ech.fnc_isEqual_hashArray, (short) 0, ech.uncompressed_point_arr1, (short) 0, len) == 0;
//ech.unlock(ech.fnc_isEqual_hashEngine);
ech.unlock(ech.fnc_isEqual_hashArray);
ech.unlock(ech.uncompressed_point_arr1);
}
return bResult;
}
示例4: same_value
import javacard.framework.Util; //导入方法依赖的package包/类
/**
* Equality check. Requires that this object and other have the same size or are padded with zeroes.
* Returns true if all digits (except for leading zeroes) are equal.
*
*
* @param other Bignat to compare
* @return true if this and other have the same value, false otherwise.
*/
public boolean same_value(Bignat other) {
short hashLen;
// Compare using hash engine
// The comparison is made with hash of point values instead of directly values.
// This way, offset of first mismatching byte is not leaked via timing side-channel.
bnh.lock(bnh.fnc_same_value_array1);
bnh.lock(bnh.fnc_same_value_hash);
if (this.length() == other.length()) {
// Same length, we can hash directly from BN values
bnh.hashEngine.doFinal(this.value, (short) 0, this.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(other.value, (short) 0, other.length(), bnh.fnc_same_value_array1, (short) 0);
}
else {
// Different length of bignats - can be still same if prepended with zeroes
// Find the length of longer one and padd other one with starting zeroes
if (this.length() < other.length()) {
this.prepend_zeros(other.length(), bnh.fnc_same_value_array1, (short) 0);
bnh.hashEngine.doFinal(bnh.fnc_same_value_array1, (short) 0, other.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(other.value, (short) 0, other.length(), bnh.fnc_same_value_array1, (short) 0);
}
else {
other.prepend_zeros(this.length(), bnh.fnc_same_value_array1, (short) 0);
bnh.hashEngine.doFinal(bnh.fnc_same_value_array1, (short) 0, this.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(this.value, (short) 0, this.length(), bnh.fnc_same_value_array1, (short) 0);
}
}
boolean bResult = Util.arrayCompare(bnh.fnc_same_value_hash, (short) 0, bnh.fnc_same_value_array1, (short) 0, hashLen) == 0;
bnh.unlock(bnh.fnc_same_value_array1);
bnh.unlock(bnh.fnc_same_value_hash);
return bResult;
}
示例5: search
import javacard.framework.Util; //导入方法依赖的package包/类
static PasswordPinEntry search(byte[] buf, short ofs, byte len) {
for (PasswordPinEntry pe = first; pe != null; pe = pe.next) {
if (pe.idLength != len) continue;
if (Util.arrayCompare(pe.id, (short) 0, buf, ofs, len) == 0)
return pe;
}
return null;
}
示例6: search
import javacard.framework.Util; //导入方法依赖的package包/类
static PasswordEntry search(byte[] buf, short ofs, byte len) {
for (PasswordEntry pe = first; pe != null; pe = pe.next) {
if (pe.idLength != len) continue;
if (Util.arrayCompare(pe.id, (short) 0, buf, ofs, len) == 0)
return pe;
}
return null;
}
示例7: VerifyYsCommitment
import javacard.framework.Util; //导入方法依赖的package包/类
public boolean VerifyYsCommitment(byte[] Ys, short YsOffset, short YsLength, byte[] commitment) {
if (YsLength != Consts.PUBKEY_YS_SHARE_SIZE) {
ISOException.throwIt(Consts.SW_INVALIDYSHARE);
}
md.reset();
md.doFinal(Ys, YsOffset, YsLength, tmp_arr, (short) 0);
return Util.arrayCompare(tmp_arr, (short) 0, commitment, (short) 0, Consts.SHARE_BASIC_SIZE) == 0;
}
示例8: same_value
import javacard.framework.Util; //导入方法依赖的package包/类
/**
* Equality check. Requires that this object and other have the same size or are padded with zeroes.
* Returns true if all digits (except for leading zeroes) are equal.
*
*
* @param other Bignat to compare
* @return true if this and other have the same value, false otherwise.
*/
public boolean same_value(Bignat other) {
short hashLen;
// Compare using hash engine
// The comparison is made with hash of point values instead of directly values.
// This way, offset of first mismatching byte is not leaked via timing side-channel.
bnh.lock(bnh.fnc_same_value_array1);
bnh.lock(bnh.fnc_same_value_hash);
if (this.length() == other.length()) {
// Same length, we can hash directly from BN values
bnh.hashEngine.doFinal(this.value, (short) 0, this.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(other.value, (short) 0, other.length(), bnh.fnc_same_value_array1, (short) 0);
}
else {
// Different length of bignats - can be still same if prepended with zeroes
// Find the length of longer one and padd other one with starting zeroes
if (this.length() < other.length()) {
this.prepend_zeros(other.length(), bnh.fnc_same_value_array1, (short) 0);
bnh.hashEngine.doFinal(bnh.fnc_same_value_array1, (short) 0, other.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(other.value, (short) 0, other.length(), bnh.fnc_same_value_array1, (short) 0);
}
else {
other.prepend_zeros(this.length(), bnh.fnc_same_value_array1, (short) 0);
bnh.hashEngine.doFinal(bnh.fnc_same_value_array1, (short) 0, this.length(), bnh.fnc_same_value_hash, (short) 0);
hashLen = bnh.hashEngine.doFinal(this.value, (short) 0, this.length(), bnh.fnc_same_value_array1, (short) 0);
}
}
boolean bResult = Util.arrayCompare(bnh.fnc_same_value_hash, (short) 0, bnh.fnc_same_value_array1, (short) 0, hashLen) == 0;
bnh.unlock(bnh.fnc_same_value_array1);
bnh.unlock(bnh.fnc_same_value_hash);
return bResult;
}