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


Java APDU类代码示例

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


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

示例1: test_EC_SETCURVE_G

import javacard.framework.APDU; //导入依赖的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

示例2: test_EC_MUL

import javacard.framework.APDU; //导入依赖的package包/类
void test_EC_MUL(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short p1_len = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_EC_MUL_1);
    Bignat scalar = m_testBN1;
    scalar.set_size(p1_len);
    scalar.from_byte_array(p1_len, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
    PM.check(PM.TRAP_EC_MUL_2);
    m_testPoint1.setW(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1_len), m_testCurve.POINT_SIZE);
    PM.check(PM.TRAP_EC_MUL_3);
    m_testPoint1.multiplication(scalar);
    PM.check(PM.TRAP_EC_MUL_4);

    short len = m_testPoint1.getW(apdubuf, (short) 0);
    PM.check(PM.TRAP_EC_MUL_5);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:19,代码来源:OCUnitTests.java

示例3: test_BN_ADD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_ADD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_BN_ADD_1);
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_ADD_2);
    Bignat num2 = m_testBN2;
    num2.set_size((short) (dataLen - p1));
    PM.check(PM.TRAP_BN_ADD_3);
    Bignat sum = m_testBN3;
    sum.set_size((short) (p1 + 1));

    PM.check(PM.TRAP_BN_ADD_4);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    num2.from_byte_array((short) (dataLen - p1), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_ADD_5);
    sum.copy(num1);
    PM.check(PM.TRAP_BN_ADD_6);
    sum.add(num2);
    PM.check(PM.TRAP_BN_ADD_7);
    short len = sum.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);    
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:26,代码来源:OCUnitTests.java

示例4: test_BN_SUB

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_SUB(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_BN_SUB_1);
    Bignat sub1 = m_testBN1;
    sub1.set_size(p1);
    PM.check(PM.TRAP_BN_SUB_2);
    Bignat sub2 = m_testBN2;
    sub2.set_size((short) (dataLen - p1));
    PM.check(PM.TRAP_BN_SUB_3);
    Bignat result = m_testBN3;
    result.set_size((short) (p1 + 1));
    PM.check(PM.TRAP_BN_SUB_4);
    sub1.from_byte_array(dataLen, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    sub2.from_byte_array(dataLen, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_SUB_5);
    result.copy(sub1);
    PM.check(PM.TRAP_BN_SUB_6);
    result.subtract(sub2);
    PM.check(PM.TRAP_BN_SUB_7);
    short len = result.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:25,代码来源:OCUnitTests.java

示例5: test_BN_EXP

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_EXP(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_EXP_1);    
    Bignat base = m_testBN1;
    base.set_size(p1);
    PM.check(PM.TRAP_BN_EXP_2);
    Bignat exp = m_testBN2;
    exp.set_size((short) (dataLen - p1));
    PM.check(PM.TRAP_BN_EXP_3);
    Bignat res = m_testBN3;
    res.set_size((short) (m_ecc.MAX_BIGNAT_SIZE / 2));
    PM.check(PM.TRAP_BN_EXP_4);
    base.from_byte_array(p1, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
    exp.from_byte_array((short) (dataLen - p1), (short) 0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_EXP_5);
    res.exponentiation(base, exp);
    PM.check(PM.TRAP_BN_EXP_6);
    short len = res.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:24,代码来源:OCUnitTests.java

示例6: test_BN_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_BN_MOD_1);
    Bignat num = m_testBN1;
    num.set_size(p1);
    PM.check(PM.TRAP_BN_MOD_2);
    Bignat mod = m_testBN2;
    mod.set_size((short) (dataLen - p1));
    PM.check(PM.TRAP_BN_MOD_3);
    num.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    mod.from_byte_array((short)(dataLen-p1), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_MOD_4);
    num.mod(mod);
    PM.check(PM.TRAP_BN_MOD_5);
    short len = num.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:20,代码来源:OCUnitTests.java

示例7: test_BN_ADD_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_ADD_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_ADD_MOD_1);    
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_ADD_MOD_2);
    Bignat num2 = m_testBN2;
    num2.set_size(p2);
    PM.check(PM.TRAP_BN_ADD_MOD_3);
    Bignat mod = m_testBN3;
    mod.set_size((short) (dataLen - p1 - p2));
    PM.check(PM.TRAP_BN_ADD_MOD_4);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    num2.from_byte_array(p2, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_ADD_MOD_5);
    mod.from_byte_array((short)(dataLen-p1-p2), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1+p2));
    PM.check(PM.TRAP_BN_ADD_MOD_6);
    num1.mod_add(num2, mod);
    PM.check(PM.TRAP_BN_ADD_MOD_7);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:26,代码来源:OCUnitTests.java

示例8: test_BN_SUB_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_SUB_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_SUB_MOD_1);    
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_SUB_MOD_2);
    Bignat num2 = m_testBN2;
    num2.set_size(p2);
    PM.check(PM.TRAP_BN_SUB_MOD_3);
    Bignat mod = m_testBN3;
    mod.set_size((short) (dataLen - p1 - p2));
    PM.check(PM.TRAP_BN_SUB_MOD_4);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    num2.from_byte_array(p2, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    mod.from_byte_array((short)(dataLen-p1-p2), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1+p2));
    PM.check(PM.TRAP_BN_SUB_MOD_5);
    num1.mod_sub(num2, mod);
    PM.check(PM.TRAP_BN_SUB_MOD_6);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:25,代码来源:OCUnitTests.java

示例9: test_BN_MUL_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_MUL_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_MUL_MOD_1);    
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_MUL_MOD_2);
    Bignat num2 = m_testBN2;
    num2.set_size(p2);
    PM.check(PM.TRAP_BN_MUL_MOD_3);
    Bignat mod = m_testBN3;
    mod.set_size((short) (dataLen - p1 - p2));
    PM.check(PM.TRAP_BN_MUL_MOD_4);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    num2.from_byte_array(p2, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    mod.from_byte_array((short)(dataLen-p1-p2), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1+p2));
    PM.check(PM.TRAP_BN_MUL_MOD_5);
    num1.mod_mult(num1, num2, mod);
    PM.check(PM.TRAP_BN_MUL_MOD_6);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:25,代码来源:OCUnitTests.java

示例10: test_BN_EXP_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_EXP_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_EXP_MOD_1);    
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_EXP_MOD_2);
    Bignat num2 = m_testBN2;
    num2.set_size(p2);
    PM.check(PM.TRAP_BN_EXP_MOD_3);
    Bignat mod = m_testBN3;
    mod.set_size((short) (dataLen - p1 - p2));
    PM.check(PM.TRAP_BN_EXP_MOD_4);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    num2.from_byte_array(p2, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    mod.from_byte_array((short)(dataLen-p1-p2), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1+p2));
    PM.check(PM.TRAP_BN_EXP_MOD_5);
    num1.mod_exp(num2, mod);
    PM.check(PM.TRAP_BN_EXP_MOD_6);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:25,代码来源:OCUnitTests.java

示例11: test_BN_POW2_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_POW2_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
    short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);

    PM.check(PM.TRAP_BN_POW2_MOD_1);
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    Bignat mod = m_testBN3;
    mod.set_size((short) (dataLen - p1));
    num1.from_byte_array(p1, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
    mod.from_byte_array((short) (dataLen - p1), (short) 0, apdubuf, (short) (ISO7816.OFFSET_CDATA + p1));
    PM.check(PM.TRAP_BN_POW2_MOD_2);
    //num1.pow2Mod_RSATrick(mod);
    num1.mod_exp2(mod);
    PM.check(PM.TRAP_BN_POW2_MOD_3);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:20,代码来源:OCUnitTests.java

示例12: test_BN_INV_MOD

import javacard.framework.APDU; //导入依赖的package包/类
void test_BN_INV_MOD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_BN_INV_MOD_1);
    Bignat num1 = m_testBN1;
    num1.set_size(p1);
    PM.check(PM.TRAP_BN_INV_MOD_2);
    Bignat mod = m_testBN2;
    mod.set_size((short) (dataLen - p1));
    PM.check(PM.TRAP_BN_INV_MOD_3);
    num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
    mod.from_byte_array((short)(dataLen-p1), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
    PM.check(PM.TRAP_BN_INV_MOD_4);
    num1.mod_inv(mod);
    PM.check(PM.TRAP_BN_INV_MOD_5);
    short len = num1.copy_to_buffer(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:20,代码来源:OCUnitTests.java

示例13: test_INT_ADD

import javacard.framework.APDU; //导入依赖的package包/类
void test_INT_ADD(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_INT_ADD_1);    
    //Integer num_add_1 = new Integer(dataLen, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
    Integer num_add_1 = m_testINT1;
    num_add_1.fromByteArray(apdubuf, ISO7816.OFFSET_CDATA, p1);
    PM.check(PM.TRAP_INT_ADD_2);
    //Integer num_add_2 = new Integer((short) (dataLen - p1), (short) 0, apdubuf, (short) (ISO7816.OFFSET_CDATA + p1));
    Integer num_add_2 = m_testINT2;
    num_add_2.fromByteArray(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1), p1);
    PM.check(PM.TRAP_INT_ADD_3);
    num_add_1.add(num_add_2);
    PM.check(PM.TRAP_INT_ADD_4);
    short len = num_add_1.toByteArray(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:19,代码来源:OCUnitTests.java

示例14: test_INT_SUB

import javacard.framework.APDU; //导入依赖的package包/类
void test_INT_SUB(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_INT_SUB_1);               
    Integer num_sub_1 = m_testINT1;
    num_sub_1.fromByteArray(apdubuf, ISO7816.OFFSET_CDATA, p1);
    Integer num_sub_2 = m_testINT2;
    num_sub_2.fromByteArray(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1), p1);
    PM.check(PM.TRAP_INT_SUB_2);

    num_sub_1.subtract(num_sub_2);
    PM.check(PM.TRAP_INT_SUB_3);
    short len = num_sub_1.toByteArray(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:17,代码来源:OCUnitTests.java

示例15: test_INT_MUL

import javacard.framework.APDU; //导入依赖的package包/类
void test_INT_MUL(APDU apdu, short dataLen) {
    byte[] apdubuf = apdu.getBuffer();
    short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);

    PM.check(PM.TRAP_INT_MUL_1);    
    Integer num_mul_1 = m_testINT1;
    num_mul_1.fromByteArray(apdubuf, ISO7816.OFFSET_CDATA, p1);
    Integer num_mul_2 = m_testINT2;
    num_mul_2.fromByteArray(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1), p1);
    PM.check(PM.TRAP_INT_MUL_2);

    num_mul_1.multiply(num_mul_2);
    PM.check(PM.TRAP_INT_MUL_3);
    short len = num_mul_1.toByteArray(apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, len);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:17,代码来源:OCUnitTests.java


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