当前位置: 首页>>代码示例>>Java>>正文


Java Util.arrayCopyNonAtomic方法代码示例

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


在下文中一共展示了Util.arrayCopyNonAtomic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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,项目名称:Myst,代码行数:15,代码来源:jcmathlib.java

示例3: 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

示例4: 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

示例5: 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,项目名称:Myst,代码行数:13,代码来源:jcmathlib.java

示例6: toByteArray

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Serializes this integer value into array. Sign is serialized as first byte
 * @param outBuffer output array
 * @param outBufferOffset start offset within output array
 * @return length of resulting serialized number including sign (number of bytes) 
 */
public short toByteArray(byte[] outBuffer, short outBufferOffset) {
    //Store sign
    outBuffer[outBufferOffset] = sign;
    //Store magnitude
    Util.arrayCopyNonAtomic(this.getMagnitude_b(), (short) 0, outBuffer, (short) (outBufferOffset + 1), this.getSize());
    return (short) (this.getSize() + 1);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:14,代码来源:Integer.java

示例7: getX

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Returns the X coordinate of this point in uncompressed form.
 * @param buffer output array for X coordinate
 * @param offset start offset within output array
 * @return length of X coordinate (in bytes)
 */
public short getX(byte[] buffer, short offset) {
    ech.lock(ech.uncompressed_point_arr1);
    thePoint.getW(ech.uncompressed_point_arr1, (short) 0);
    Util.arrayCopyNonAtomic(ech.uncompressed_point_arr1, (short) 1, buffer, offset, this.theCurve.COORD_SIZE);
    ech.unlock(ech.uncompressed_point_arr1);
    return this.theCurve.COORD_SIZE;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:14,代码来源:jcmathlib.java

示例8: computeHmacSha256

import javacard.framework.Util; //导入方法依赖的package包/类
private short computeHmacSha256(byte[] key, short key_offset, short key_length, 
	byte[] message, short message_offset, short message_length,
	byte[] mac, short mac_offset){
  	
  	byte[] hmacBuffer = JCSystem.makeTransientByteArray((short) 128, JCSystem.CLEAR_ON_DESELECT);

  	short BLOCKSIZE=64; 
  	short HASHSIZE=32;
  	
// compute inner hash
for (short i=0; i<key_length; i++){
	hmacBuffer[i]= (byte) (key[(short)(key_offset+i)] ^ (0x36));
}
Util.arrayFillNonAtomic(hmacBuffer, key_length, (short)(BLOCKSIZE-key_length), (byte)0);		
Util.arrayCopyNonAtomic(message, message_offset, hmacBuffer, BLOCKSIZE, message_length);
sha256.reset();
sha256.doFinal(hmacBuffer, (short)0, (short)(BLOCKSIZE+message_length), hmacBuffer, BLOCKSIZE); // copy hash result to data buffer!

// compute outer hash
for (short i=0; i<key_length; i++){
	hmacBuffer[i]= (byte) (key[(short)(key_offset+i)] ^ (0x5c));
}
Util.arrayFillNonAtomic(hmacBuffer, key_length, (short)(BLOCKSIZE-key_length), (byte)0);
// previous hash already copied to correct offset in scratch
sha256.reset();
sha256.doFinal(hmacBuffer, (short)0, (short)(BLOCKSIZE+HASHSIZE), mac, mac_offset);

return HASHSIZE;
  }
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:30,代码来源:FIDOCCImplementation.java

示例9: deep_resize

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Create Bignat with different number of bytes used. Will cause longer number 
 * to shrink (loss of the more significant bytes) and shorter to be prepended with zeroes
 *
 * @param new_size new size in bytes
 */
void deep_resize(short new_size) {
    if (new_size > this.max_size) {
        if (ALLOW_RUNTIME_REALLOCATION) {
            allocate_storage_array(new_size, this.allocatorType);
        } else {
            ISOException.throwIt(ReturnCodes.SW_BIGNAT_REALLOCATIONNOTALLOWED); // Reallocation to longer size not permitted
        }
    }
    
    if (new_size == this.size) {
        // No need to resize enything, same length
    } 
    else {
        short this_start, other_start, len;
        bnh.lock(bnh.fnc_deep_resize_tmp);
        if (this.size >= new_size) {
            this_start = (short) (this.size - new_size);
            other_start = 0;
            len = new_size;

            // Shrinking/cropping 
            Util.arrayCopyNonAtomic(value, this_start, bnh.fnc_deep_resize_tmp, (short) 0, len);
            Util.arrayCopyNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, value, (short) 0, len); // Move bytes in item array towards beggining
            // Erase rest of allocated array with zeroes (just as sanitization)
            short toErase = (short) (this.max_size - new_size);
            if (toErase > 0) {
                Util.arrayFillNonAtomic(value, new_size, toErase, (byte) 0);
            }
        } else {
            this_start = 0;
            other_start = (short) (new_size - this.size);
            len = this.size;
            // Enlarging => Insert zeroes at begging, move bytes in item array towards the end
            Util.arrayCopyNonAtomic(value, this_start, bnh.fnc_deep_resize_tmp, (short) 0, len);
            // Move bytes in item array towards end
            Util.arrayCopyNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, value, other_start, len);
            // Fill begin of array with zeroes (just as sanitization)
            if (other_start > 0) {
                Util.arrayFillNonAtomic(value, (short) 0, other_start, (byte) 0);
            }
        }
        bnh.unlock(bnh.fnc_deep_resize_tmp);

        set_size(new_size);
    }
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:53,代码来源:Bignat.java

示例10: deep_resize

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Create Bignat with different number of bytes used. Will cause longer number 
 * to shrink (loss of the more significant bytes) and shorter to be prepended with zeroes
 *
 * @param new_size new size in bytes
 */
void deep_resize(short new_size) {
    if (new_size > this.max_size) {
        if (ALLOW_RUNTIME_REALLOCATION) {
            allocate_storage_array(new_size, this.allocatorType);
        } else {
            ISOException.throwIt(ReturnCodes.SW_BIGNAT_REALLOCATIONNOTALLOWED); // Reallocation to longer size not permitted
        }
    }
    
    if (new_size == this.size) {
        // No need to resize enything, same length
    } 
    else {
        short this_start, other_start, len;
        bnh.lock(bnh.fnc_deep_resize_tmp);
        if (this.size >= new_size) {
            this_start = (short) (this.size - new_size);
            other_start = 0;
            len = new_size;
    
            // Shrinking/cropping 
            Util.arrayCopyNonAtomic(value, this_start, bnh.fnc_deep_resize_tmp, (short) 0, len);
            Util.arrayCopyNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, value, (short) 0, len); // Move bytes in item array towards beggining
            // Erase rest of allocated array with zeroes (just as sanitization)
            short toErase = (short) (this.max_size - new_size);
            if (toErase > 0) {
                Util.arrayFillNonAtomic(value, new_size, toErase, (byte) 0);
            }
        } else {
            this_start = 0;
            other_start = (short) (new_size - this.size);
            len = this.size;
            // Enlarging => Insert zeroes at begging, move bytes in item array towards the end
            Util.arrayCopyNonAtomic(value, this_start, bnh.fnc_deep_resize_tmp, (short) 0, len);
            // Move bytes in item array towards end
            Util.arrayCopyNonAtomic(bnh.fnc_deep_resize_tmp, (short) 0, value, other_start, len);
            // Fill begin of array with zeroes (just as sanitization)
            if (other_start > 0) {
                Util.arrayFillNonAtomic(value, (short) 0, other_start, (byte) 0);
            }
        }
        bnh.unlock(bnh.fnc_deep_resize_tmp);
    
        set_size(new_size);
    }
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:53,代码来源:jcmathlib.java

示例11: shift_left

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * One digit left shift.
 * <P>
 * Asserts that the first digit is zero.
 */
public void shift_left() {
    // NOTE: assumes that overlapping src and dest arrays are properly handled by Util.arrayCopyNonAtomic
    Util.arrayCopyNonAtomic(this.value, (short) 1, this.value, (short) 0, (short) (size - 1)); 
    value[(short) (size - 1)] = 0;
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:11,代码来源:Bignat.java

示例12: GetXi

import javacard.framework.Util; //导入方法依赖的package包/类
public short GetXi(byte[] array, short offset) {
    state.CheckAllowedFunction(StateModel.FNC_QuorumContext_GetXi);
    
    Util.arrayCopyNonAtomic(x_i_Bn, (short) 0, array, offset, (short) x_i_Bn.length);
    return (short) x_i_Bn.length;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:7,代码来源:QuorumContext.java

示例13: OCUnitTests

import javacard.framework.Util; //导入方法依赖的package包/类
public OCUnitTests() {
    m_memoryInfo = new short[(short) (7 * 3)]; // Contains RAM and EEPROM memory required for basic library objects 
    m_memoryInfoOffset = snapshotAvailableMemory((short) 1, m_memoryInfo, m_memoryInfoOffset);
    if (bTEST_256b_CURVE) {
        m_ecc = new ECConfig((short) 256);
    }
    if (bTEST_512b_CURVE) {
        m_ecc = new ECConfig((short) 512);
    }
    m_memoryInfoOffset = snapshotAvailableMemory((short) 2, m_memoryInfo, m_memoryInfoOffset);
    

    // Pre-allocate test objects (no new allocation for every tested operation)
    if (bTEST_256b_CURVE) {
        m_testCurve = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, m_ecc);
        m_memoryInfoOffset = snapshotAvailableMemory((short) 3, m_memoryInfo, m_memoryInfoOffset);
        // m_testCurveCustom and m_testPointCustom will have G occasionally changed so we need separate ECCurve
        m_customG = new byte[(short) SecP256r1.G.length];
        Util.arrayCopyNonAtomic(SecP256r1.G, (short) 0, m_customG, (short) 0, (short) SecP256r1.G.length);
        m_testCurveCustom = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, m_customG, SecP256r1.r, m_ecc);
    }
    if (bTEST_512b_CURVE) {
        m_testCurve = new ECCurve(false, P512r1.p, P512r1.a, P512r1.b, P512r1.G, P512r1.r, m_ecc);
        // m_testCurveCustom and m_testPointCustom will have G occasionally changed so we need separate ECCurve
        m_customG = new byte[(short) P512r1.G.length];
        Util.arrayCopyNonAtomic(P512r1.G, (short) 0, m_customG, (short) 0, (short) P512r1.G.length);
        m_testCurveCustom = new ECCurve(false, P512r1.p, P512r1.a, P512r1.b, m_customG, P512r1.r, m_ecc);
    }
    
    m_memoryInfoOffset = snapshotAvailableMemory((short) 5, m_memoryInfo, m_memoryInfoOffset);
    m_testPoint1 = new ECPoint(m_testCurve, m_ecc);
    m_memoryInfoOffset = snapshotAvailableMemory((short) 6, m_memoryInfo, m_memoryInfoOffset);
    m_testPoint2 = new ECPoint(m_testCurve, m_ecc);
    m_testPointCustom = new ECPoint(m_testCurveCustom, m_ecc);

    // Testing Bignat objects used in tests
    m_memoryInfoOffset = snapshotAvailableMemory((short) 7, m_memoryInfo, m_memoryInfoOffset);
    byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET;
    m_testBN1 = new Bignat(m_ecc.MAX_BIGNAT_SIZE, memoryType, m_ecc);
    m_memoryInfoOffset = snapshotAvailableMemory((short) 8, m_memoryInfo, m_memoryInfoOffset);
    m_testBN2 = new Bignat(m_ecc.MAX_BIGNAT_SIZE, memoryType, m_ecc);
    m_testBN3 = new Bignat(m_ecc.MAX_BIGNAT_SIZE, memoryType, m_ecc);
    
    short intLen = 4;
    m_testINT1 = new Integer(intLen, m_ecc);
    m_testINT2 = new Integer(intLen, m_ecc);
}
 
开发者ID:OpenCryptoProject,项目名称:JCProfiler,代码行数:48,代码来源:OCUnitTests.java

示例14: handleVersion

import javacard.framework.Util; //导入方法依赖的package包/类
private void handleVersion(APDU apdu) throws ISOException {
    byte[] buffer = apdu.getBuffer();
    Util.arrayCopyNonAtomic(VERSION, (short)0, buffer, (short)0, (short)VERSION.length);
    apdu.setOutgoingAndSend((short)0, (short)VERSION.length);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:6,代码来源:U2FApplet.java

示例15: process

import javacard.framework.Util; //导入方法依赖的package包/类
public void process(APDU apdu) throws ISOException {
    byte[] buffer = apdu.getBuffer();
    if (selectingApplet()) {
        if (attestationCertificateSet) {
            Util.arrayCopyNonAtomic(VERSION, (short)0, buffer, (short)0, (short)VERSION.length);
            apdu.setOutgoingAndSend((short)0, (short)VERSION.length);
        }
        return;
    }
    if (buffer[ISO7816.OFFSET_CLA] == PROPRIETARY_CLA) {
        if (attestationCertificateSet) {
            ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
        }
        switch(buffer[ISO7816.OFFSET_INS]) {
        case FIDO_ADM_SET_ATTESTATION_CERT:
            handleSetAttestationCert(apdu);
            break;
        default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }
    else if (buffer[ISO7816.OFFSET_CLA] == FIDO_CLA) {
        if (!attestationCertificateSet) {
            ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
        }
        switch(buffer[ISO7816.OFFSET_INS]) {
        case FIDO_INS_ENROLL:
            handleEnroll(apdu);
            break;
        case FIDO_INS_SIGN:
            handleSign(apdu);
            break;
        case FIDO_INS_VERSION:
            handleVersion(apdu);
            break;
        case ISO_INS_GET_DATA:
            handleGetData(apdu);
            break;
        default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }
    else {
        ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    }
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:47,代码来源:U2FApplet.java


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