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


Java Util.getShort方法代码示例

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


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

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

示例2: GetOperationParamsOffset

import javacard.framework.Util; //导入方法依赖的package包/类
short GetOperationParamsOffset(byte operationCode, APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short dataLen = apdu.getIncomingLength();
    // Check correctness of basic structure and expected operation
    short offset = ISO7816.OFFSET_CDATA;
    if (apdubuf[offset] != Consts.TLV_TYPE_MPCINPUTPACKET) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE);
    offset++;
    short packetLen = Util.getShort(apdubuf, offset);
    if (packetLen < 1 || packetLen > dataLen) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE); // at least 1 byte of packet content required for operationCode
    offset += 2;
    if (apdubuf[offset] != operationCode) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE);

    return offset;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:15,代码来源:MPCApplet.java

示例3: Quorum_SetupNew

import javacard.framework.Util; //导入方法依赖的package包/类
void Quorum_SetupNew(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    
    short paramsOffset = GetOperationParamsOffset(Consts.INS_QUORUM_SETUP_NEW, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_SetupNew);
    // Extract function parameters
    short numPlayers = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SETUPNEWQUORUM_NUMPLAYERS_OFFSET));
    short thisPlayerIndex = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SETUPNEWQUORUM_THISPLAYERINDEX_OFFSET));
    quorumCtx.SetupNew(numPlayers, thisPlayerIndex);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:14,代码来源:MPCApplet.java

示例4: KeyGen_StorePublicKey

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Verify the validity of Y’s elements against their previous commitments KeyGen_StoreCommitment().
 * If one or more commitments fail the verification then the member infers that an error (either intentional or
 * unintentional) occurred and the protocol is terminated.
 * @param apdu 
 */
void KeyGen_StorePublicKey(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short len = apdu.getIncomingLength();

    short paramsOffset = GetOperationParamsOffset(Consts.INS_KEYGEN_STORE_PUBKEY, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_SetYs);
    // Store provided public key 
    short playerId = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PLAYERID_OFFSET));
    short pubKeyLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEYLENGTH_OFFSET));
    quorumCtx.SetYs(playerId, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEY_OFFSET), pubKeyLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:21,代码来源:MPCApplet.java

示例5: EncryptData

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * For encryption, we use the Elliptic Curve ElGamal scheme 
 * (Algorithm 4.4). This operation does not use the secret key, and can be
 * performed directly on the host, or remotely by any party holding the
 * public key, hence there is no need to perform it in a distributed manner.
 * @param apdu 
 */
void EncryptData(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short paramsOffset = GetOperationParamsOffset(Consts.INS_ENCRYPT, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_Encrypt);
    short dataLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_ENCRYPT_DATALENGTH_OFFSET));
    dataLen = quorumCtx.Encrypt(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_ENCRYPT_DATA_OFFSET), dataLen, apdubuf);
    apdu.setOutgoingAndSend((short) 0, dataLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:19,代码来源:MPCApplet.java

示例6: DecryptData

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Distributed data decryption (Algorithm 4.5). All KeyGen_xxx must be executed before.
 * @param apdu 
 */
void DecryptData(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short paramsOffset = GetOperationParamsOffset(Consts.INS_DECRYPT, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization - is caller allowed to ask for decryption? 
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_DecryptShare);

    short dataLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_DECRYPT_DATALENGTH_OFFSET));
    dataLen = quorumCtx.DecryptShare(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_DECRYPT_DATA_OFFSET), dataLen, apdubuf);
    // TODO: encrypt result under host public key and sign by card's key
    apdu.setOutgoingAndSend((short) 0, dataLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:18,代码来源:MPCApplet.java

示例7: Sign_RetrieveRandomRi

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * First part of distributed signature scheme (Algorithm 4.7). All KeyGen_xxx must be executed
 * before. 
 * @apdu input apdu
 */
void Sign_RetrieveRandomRi(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short paramsOffset = GetOperationParamsOffset(Consts.INS_SIGN_RETRIEVE_RI, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_Sign_RetrieveRandomRi);
    
    short counter = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SIGNRETRIEVERI_COUNTER_OFFSET));
    short dataLen = quorumCtx.Sign_RetrieveRandomRi(counter, apdubuf);
    apdu.setOutgoingAndSend((short) 0, dataLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:18,代码来源:MPCApplet.java

示例8: Sign

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Second part of distributed signature scheme (Algorithm 4.7). All
 * KeyGen_xxx must be executed before.
 *
 * @apdu input data
 */
void Sign(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short paramsOffset = GetOperationParamsOffset(Consts.INS_SIGN, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_Sign);

    m_cryptoOps.temp_sign_counter.from_byte_array((short) 2, (short) 0, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SIGN_COUNTER_OFFSET));
    short dataLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SIGN_DATALENGTH_OFFSET));
    dataLen = quorumCtx.Sign(m_cryptoOps.temp_sign_counter, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_SIGN_DATA_OFFSET), dataLen, apdubuf, (short) 0);
    apdu.setOutgoingAndSend((short) 0, dataLen); //Send signature share 
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:20,代码来源:MPCApplet.java

示例9: decodeLengthField

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * \brief Decode the length field of a TLV-entry.
 *
 * The length field itself can be 1, 2 or 3 bytes long:
 * 	- If the length is between 0 and 127, it is 1 byte long.
 * 	- If the length is between 128 and 255, it is 2 bytes long.
 *		The first byte is 0x81 to indicate this.
 *	- If the length is between 256 and 65535, it is 3 bytes long.
 *		The first byte is 0x82, the following 2 contain the actual length.
 *		Note: Only lengths up to 0x7FFF (32767) are supported here, because a short in Java is signed.
 *
 * \param buf The buffer containing the length field.
 *
 * \param offset The offset at where the length field starts.
 *
 * \param length The length of the buffer (buf). This is to prevent that the index gets out of bounds.
 *
 * \return The (positive) length encoded by the length field, or in case of an error, -1.
 *
 * \throw InvalidArgumentsException If offset is too big for a signed Java short
 *                                  If the first byte of the length field is invalid
 */
public static short decodeLengthField(byte[] buf, short offset) {
    if(buf[offset] == (byte)0x82) { // 256..65535
        // Check for short overflow
        // (In Java, a short is signed: positive values are 0000..7FFF)
        if(buf[(short)(offset+1)] < 0) { // 80..FF
            return -1;
        }
        return Util.getShort(buf, (short)(offset+1));
    } else if(buf[offset] == (byte)0x81) {
        return (short) ( 0x00FF & buf[(short)(offset+1)]);
    } else if(buf[offset] > 0) { // 00..7F
        return (short) ( 0x007F & buf[offset]);
    } else {
        return -1;
    }
}
 
开发者ID:petrs,项目名称:hotp_via_ndef,代码行数:39,代码来源:UtilTLV.java

示例10: GetTargetQuorumContext

import javacard.framework.Util; //导入方法依赖的package包/类
/**
 * Returns target quorum based on info from input apdu
 * @param apdubuf
 * @param paramsStartOffset
 * @return 
 */
QuorumContext GetTargetQuorumContext(byte[] apdubuf, short paramsStartOffset) {
    short ctxIndex = Util.getShort(apdubuf, (short) (paramsStartOffset + Consts.PACKET_PARAMS_CTXINDEX_OFFSET));
    if (ctxIndex < 0 || ctxIndex >= (short) m_quorums.length) ISOException.throwIt(Consts.SW_INVALIDQUORUMINDEX);
    return m_quorums[ctxIndex];
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:12,代码来源:MPCApplet.java


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