• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Util类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javacard.framework.Util的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Util类属于javacard.framework包,在下文中一共展示了Util类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:35,代码来源:Bignat.java


示例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();
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:28,代码来源:Bignat.java


示例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;
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:30,代码来源:ECPoint.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:24,代码来源:ResourceManager.java


示例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
     }
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:22,代码来源:OCUnitTests.java


示例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;
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:21,代码来源:FIDOCCImplementation.java


示例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
}
 
开发者ID:petrs,项目名称:hotp_via_ndef,代码行数:30,代码来源:UtilBCD.java


示例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));
    }
}
 
开发者ID:petrs,项目名称:hotp_via_ndef,代码行数:25,代码来源:UtilBCD.java


示例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);
    
}
 
开发者ID:petrs,项目名称:hotp_via_ndef,代码行数:32,代码来源:HMACgenerator.java


示例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
     }
}
 
开发者ID:OpenCryptoProject,项目名称:JCProfiler,代码行数:22,代码来源:OCUnitTests.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:35,代码来源:jcmathlib.java


示例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);  
        }
        
    }
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:26,代码来源:QuorumContext.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:24,代码来源:jcmathlib.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:23,代码来源:MPCApplet.java


示例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;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:22,代码来源:QuorumContext.java


示例16: prepend_zeros

import javacard.framework.Util; //导入依赖的package包/类
/**
 * Prepends zeros before the value of this Bignat up to target length. 
 *
 * @param targetLength required length including prepended zeroes
 * @param outBuffer output buffer for value with prepended zeroes
 * @param outOffset start offset inside outBuffer for write
 */
public void prepend_zeros(short targetLength, byte[] outBuffer, short outOffset) { 
    short other_start = (short) (targetLength - this.size);
    if (other_start > 0) {
        Util.arrayFillNonAtomic(outBuffer, outOffset, other_start, (byte) 0); //fill prefix with zeros
    }
    Util.arrayCopyNonAtomic(value, (short) 0, outBuffer, (short) (outOffset + other_start), this.size); //copy the value
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:15,代码来源:Bignat.java


示例17: 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;
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:43,代码来源:Bignat.java


示例18: mod_exp

import javacard.framework.Util; //导入依赖的package包/类
/**
 * Computes {@code res := this ** exponent mod modulo} and store results into this. 
 * Uses RSA engine to quickly compute this^exponent % modulo
 * @param exponent value of exponent
 * @param modulo value of modulo
 */
public void mod_exp(Bignat exponent, Bignat modulo) {
    short tmp_size = (short)(bnh.MODULO_RSA_ENGINE_MAX_LENGTH_BITS / 8);
    bnh.fnc_mod_exp_modBN.lock();
    bnh.fnc_mod_exp_modBN.set_size(tmp_size);

    short len = n_mod_exp(tmp_size, this, exponent.as_byte_array(), exponent.length(), modulo, bnh.fnc_mod_exp_modBN.value, (short) 0);
    if (bnh.bIsSimulator) {
        // Decrypted length can be either tmp_size or less because of leading zeroes consumed by simulator engine implementation
        // Move obtained value into proper position with zeroes prepended
        if (len != tmp_size) {
            bnh.lock(bnh.fnc_deep_resize_tmp);
            Util.arrayFillNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, (short) bnh.fnc_deep_resize_tmp.length, (byte) 0);
            Util.arrayCopyNonAtomic(bnh.fnc_mod_exp_modBN.value, (short) 0, bnh.fnc_deep_resize_tmp, (short) (tmp_size - len), len);
            Util.arrayCopyNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, bnh.fnc_mod_exp_modBN.value, (short) 0, tmp_size);
            bnh.unlock(bnh.fnc_deep_resize_tmp);
        }
    }
    else {
        // real cards should keep whole length of block, just check
        if (len != tmp_size) {
            ISOException.throwIt(ReturnCodes.SW_ECPOINT_UNEXPECTED_KA_LEN);
        }
    }
    bnh.fnc_mod_exp_modBN.mod(modulo);
	bnh.fnc_mod_exp_modBN.shrink();
	this.clone(bnh.fnc_mod_exp_modBN);
    bnh.fnc_mod_exp_modBN.unlock();
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:35,代码来源:Bignat.java


示例19: shift_bytes_right

import javacard.framework.Util; //导入依赖的package包/类
/**
 * Shifts stored value to right by specified number of bytes. This operation equals to multiplication by value numBytes * 256.
 * @param numBytes number of bytes to shift
 */
public void shift_bytes_right(short numBytes) {
    // Move whole content by numBytes offset
    bnh.lock(bnh.fnc_shift_bytes_right_tmp);
    Util.arrayCopyNonAtomic(this.value, (short) 0, bnh.fnc_shift_bytes_right_tmp, (short) 0, (short) (this.value.length));
    Util.arrayCopyNonAtomic(bnh.fnc_shift_bytes_right_tmp, (short) 0, this.value, numBytes, (short) ((short) (this.value.length) - numBytes));
    Util.arrayFillNonAtomic(this.value, (short) 0, numBytes, (byte) 0);
    bnh.unlock(bnh.fnc_shift_bytes_right_tmp);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:13,代码来源:Bignat.java


示例20: from_byte_array

import javacard.framework.Util; //导入依赖的package包/类
/**
 * Set content of Bignat internal array
 *
 * @param from_array_length available data in {@code from_array}
 * @param this_offset offset where data should be stored
 * @param from_array data array to deserialize from
 * @param from_array_offset offset in {@code from_array}
 * @return the number of shorts actually read, except for the case where
 * deserialization finished by reading precisely {@code len} shorts, in this
 * case {@code len + 1} is returned.
 */
public short from_byte_array(short from_array_length, short this_offset, byte[] from_array, short from_array_offset) {
    short max
            = (short) (this_offset + from_array_length) <= this.size
                    ? from_array_length : (short) (this.size - this_offset);
    Util.arrayCopyNonAtomic(from_array, from_array_offset, value, this_offset, max);
    if ((short) (this_offset + from_array_length) == this.size) {
        return (short) (from_array_length + 1);
    } else {
        return max;
    }
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:23,代码来源:Bignat.java



注:本文中的javacard.framework.Util类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ECConstants类代码示例发布时间:2022-05-21
下一篇:
Java CommonUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap