本文整理汇总了Java中javacard.security.ECPrivateKey类的典型用法代码示例。如果您正苦于以下问题:Java ECPrivateKey类的具体用法?Java ECPrivateKey怎么用?Java ECPrivateKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ECPrivateKey类属于javacard.security包,在下文中一共展示了ECPrivateKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newKeyPair
import javacard.security.ECPrivateKey; //导入依赖的package包/类
static public KeyPair newKeyPair() {
KeyPair kp = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);
ECPrivateKey ecPrv = (ECPrivateKey) kp.getPrivate();
ECPublicKey ecPub = (ECPublicKey) kp.getPublic();
ecPrv.setFieldFP(p, (short) 0, (short) p.length);
ecPrv.setA(a, (short) 0, (short) a.length);
ecPrv.setB(b, (short) 0, (short) b.length);
ecPrv.setG(G, (short) 0, (short) G.length);
ecPrv.setR(r, (short) 0, (short) r.length);
ecPub.setFieldFP(p, (short) 0, (short) p.length);
ecPub.setA(a, (short) 0, (short) a.length);
ecPub.setB(b, (short) 0, (short) b.length);
ecPub.setG(G, (short) 0, (short) G.length);
ecPub.setR(r, (short) 0, (short) r.length);
return kp;
}
示例2: FIDOCCImplementation
import javacard.security.ECPrivateKey; //导入依赖的package包/类
public FIDOCCImplementation() {
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
scratch = JCSystem.makeTransientByteArray((short)128, JCSystem.CLEAR_ON_DESELECT);
//seed = new byte[64];
keyPair = new KeyPair(
(ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false),
(ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPrivate());
Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPublic());
// Initialize the unique seed for DRNG function
//random.generateData(seed, (short)0, (short)64);
// Initialize the unique seed for DRNG function
drngSeed1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false);
drngSeed2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false);
random.generateData(scratch, (short)0, (short)32);
drngSeed1.setKey(scratch, (short)0);
random.generateData(scratch, (short)0, (short)32);
drngSeed2.setKey(scratch, (short)0);
sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
// Initialize the unique keys for MAC function
macKey1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false);
macKey2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false);
random.generateData(scratch, (short)0, (short)16);
macKey1.setKey(scratch, (short)0);
random.generateData(scratch, (short)0, (short)16);
macKey2.setKey(scratch, (short)0);
// Initialize ecMultiplier
ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
}
示例3: 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;
}
示例4: FIDOStandalone
import javacard.security.ECPrivateKey; //导入依赖的package包/类
public FIDOStandalone() {
scratch = JCSystem.makeTransientByteArray((short)64, JCSystem.CLEAR_ON_DESELECT);
keyPair = new KeyPair(
(ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false),
(ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPrivate());
Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPublic());
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
// Initialize the unique wrapping key
chipKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false);
random.generateData(scratch, (short)0, (short)32);
chipKey.setKey(scratch, (short)0);
cipherEncrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);
cipherEncrypt.init(chipKey, Cipher.MODE_ENCRYPT, IV_ZERO_AES, (short)0, (short)IV_ZERO_AES.length);
cipherDecrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);
cipherDecrypt.init(chipKey, Cipher.MODE_DECRYPT, IV_ZERO_AES, (short)0, (short)IV_ZERO_AES.length);
}
示例5: 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;
}
示例6: newKeyPair
import javacard.security.ECPrivateKey; //导入依赖的package包/类
static public KeyPair newKeyPair() {
KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);
ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
ECPublicKey pubKey = (ECPublicKey) key.getPublic();
privKey.setFieldFP(q, (short) 0, (short) q.length);
privKey.setA(a, (short) 0, (short) a.length);
privKey.setB(b, (short) 0, (short) b.length);
privKey.setG(G, (short) 0, (short) G.length);
privKey.setR(r, (short) 0, (short) r.length);
pubKey.setFieldFP(q, (short) 0, (short) q.length);
pubKey.setA(a, (short) 0, (short) a.length);
pubKey.setB(b, (short) 0, (short) b.length);
pubKey.setG(G, (short) 0, (short) G.length);
pubKey.setR(r, (short) 0, (short) r.length);
return key;
}
示例7: newKeyPair
import javacard.security.ECPrivateKey; //导入依赖的package包/类
static public KeyPair newKeyPair() {
KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);
ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
ECPublicKey pubKey = (ECPublicKey) key.getPublic();
privKey.setFieldFP(p, (short) 0, (short) p.length);
privKey.setA(a, (short) 0, (short) a.length);
privKey.setB(b, (short) 0, (short) b.length);
privKey.setG(G, (short) 0, (short) G.length);
privKey.setR(r, (short) 0, (short) r.length);
pubKey.setFieldFP(p, (short) 0, (short) p.length);
pubKey.setA(a, (short) 0, (short) a.length);
pubKey.setB(b, (short) 0, (short) b.length);
pubKey.setG(G, (short) 0, (short) G.length);
pubKey.setR(r, (short) 0, (short) r.length);
return key;
}
示例8: newKeyPair
import javacard.security.ECPrivateKey; //导入依赖的package包/类
static public KeyPair newKeyPair() {
KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 320);
ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
ECPublicKey pubKey = (ECPublicKey) key.getPublic();
privKey.setFieldFP(q, (short) 0, (short) q.length);
privKey.setA(a, (short) 0, (short) a.length);
privKey.setB(b, (short) 0, (short) b.length);
privKey.setG(G, (short) 0, (short) G.length);
privKey.setR(r, (short) 0, (short) r.length);
pubKey.setFieldFP(q, (short) 0, (short) q.length);
pubKey.setA(a, (short) 0, (short) a.length);
pubKey.setB(b, (short) 0, (short) b.length);
pubKey.setG(G, (short) 0, (short) G.length);
pubKey.setR(r, (short) 0, (short) r.length);
return key;
}
示例9: 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);
}
}
示例10: ECCurve
import javacard.security.ECPrivateKey; //导入依赖的package包/类
/**
* Creates new curve object from provided parameters. Either copy of provided
* arrays is performed (bCopyArgs == true, input arrays can be reused later for other
* purposes) or arguments are directly stored (bCopyArgs == false, usable for fixed static arrays) .
* @param bCopyArgs if true, copy of arguments is created, otherwise reference is directly stored
* @param p_arr array with p
* @param a_arr array with a
* @param b_arr array with b
* @param G_arr array with base point G
* @param r_arr array with r
*/
public ECCurve(boolean bCopyArgs, byte[] p_arr, byte[] a_arr, byte[] b_arr, byte[] G_arr, byte[] r_arr) {
//ECCurve_initialize(p_arr, a_arr, b_arr, G_arr, r_arr);
this.KEY_LENGTH = (short) (p_arr.length * 8);
this.POINT_SIZE = (short) G_arr.length;
this.COORD_SIZE = (short) ((short) (G_arr.length - 1) / 2);
if (bCopyArgs) {
// Copy curve parameters into newly allocated arrays in EEPROM (will be only read, not written later => good performance even when in EEPROM)
this.p = new byte[(short) p_arr.length];
this.a = new byte[(short) a_arr.length];
this.b = new byte[(short) b_arr.length];
this.G = new byte[(short) G_arr.length];
this.r = new byte[(short) r_arr.length];
Util.arrayCopyNonAtomic(p_arr, (short) 0, p, (short) 0, (short) p.length);
Util.arrayCopyNonAtomic(a_arr, (short) 0, a, (short) 0, (short) a.length);
Util.arrayCopyNonAtomic(b_arr, (short) 0, b, (short) 0, (short) b.length);
Util.arrayCopyNonAtomic(G_arr, (short) 0, G, (short) 0, (short) G.length);
Util.arrayCopyNonAtomic(r_arr, (short) 0, r, (short) 0, (short) r.length);
}
else {
// No allocation, store directly provided arrays
this.p = p_arr;
this.a = a_arr;
this.b = b_arr;
this.G = G_arr;
this.r = r_arr;
}
// We will not modify values of p/a/b during the lifetime of curve => allocate helper bignats directly from the array
// Additionally, these Bignats will be only read from so Bignat_Helper can be null (saving need to pass as argument to ECCurve)
this.pBN = new Bignat(this.p, null);
this.aBN = new Bignat(this.a, null);
this.bBN = new Bignat(this.b, null);
this.disposable_pair = this.newKeyPair(null);
this.disposable_priv = (ECPrivateKey) this.disposable_pair.getPrivate();
}
示例11: setG
import javacard.security.ECPrivateKey; //导入依赖的package包/类
/**
* Set new G for this curve. Also updates all dependent key values.
* @param newG buffer with new G
* @param newGOffset start offset within newG
* @param newGLen length of new G
*/
public void setG(byte[] newG, short newGOffset, short newGLen) {
Util.arrayCopyNonAtomic(newG, newGOffset, G, (short) 0, newGLen);
this.disposable_pair = this.newKeyPair(this.disposable_pair);
this.disposable_priv = (ECPrivateKey) this.disposable_pair.getPrivate();
this.disposable_priv.setG(newG, newGOffset, newGLen);
}
示例12: PRNGTest
import javacard.security.ECPrivateKey; //导入依赖的package包/类
private PRNGTest() {
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
drngAESKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
KeyBuilder.LENGTH_AES_128, false);
tmp = JCSystem.makeTransientByteArray((short) 40,
JCSystem.CLEAR_ON_DESELECT);
random.generateData(tmp, (short) 0, (short) 16);
drngAESKey.setKey(tmp, (short) 0);
scratch = JCSystem.makeTransientByteArray((short) 32,
JCSystem.CLEAR_ON_DESELECT);
keyPair = new KeyPair((ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256,false),
(ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPrivate());
Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPublic());
// Initialize the unique key for DRNG function (AES CMAC)
drngKey1 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
KeyBuilder.LENGTH_AES_128, false);
drngKey2 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
KeyBuilder.LENGTH_AES_128, false);
random.generateData(scratch, (short) 0, (short) 32);
drngKey1.setKey(scratch, (short) 0);
drngKey2.setKey(scratch, (short) 16);
drng1 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
drng1.init(drngKey1, Signature.MODE_SIGN);
drng2 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
drng2.init(drngKey2, Signature.MODE_SIGN);
// Initialize the unique key for MAC function (AES CMAC)
macKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
KeyBuilder.LENGTH_AES_128, false);
random.generateData(scratch, (short) 0, (short) 16);
macKey.setKey(scratch, (short) 0);
cmacSign = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
cmacSign.init(macKey, Signature.MODE_SIGN);
cmacVerify = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
cmacVerify.init(macKey, Signature.MODE_VERIFY);
// Initialize ecMultiplier
ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
}
示例13: allocate
import javacard.security.ECPrivateKey; //导入依赖的package包/类
static void allocate(ECCurve curve) {
theCurve = curve;
disposable_pair = theCurve.newKeyPair(disposable_pair);
disposable_priv = (ECPrivateKey) disposable_pair.getPrivate();
disposable_pair.genKeyPair();
disposable_pairDecrypt = theCurve.newKeyPair(disposable_pairDecrypt);
disposable_privDecrypt = (ECPrivateKey) disposable_pairDecrypt.getPrivate();
disposable_pairDecrypt.genKeyPair();
TempBuffer65 = JCSystem.makeTransientByteArray(Consts.SHARE_DOUBLE_SIZE_CARRY, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
pointTpmArray = JCSystem.makeTransientByteArray(Consts.SHARE_DOUBLE_SIZE_CARRY, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
pt_A_arr = JCSystem.makeTransientByteArray(Consts.SHARE_DOUBLE_SIZE_CARRY, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
}
示例14: ECCurve
import javacard.security.ECPrivateKey; //导入依赖的package包/类
/**
* Creates new curve object from provided parameters. Either copy of provided
* arrays is performed (bCopyArgs == true, input arrays can be reused later for other
* purposes) or arguments are directly stored (bCopyArgs == false, usable for fixed static arrays) .
* @param bCopyArgs if true, copy of arguments is created, otherwise reference is directly stored
* @param p_arr array with p
* @param a_arr array with a
* @param b_arr array with b
* @param G_arr array with base point G
* @param r_arr array with r
*/
public ECCurve(boolean bCopyArgs, byte[] p_arr, byte[] a_arr, byte[] b_arr, byte[] G_arr, byte[] r_arr) {
//ECCurve_initialize(p_arr, a_arr, b_arr, G_arr, r_arr);
this.KEY_LENGTH = (short) (p_arr.length * 8);
this.POINT_SIZE = (short) G_arr.length;
this.COORD_SIZE = (short) ((short) (G_arr.length - 1) / 2);
if (bCopyArgs) {
// Copy curve parameters into newly allocated arrays in EEPROM (will be only read, not written later => good performance even when in EEPROM)
this.p = new byte[(short) p_arr.length];
this.a = new byte[(short) a_arr.length];
this.b = new byte[(short) b_arr.length];
this.G = new byte[(short) G_arr.length];
this.r = new byte[(short) r_arr.length];
Util.arrayCopyNonAtomic(p_arr, (short) 0, p, (short) 0, (short) p.length);
Util.arrayCopyNonAtomic(a_arr, (short) 0, a, (short) 0, (short) a.length);
Util.arrayCopyNonAtomic(b_arr, (short) 0, b, (short) 0, (short) b.length);
Util.arrayCopyNonAtomic(G_arr, (short) 0, G, (short) 0, (short) G.length);
Util.arrayCopyNonAtomic(r_arr, (short) 0, r, (short) 0, (short) r.length);
}
else {
// No allocation, store directly provided arrays
this.p = p_arr;
this.a = a_arr;
this.b = b_arr;
this.G = G_arr;
this.r = r_arr;
}
// We will not modify values of p/a/b during the lifetime of curve => allocate helper bignats directly from the array
// Additionally, these Bignats will be only read from so Bignat_Helper can be null (saving need to pass as argument to ECCurve)
this.pBN = new Bignat(this.p, null);
this.aBN = new Bignat(this.a, null);
this.bBN = new Bignat(this.b, null);
this.disposable_pair = this.newKeyPair(null);
this.disposable_priv = (ECPrivateKey) this.disposable_pair.getPrivate();
}
示例15: 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);
}