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


Java APDU.setOutgoingAndSend方法代码示例

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


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

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

示例2: 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,项目名称:JCProfiler,代码行数:20,代码来源: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_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

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

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

示例7: GetObjectSize

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * This function returns the size of an object that has been previously created with 
 * MSCCreateObject.  
 *   
	 * ins: 0x57
 * p1: 0x00
 * p2: 0x00 
 * data: [object_id(4b)] 
 * return: [object_size(2b)]
 */
private void GetObjectSize(APDU apdu, byte[] buffer) {
	// Checking P1 & P2
	if (buffer[ISO7816.OFFSET_P1] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P1);
	if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P2);
	short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
	if (bytesLeft != apdu.setIncomingAndReceive())
		ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
	if (bytesLeft != (short) 4)
		ISOException.throwIt(SW_INVALID_PARAMETER);
	short obj_class = Util.getShort(buffer, ISO7816.OFFSET_CDATA);
	short obj_id = Util.getShort(buffer, (short) (ISO7816.OFFSET_CDATA + (short) 2));
	short base = om.getBaseAddress(obj_class, obj_id);
	// Verify that object exists
	if (base == MemoryManager.NULL_OFFSET)
		ISOException.throwIt(SW_INVALID_PARAMETER);
	// get object size
	short obj_size= om.getSizeFromAddress(base);
	// Fill the buffer
	Util.setShort(buffer, (short) 0, obj_size);
	// Send response
	apdu.setOutgoingAndSend((short) 0, (short) 2);
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:35,代码来源:CardEdge.java

示例8: ListPINs

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * This function returns a 2 byte bit mask of the available PINs that are currently in
 * use. Each set bit corresponds to an active PIN.
 * 
 *  ins: 0x48
 *  p1: 0x00
 *  p2: 0x00
 *  data: none
 *  return: [RFU(1b) | PIN_mask(1b)]
 */
private void ListPINs(APDU apdu, byte[] buffer) {
	// Checking P1 & P2
	if (buffer[ISO7816.OFFSET_P1] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P1);
	if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P2);
	byte expectedBytes = (byte) (buffer[ISO7816.OFFSET_LC]);
	if (expectedBytes != (short) 2)
		ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
	// Build the PIN bit mask
	short mask = (short) 0x00;
	short b;
	for (b = (short) 0; b < MAX_NUM_PINS; b++)
		if (pins[b] != null)
			mask |= (short) (((short) 0x01) << b);
	// Fill the buffer
	Util.setShort(buffer, (short) 0, mask);
	// Send response
	apdu.setOutgoingAndSend((short) 0, (short) 2);
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:31,代码来源:CardEdge.java

示例9: ListObjects

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * This function returns a list of current objects and their properties including id,
 * size, and access control. This function must be initially called with the reset
 * option. The function only returns one object information at a time and must be
 * called in repetition until SW_SUCCESS is returned with no further data.
 * Applications cannot rely on any special ordering of the sequence of returned objects. 
 * 
 *  ins: 0x58
 *  p1: 0x00 (reset and get first entry) or 0x01 (next entry)
 *  p2: 0x00 
 *  data: none
 *  return: [object_id(4b) | object_size(4b) | object_ACL(6b)]
 */
private void ListObjects(APDU apdu, byte[] buffer) {
	// Checking P1 & P2
	if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P2);
	byte expectedBytes = (byte) (buffer[ISO7816.OFFSET_LC]);
	if (expectedBytes < ObjectManager.RECORD_SIZE)
		ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
	boolean found = false; // Suppress compiler warning
	if (buffer[ISO7816.OFFSET_P1] == LIST_OPT_RESET)
		found = om.getFirstRecord(buffer, (short) 0);
	else if (buffer[ISO7816.OFFSET_P1] != LIST_OPT_NEXT)
		ISOException.throwIt(SW_INCORRECT_P1);
	else
		found = om.getNextRecord(buffer, (short) 0);
	if (found)
		apdu.setOutgoingAndSend((short) 0, (short) ObjectManager.RECORD_SIZE);
	else
		ISOException.throwIt(SW_SEQUENCE_END);
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:33,代码来源:CardEdge.java

示例10: ListKeys

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * This function returns a list of current keys and their properties including id, type,
 * size, partner, and access control. This function is initially called with the reset
 * sequence set for sequence type. The function only returns one object id at a time
 * and must be called in repetition until SW_SUCCESS is returned. 
 * 
 *  ins: 0x3A
 *  p1: 0x00 (reset and get first entry) or 0x01 (next entry)
 *  p2: 0x00 
 *  data: none
 *  return: [key_num(1b) | key_type(1b) | key_partner(1b) | key_size(2b) | key_ACL(6b)]
 */
private void ListKeys(APDU apdu, byte[] buffer) {
	// Checking P2
	if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
		ISOException.throwIt(SW_INCORRECT_P2);
	short expectedBytes = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
	if (expectedBytes != (short) 0x0B)
		ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
	if (buffer[ISO7816.OFFSET_P1] == LIST_OPT_RESET)
		key_it = (byte) 0;
	else if (buffer[ISO7816.OFFSET_P1] != LIST_OPT_NEXT)
		ISOException.throwIt(SW_INCORRECT_P1);
	while ((key_it < MAX_NUM_KEYS) && ((keys[key_it] == null) || !keys[key_it].isInitialized()))
		key_it++;
	if (key_it < MAX_NUM_KEYS) {
		Key key = keys[key_it];
		buffer[(short) 0] = key_it;
		buffer[(short) 1] = key.getType();// getKeyType(key);
		buffer[(short) 2] = (byte) 0xFF; // No partner information available
		Util.setShort(buffer, (short) 3, key.getSize());
		Util.arrayCopyNonAtomic(keyACLs, (short) (key_it * KEY_ACL_SIZE), buffer, (short) 5, KEY_ACL_SIZE);
		// Advance iterator
		key_it++;
		apdu.setOutgoingAndSend((short) 0, (short) (5 + KEY_ACL_SIZE));
	}
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:38,代码来源:CardEdge.java

示例11: getBIP32AuthentiKey

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * This function returns the authentikey public key (uniquely derived from the Bip32 seed).
 * The function returns the x-coordinate of the authentikey, self-signed.
 * The authentikey full public key can be recovered from the signature.
 * 
 *  ins: 0x73
 *  p1: 0x00 
 *  p2: 0x00 
 *  data: none
 *  return: [coordx_size(2b) | coordx | sig_size(2b) | sig]
 */
private void getBIP32AuthentiKey(APDU apdu, byte[] buffer){
	
	// check whether the seed is initialized
	if (!bip32_seeded)
		ISOException.throwIt(SW_BIP32_UNINITIALIZED_SEED);
	
	// compute the partial authentikey public key...
       keyAgreement.init(bip32_authentikey);
       short coordx_size = keyAgreement.generateSecret(Secp256k1.SECP256K1, Secp256k1.OFFSET_SECP256K1_G, (short) 65, buffer, (short)2); // compute x coordinate of public key as k*G
       Util.setShort(buffer, (short)0, coordx_size);
       // self signed public key
       sigECDSA.init(bip32_authentikey, Signature.MODE_SIGN);
       short sign_size= sigECDSA.sign(buffer, (short)0, (short)(coordx_size+2), buffer, (short)(coordx_size+4));
       Util.setShort(buffer, (short)(coordx_size+2), sign_size);
       
       // return x-coordinate of public key+signature
       // the client can recover full public-key from the signature or
       // by guessing the compression value () and verifying the signature... 
       // buffer= [coordx_size(2) | coordx | sigsize(2) | sig]
       apdu.setOutgoingAndSend((short) 0, (short)(coordx_size+sign_size+4));
	
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:34,代码来源:CardEdge.java

示例12: send_array

import javacard.framework.APDU; //导入方法依赖的package包/类
public static void send_array(byte[] array, short offset, short len) {
	// get buffer
	APDU apdu = APDU.getCurrentAPDU();
	// This method is failsafe.
	if ((short)(offset + len) > (short)array.length)
		len = (short) (array.length - offset);
	// Copy data
	Util.arrayCopyNonAtomic(array, offset, apdu.getBuffer(), (short)0, len);
	// Check if setOutgoing() has already been called
	if (apdu.getCurrentState() == APDU.STATE_OUTGOING) {
		apdu.setOutgoingLength(len);
		apdu.sendBytes((short)0, len);
	} else {
		apdu.setOutgoingAndSend((short)0, len);
	}
	// Exit normal code flow
	ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
 
开发者ID:martinpaljak,项目名称:esteid-applets,代码行数:19,代码来源:Pro.java

示例13: internalAuthenticate

import javacard.framework.APDU; //导入方法依赖的package包/类
private void internalAuthenticate(APDU apdu) {
  byte[] buffer = apdu.getBuffer();
  // PW1 with 0x82
  if (!pins[PIN_INDEX_PW1].isValidated() || !pinSubmitted[1]) {
    ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
  }
  short len = apdu.setIncomingAndReceive();
  if (len > (short) 102 || len != (buffer[ISO7816.OFFSET_LC] & 0xFF)) {
    ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
  }
  if (!authenticationKey.getPrivate().isInitialized()) {
    ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
  }
  cipherRSA.init(authenticationKey.getPrivate(), Cipher.MODE_ENCRYPT);
  cipherRSA.doFinal(buffer, ISO7816.OFFSET_CDATA, len, buffer, (short) 0);
  apdu.setOutgoingAndSend((short) 0, RSA_KEY_LENGTH_BYTES);
}
 
开发者ID:JavaCardOS,项目名称:FluffyPGP-Applet,代码行数:18,代码来源:Gpg.java

示例14: handleVerifyPin

import javacard.framework.APDU; //导入方法依赖的package包/类
private static void handleVerifyPin(APDU apdu) throws ISOException {
    byte[] buffer = apdu.getBuffer();
    if ((setup == TC.FALSE) || (setup != TC.TRUE)) {
        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
    }
    if (buffer[ISO7816.OFFSET_P1] == P1_GET_REMAINING_ATTEMPTS) {
     buffer[0] = walletPin.getTriesRemaining();
     apdu.setOutgoingAndSend((short)0, (short)1);
     return;
    }
    apdu.setIncomingAndReceive();
    if (buffer[ISO7816.OFFSET_LC] != walletPinSize) {
        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
    }
    Util.arrayFillNonAtomic(scratch256, (short)0, WALLET_PIN_SIZE, (byte)0xff);
    Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, scratch256, (short)0, walletPinSize);
    if (!walletPin.check(scratch256, (short)0, WALLET_PIN_SIZE)) {
        if (walletPin.getTriesRemaining() == 0) {
            reset();
        }
        ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
    }
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard,代码行数:24,代码来源:LedgerWalletApplet.java

示例15: test_EC_GEN

import javacard.framework.APDU; //导入方法依赖的package包/类
void test_EC_GEN(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();

    PM.check(PM.TRAP_EC_GEN_1);
    m_testPoint1.randomize();
    PM.check(PM.TRAP_EC_GEN_2);

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


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