本文整理汇总了Java中javacard.framework.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于javacard.framework包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copy
import javacard.framework.Util; //导入依赖的package包/类
/**
* Copies {@code other} into this. No size requirements. If {@code other}
* has more digits then the superfluous leading digits of {@code other} are
* asserted to be zero. If this bignat has more digits than its leading
* digits are correctly initilized to zero. This function will not change size
* attribute of this object.
*
* @param other
* Bignat to copy into this object.
*/
public void copy(Bignat other) {
short this_start, other_start, len;
if (this.size >= other.size) {
this_start = (short) (this.size - other.size);
other_start = 0;
len = other.size;
} else {
this_start = 0;
other_start = (short) (other.size - this.size);
len = this.size;
// Verify here that other have leading zeroes up to other_start
for (short i = 0; i < other_start; i ++) {
if (other.value[i] != 0) {
ISOException.throwIt(ReturnCodes.SW_BIGNAT_INVALIDCOPYOTHER);
}
}
}
if (this_start > 0) {
// if this bignat has more digits than its leading digits are initilized to zero
Util.arrayFillNonAtomic(this.value, (short) 0, this_start, (byte) 0);
}
Util.arrayCopyNonAtomic(other.value, other_start, this.value, this_start, len);
}
示例2: clone
import javacard.framework.Util; //导入依赖的package包/类
/**
* Copies content of {@code other} into this and set size of this to {@code other}.
* The size attribute (returned by length()) is updated. If {@code other}
* is longer than maximum capacity of this, internal buffer is reallocated if enabled
* (ALLOW_RUNTIME_REALLOCATION), otherwise exception is thrown.
* @param other
* Bignat to clone into this object.
*/
public void clone(Bignat other) {
// Reallocate array only if current array cannot store the other value and reallocation is enabled by ALLOW_RUNTIME_REALLOCATION
if (this.max_size < other.length()) {
// Reallocation necessary
if (ALLOW_RUNTIME_REALLOCATION) {
allocate_storage_array(other.length(), this.allocatorType);
}
else {
ISOException.throwIt(ReturnCodes.SW_BIGNAT_REALLOCATIONNOTALLOWED);
}
}
// copy value from other into proper place in this (this can be longer than other so rest of bytes wil be filled with 0)
other.copy_to_buffer(this.value, (short) 0);
if (this.max_size > other.length()) {
Util.arrayFillNonAtomic(this.value, other.length(), (short) (this.max_size - other.length()), (byte) 0);
}
this.size = other.length();
}
示例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: erase
import javacard.framework.Util; //导入依赖的package包/类
/**
* Erase all values stored in helper objects
*/
void erase() {
helper_BN_A.erase();
helper_BN_B.erase();
helper_BN_C.erase();
helper_BN_D.erase();
helper_BN_E.erase();
helper_BN_F.erase();
helperEC_BN_A.erase();
helperEC_BN_B.erase();
helperEC_BN_C.erase();
helperEC_BN_D.erase();
helperEC_BN_E.erase();
helperEC_BN_F.erase();
Util.arrayFillNonAtomic(helper_BN_array1, (short) 0, (short) helper_BN_array1.length, (byte) 0);
Util.arrayFillNonAtomic(helper_BN_array2, (short) 0, (short) helper_BN_array2.length, (byte) 0);
Util.arrayFillNonAtomic(helper_uncompressed_point_arr1, (short) 0, (short) helper_uncompressed_point_arr1.length, (byte) 0);
}
示例5: test_EC_SETCURVE_G
import javacard.framework.Util; //导入依赖的package包/类
void test_EC_SETCURVE_G(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
Util.arrayCopyNonAtomic(apdubuf, ISO7816.OFFSET_CDATA, m_customG, (short) 0, dataLen);
PM.check(PM.TRAP_EC_SETCURVE_1);
if (apdubuf[ISO7816.OFFSET_P2] == 1) { // If required, complete new custom curve and point is allocated
m_testCurveCustom = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, m_customG, SecP256r1.r);
m_testPointCustom = new ECPoint(m_testCurveCustom, m_ecc.ech);
PM.check(PM.TRAP_EC_SETCURVE_2);
// Release unused previous objects
if (!bIsSimulator) {
JCSystem.requestObjectDeletion();
}
}
else {
// Otherwise, only G is set and relevant objects are updated
m_testCurveCustom.setG(apdubuf, (short) ISO7816.OFFSET_CDATA, m_testCurveCustom.POINT_SIZE);
m_testPointCustom.updatePointObjects(); // After changing curve parameters, internal objects needs to be actualized
}
}
示例6: 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;
}
示例7: toBCD
import javacard.framework.Util; //导入依赖的package包/类
/**
* Converts up to 8 byte value to BCD array.
* Lenght of array + outOffset should be always >= 10.
* Number is considered to be big-endian.
* Output array can be same as input array.
*
* @param input Byte array containing number ot convert
* @param inOffset Start index of number in input array
* @param inLenght Length of number in bytes
* @param out Byte array that will be filled with BCD values.
* @param outOffset Start index of output array.
* @return Number of digits. Curretly always 10.
*/
public static short toBCD(byte[] input, short inOffset, short inLenght, byte[] out, short outOffset){
Util.arrayFillNonAtomic(buffer, (short) 0, (short) buffer.length, (byte) 0x00);
for(short index = inOffset; index < (short)(inOffset + inLenght); index++){
short bytePosition = (short)(index - inOffset);
short bytePositionFromLeft = (short)(inLenght - bytePosition - 1);
for(short bitPosition = 0; bitPosition < 8; bitPosition++){
if(((input[index] >> (7 - bitPosition)) & 1) > 0){
add(buffer, bcdValues, (short)((bytePositionFromLeft * 8 + (7 - bitPosition)) * 10));
}
}
}
Util.arrayCopyNonAtomic(buffer, (short) 0, out, outOffset, (short) 10);
Util.arrayFillNonAtomic(buffer, (short) 0, (short) buffer.length, (byte) 0); // Cleaning buffer, as static variables are not protected by firewall
return 10; //TODO
}
示例8: asciiToHex
import javacard.framework.Util; //导入依赖的package包/类
/**
* Converts array containing ASCII values binary array.
* Output length should be at least half the length of input.
* @param input ASCII array
* @param inOffset Starting index of input
* @param inLenght Length of input
* @param output Array to store binary values. Starts at 0
*/
public static void asciiToHex(byte[] input, short inOffset, short inLenght, byte[] output){
Util.arrayFillNonAtomic(output, (short) 0, (short) (inLenght/2 + inLenght % 2), (byte) 0);
byte alignment = (byte) (inLenght % 2);
byte shift, ialign;
byte in;
for(short i = (short) 0; i < inLenght; i++){
ialign = (byte) ((byte)(i + alignment)/2);
in = output[(byte)((byte)(i + alignment)/2)];
if((short)((short)(i + alignment) % (short)2) == (short) 0){
shift = (byte) 4;
}else{
shift = (byte) 0;
}
output[ialign] = (byte) (in | (byte)(asciiToBcd(input[(short)(inOffset + i)]) << shift));
}
}
示例9: HMACgenerator
import javacard.framework.Util; //导入依赖的package包/类
/**
*
* @param key Shared secret to use when generating HMAC
* @param keyLen Length of shared secret in bytes
* @param digits Numbers of digits to generate
*/
public HMACgenerator(byte key[], short keyLen, short digits){
//Set counter to 0
counter = new byte[counterSize];
Util.arrayFillNonAtomic(counter, (short) 0, counterSize, (byte) 0);
k_opad = new byte[64];
k_ipad = new byte[64];
shaBuffer = new byte[84];
outBuffer = new byte[20];
this.digits = digits;
asciiBuffer = new byte[10];
outputCodeDigits = new byte[digits];
for (short i = (short) 0; i < (short) 64; i++){
if(i < keyLen){
k_opad[i] = (byte) (key[i] ^ 0x5c);
k_ipad[i] = (byte) (key[i] ^ 0x36);
} else {
k_opad[i] = (byte) (0x5c);
k_ipad[i] = (byte) (0x36);
}
}
digest = MessageDigest.getInstance(MessageDigest.ALG_SHA, true);
}
示例10: test_EC_SETCURVE_G
import javacard.framework.Util; //导入依赖的package包/类
void test_EC_SETCURVE_G(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
Util.arrayCopyNonAtomic(apdubuf, ISO7816.OFFSET_CDATA, m_customG, (short) 0, dataLen);
PM.check(PM.TRAP_EC_SETCURVE_1);
if (apdubuf[ISO7816.OFFSET_P2] == 1) { // If required, complete new custom curve and point is allocated
m_testCurveCustom = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, m_customG, SecP256r1.r, m_ecc);
m_testPointCustom = new ECPoint(m_testCurveCustom, m_ecc);
PM.check(PM.TRAP_EC_SETCURVE_2);
// Release unused previous objects
if (!bIsSimulator) {
JCSystem.requestObjectDeletion();
}
}
else {
// Otherwise, only G is set and relevant objects are updated
m_testCurveCustom.setG(apdubuf, (short) ISO7816.OFFSET_CDATA, m_testCurveCustom.POINT_SIZE);
m_testPointCustom.updatePointObjects(); // After changing curve parameters, internal objects needs to be actualized
}
}
示例11: copy
import javacard.framework.Util; //导入依赖的package包/类
/**
* Copies {@code other} into this. No size requirements. If {@code other}
* has more digits then the superfluous leading digits of {@code other} are
* asserted to be zero. If this bignat has more digits than its leading
* digits are correctly initilized to zero. This function will not change size
* attribute of this object.
*
* @param other
* Bignat to copy into this object.
*/
public void copy(Bignat other) {
short this_start, other_start, len;
if (this.size >= other.size) {
this_start = (short) (this.size - other.size);
other_start = 0;
len = other.size;
} else {
this_start = 0;
other_start = (short) (other.size - this.size);
len = this.size;
// Verify here that other have leading zeroes up to other_start
for (short i = 0; i < other_start; i ++) {
if (other.value[i] != 0) {
ISOException.throwIt(ReturnCodes.SW_BIGNAT_INVALIDCOPYOTHER);
}
}
}
if (this_start > 0) {
// if this bignat has more digits than its leading digits are initilized to zero
Util.arrayFillNonAtomic(this.value, (short) 0, this_start, (byte) 0);
}
Util.arrayCopyNonAtomic(other.value, other_start, this.value, this_start, len);
}
示例12: StoreCommitment
import javacard.framework.Util; //导入依赖的package包/类
public void StoreCommitment(short id, byte[] commitment, short commitmentOffset, short commitmentLength) {
state.CheckAllowedFunction(StateModel.FNC_QuorumContext_StoreCommitment);
if (id < 0 || id == CARD_INDEX_THIS || id >= NUM_PLAYERS) {
ISOException.throwIt(Consts.SW_INVALIDPLAYERINDEX);
}
if (commitmentLength != players[id].YsCommitment.length) {
ISOException.throwIt(Consts.SW_INVALIDCOMMITMENTLENGTH);
}
if (players[id].bYsCommitmentValid) {
// commitment already stored
ISOException.throwIt(Consts.SW_COMMITMENTALREADYSTORED);
}
else {
Util.arrayCopyNonAtomic(commitment, commitmentOffset, players[id].YsCommitment, (short) 0, commitmentLength);
players[id].bYsCommitmentValid = true;
num_commitments_count++;
if (num_commitments_count == NUM_PLAYERS) {
// All commitments were collected, allow for export of this card share
state.MakeStateTransition(StateModel.STATE_KEYGEN_COMMITMENTSCOLLECTED);
}
}
}
示例13: erase
import javacard.framework.Util; //导入依赖的package包/类
/**
* Erase all values stored in helper objects
*/
void erase() {
helper_BN_A.erase();
helper_BN_B.erase();
helper_BN_C.erase();
helper_BN_D.erase();
helper_BN_E.erase();
helper_BN_F.erase();
helperEC_BN_A.erase();
helperEC_BN_B.erase();
helperEC_BN_C.erase();
helperEC_BN_D.erase();
helperEC_BN_E.erase();
helperEC_BN_F.erase();
Util.arrayFillNonAtomic(helper_BN_array1, (short) 0, (short) helper_BN_array1.length, (byte) 0);
Util.arrayFillNonAtomic(helper_BN_array2, (short) 0, (short) helper_BN_array2.length, (byte) 0);
Util.arrayFillNonAtomic(helper_uncompressed_point_arr1, (short) 0, (short) helper_uncompressed_point_arr1.length, (byte) 0);
}
示例14: KeyGen_StoreCommitment
import javacard.framework.Util; //导入依赖的package包/类
/**
* Upon the generation of the triplet, the members perform a pairwise
* exchange of their commitments by the end of which, they all hold a
* set H = {h1,h2, ..,ht }. The commitment exchange terminates when |Hq | =
* t ∀q ∈ Q
* @param apdu
*/
void KeyGen_StoreCommitment(APDU apdu) {
byte[] apdubuf = apdu.getBuffer();
short len = apdu.getIncomingLength();
short paramsOffset = GetOperationParamsOffset(Consts.INS_KEYGEN_STORE_COMMITMENT, apdu);
// Parse incoming apdu to obtain target quorum context
QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
// Verify authorization
quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_StoreCommitment);
// Store provided commitment
short playerId = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_PLAYERID_OFFSET));
short commitmentLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENTLENGTH_OFFSET));
quorumCtx.StoreCommitment(playerId, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENT_OFFSET), commitmentLen);
}
示例15: GetYi
import javacard.framework.Util; //导入依赖的package包/类
/**
* Returns this card public key share
* @param commitmentBuffer output buffer where to store commitment
* @param commitmentOffset start offset within target output buffer
* @return
*/
public short GetYi(byte[] commitmentBuffer, short commitmentOffset) {
state.CheckAllowedFunction(StateModel.FNC_QuorumContext_GetYi);
if (state.GetState() == StateModel.STATE_KEYGEN_COMMITMENTSCOLLECTED) {
if (players[CARD_INDEX_THIS].bYsValid) {
Util.arrayCopyNonAtomic(this_card_Ys, (short) 0, commitmentBuffer, commitmentOffset, (short) this_card_Ys.length);
return (short) this_card_Ys.length;
} else {
ISOException.throwIt(Consts.SW_INVALIDYSHARE);
}
} else {
ISOException.throwIt(Consts.SW_INCORRECTSTATE);
}
return 0;
}