本文整理汇总了Java中javacard.security.ECPrivateKey.setS方法的典型用法代码示例。如果您正苦于以下问题:Java ECPrivateKey.setS方法的具体用法?Java ECPrivateKey.setS怎么用?Java ECPrivateKey.setS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.security.ECPrivateKey
的用法示例。
在下文中一共展示了ECPrivateKey.setS方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrap
import javacard.security.ECPrivateKey; //导入方法依赖的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;
}
示例2: unwrap
import javacard.security.ECPrivateKey; //导入方法依赖的package包/类
public boolean unwrap(byte[] keyHandle, short keyHandleOffset, short keyHandleLength, byte[] applicationParameter, short applicationParameterOffset, ECPrivateKey unwrappedPrivateKey) {
// Verify
cipherDecrypt.doFinal(keyHandle, keyHandleOffset, (short)64, keyHandle, keyHandleOffset);
deinterleave(keyHandle, keyHandleOffset, scratch, (short)0, scratch, (short)32, (short)32);
if (!FIDOUtils.compareConstantTime(applicationParameter, applicationParameterOffset, scratch, (short)0, (short)32)) {
Util.arrayFillNonAtomic(scratch, (short)32, (short)32, (byte)0x00);
Util.arrayFillNonAtomic(keyHandle, keyHandleOffset, (short)64, (byte)0x00);
return false;
}
Util.arrayFillNonAtomic(keyHandle, keyHandleOffset, (short)64, (byte)0x00);
if (unwrappedPrivateKey != null) {
unwrappedPrivateKey.setS(scratch, (short)32, (short)32);
}
Util.arrayFillNonAtomic(scratch, (short)32, (short)32, (byte)0x00);
return true;
}
示例3: LedgerWalletApplet
import javacard.security.ECPrivateKey; //导入方法依赖的package包/类
public LedgerWalletApplet(byte[] parameters, short parametersOffset, byte parametersLength) {
BCDUtils.init();
TC.init();
Crypto.init();
Transaction.init();
Bip32Cache.init();
Keycard.init();
limits = new byte[LIMIT_LAST];
scratch256 = JCSystem.makeTransientByteArray((short)256, JCSystem.CLEAR_ON_DESELECT);
transactionPin = new OwnerPIN(TRANSACTION_PIN_ATTEMPTS, TRANSACTION_PIN_SIZE);
walletPin = new OwnerPIN(WALLET_PIN_ATTEMPTS, WALLET_PIN_SIZE);
secondaryPin = new OwnerPIN(SECONDARY_PIN_ATTEMPTS, SECONDARY_PIN_SIZE);
masterDerived = new byte[64];
chipKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false);
trustedInputKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false);
developerKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false);
try {
pairingKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false);
}
catch(Exception e) {
}
reset();
if (parametersLength != 0) {
attestationPrivate = (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false);
attestationPublic = new byte[65];
Secp256k1.setCommonCurveParameters(attestationPrivate);
attestationPrivate.setS(parameters, parametersOffset, (short)32);
parametersOffset += (short)32;
attestationSignature = new byte[parameters[(short)(parametersOffset + 1)] + 2];
Util.arrayCopy(parameters, parametersOffset, attestationSignature, (short)0, (short)attestationSignature.length);
}
}
示例4: GenerateExampleBackdooredKeyPair
import javacard.security.ECPrivateKey; //导入方法依赖的package包/类
/**
* Generates intentionally insecure private key to demonstrate behaviour when
* some participants are malicious. Private key bytes are all 0x55 ... 0x55
*/
void GenerateExampleBackdooredKeyPair() {
state.CheckAllowedFunction(StateModel.FNC_QuorumContext_GenerateExampleBackdooredKeyPair);
// If enabled, key is not generated randomly as required per protocol, but fixed to vulnerable value instead
ECPublicKey pub = (ECPublicKey) pair.getPublic();
ECPrivateKey priv = (ECPrivateKey) pair.getPrivate();
// Set "backdoored" (known) private key - all 0x55 ... 0x55
priv.setS(privbytes_backdoored, (short) 0, (short) privbytes_backdoored.length);
((ECPrivateKey) pair.getPrivate()).getS(x_i_Bn, (short) 0);
// Compute and set corresponding public key (to backdoored private one)
cryptoOps.placeholder.ScalarMultiplication(cryptoOps.GenPoint, privbytes_backdoored, cryptoOps.tmp_arr);
pub.setW(cryptoOps.tmp_arr, (short) 0, (short) 65);
}
示例5: setParameter
import javacard.security.ECPrivateKey; //导入方法依赖的package包/类
/**
* @param key
* @param param
* @param data
* @param offset
* @param length
* @return
*/
public short setParameter(KeyPair keypair, byte key, short param, byte[] data, short offset, short length) {
try {
sw = AppletUtil.keypairCheck(keypair);
ECPublicKey ecPublicKey = (ECPublicKey) keypair.getPublic();
ECPrivateKey ecPrivateKey = (ECPrivateKey) keypair.getPrivate();
switch (param) {
case EC_Consts.PARAMETER_FP:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldFP(data, offset, length);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldFP(data, offset, length);
break;
case EC_Consts.PARAMETER_F2M:
if (length == 4) {
short i = Util.makeShort(data[(short) (offset + 2)], data[(short) (offset + 3)]);
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i);
} else if (length == 8) {
short i1 = Util.makeShort(data[(short) (offset + 2)], data[(short) (offset + 3)]);
short i2 = Util.makeShort(data[(short) (offset + 4)], data[(short) (offset + 5)]);
short i3 = Util.makeShort(data[(short) (offset + 6)], data[(short) (offset + 7)]);
// if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i1, i2, i3);
// if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i1, i2, i3);
// TODO: fix this, ^^ fails on jcardsim, but is up to spec
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i3, i2, i1);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i3, i2, i1);
} else {
sw = ISO7816.SW_UNKNOWN;
}
break;
case EC_Consts.PARAMETER_A:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setA(data, offset, length);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setA(data, offset, length);
break;
case EC_Consts.PARAMETER_B:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setB(data, offset, length);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setB(data, offset, length);
break;
case EC_Consts.PARAMETER_G:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setG(data, offset, length);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setG(data, offset, length);
break;
case EC_Consts.PARAMETER_R:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setR(data, offset, length);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setR(data, offset, length);
break;
case EC_Consts.PARAMETER_K:
short k = 0;
if (length > 2 || length <= 0) {
sw = ISO7816.SW_UNKNOWN;
break;
} else if (length == 2) {
k = Util.getShort(data, offset);
} else if (length == 1) {
k = data[offset];
}
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setK(k);
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setK(k);
break;
case EC_Consts.PARAMETER_S:
if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setS(data, offset, length);
break;
case EC_Consts.PARAMETER_W:
if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setW(data, offset, length);
break;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
} catch (CardRuntimeException ce) {
sw = ce.getReason();
}
return sw;
}
示例6: GeneratePrivateKeyECFP
import javacard.security.ECPrivateKey; //导入方法依赖的package包/类
private void GeneratePrivateKeyECFP(byte[] buffer){
byte prv_key_nb = buffer[ISO7816.OFFSET_P1];
if ((prv_key_nb < 0) || (prv_key_nb >= MAX_NUM_KEYS))
ISOException.throwIt(SW_INCORRECT_P1);
short key_size = Util.getShort(buffer, OFFSET_GENKEY_SIZE);
byte options = buffer[OFFSET_GENKEY_OPTIONS];
ECPrivateKey prv_key = (ECPrivateKey) getKey(prv_key_nb, KeyBuilder.TYPE_EC_FP_PRIVATE, key_size);
/* If we're going to overwrite a keyPair's contents, check ACL */
if (prv_key.isInitialized() && !authorizeKeyOp(prv_key_nb,ACL_WRITE))
ISOException.throwIt(SW_UNAUTHORIZED);
/* Store private key ACL */
Util.arrayCopy(buffer, OFFSET_GENKEY_PRV_ACL, keyACLs, (short) (prv_key_nb * KEY_ACL_SIZE), KEY_ACL_SIZE);
if (randomData == null)
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
switch (options) {
case OPT_DEFAULT:
// As default params were specified, we have to clear the public key
// if already initialized, otherwise their params would be used.
if (prv_key.isInitialized())
prv_key.clearKey();
break;
case OPT_EC_SECP256k1:
// Bitcoin uses 256-bit keysize!
if (key_size!=256)
ISOException.throwIt(SW_INVALID_PARAMETER);
// Satochip default is secp256k1 (over Fp)
Secp256k1.setCommonCurveParameters(prv_key);
// prv_key.setFieldFP( SECP256K1_P, (short)0, (short)SECP256K1_P.length);
// prv_key.setA( SECP256K1_a, (short)0, (short)SECP256K1_a.length);
// prv_key.setB( SECP256K1_b, (short)0, (short)SECP256K1_b.length);
// prv_key.setG( SECP256K1_G, (short)0, (short)SECP256K1_G.length);
// prv_key.setR( SECP256K1_R, (short)0, (short)SECP256K1_R.length);
// prv_key.setK( SECP256K1_K);
// Set secret value from random
randomData.generateData(recvBuffer,(short)0,(short)(key_size/8));
prv_key.setS(recvBuffer, (short)0, (short)(key_size/8));
Util.arrayFillNonAtomic(recvBuffer, (short)0, (short)(key_size/8), (byte)0);
break;
default:
ISOException.throwIt(SW_INVALID_PARAMETER);
}
}