• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ECPrivateKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ECPrivateKey类属于javacard.security包,在下文中一共展示了ECPrivateKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:SecP256k1.java


示例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);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:38,代码来源:FIDOCCImplementation.java


示例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;
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:21,代码来源:FIDOCCImplementation.java


示例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);
}
 
开发者ID:LedgerHQ,项目名称:ledger-u2f-javacard,代码行数:18,代码来源:FIDOStandalone.java


示例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;
}
 
开发者ID:LedgerHQ,项目名称:ledger-u2f-javacard,代码行数:17,代码来源:FIDOStandalone.java


示例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;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:Frp256v1.java


示例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;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:SecP256r1.java


示例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;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:BrainpoolP320r1.java


示例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);
    }
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard,代码行数:33,代码来源:LedgerWalletApplet.java


示例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();
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:50,代码来源:ECCurve.java


示例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);  
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:13,代码来源:ECCurve.java


示例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);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:52,代码来源:PRNGTest.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:14,代码来源:ECPointBase.java


示例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();
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:50,代码来源:jcmathlib.java


示例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);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:18,代码来源:QuorumContext.java


示例16: generateKeyAndWrap

import javacard.security.ECPrivateKey; //导入依赖的package包/类
public short generateKeyAndWrap(byte[] applicationParameter, short applicationParameterOffset, ECPrivateKey generatedPrivateKey, byte[] publicKey, short publicKeyOffset, byte[] keyHandle, short keyHandleOffset) {
    // Generate a new pair
    keyPair.genKeyPair();
    // Copy public key
    ((ECPublicKey)keyPair.getPublic()).getW(publicKey, publicKeyOffset);
    // Wrap keypair and application parameters
    ((ECPrivateKey)keyPair.getPrivate()).getS(scratch, (short)0);
    interleave(applicationParameter, applicationParameterOffset, scratch, (short)0, keyHandle, keyHandleOffset, (short)32);
    cipherEncrypt.doFinal(keyHandle, keyHandleOffset, (short)64, keyHandle, keyHandleOffset);
    Util.arrayFillNonAtomic(scratch, (short)0, (short)32, (byte)0x00);
    return (short)64;
}
 
开发者ID:LedgerHQ,项目名称:ledger-u2f-javacard,代码行数:13,代码来源:FIDOStandalone.java


示例17: CardApplet

import javacard.security.ECPrivateKey; //导入依赖的package包/类
/**
   * Allocate memory for the data on the card and initialise the fields
   */
  public CardApplet() {
// Get instances of cryptographic operations
agreement = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN, false);

// Build keys
privKey = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KEY_LENGTH, false);
pubKey = (ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KEY_LENGTH, false);
blindKeyValue = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KEY_LENGTH, false);
blindKeyPoint = (ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KEY_LENGTH, false);
public_key = new byte[POINT_SIZE];

// Construct key pairs
keyPair = new KeyPair(pubKey, privKey);
blindKeyPair = new KeyPair(blindKeyPoint, blindKeyValue);

// Construct attribute storage
attribute_id = new byte[ATTRIBUTE_COUNT];
Util.arrayFillNonAtomic(attribute_id, _0, ATTRIBUTE_COUNT, (byte) 0x00);
attribute_length = new short[ATTRIBUTE_COUNT];
attribute_signature = new Object[ATTRIBUTE_COUNT];
attribute_value = new Object[ATTRIBUTE_COUNT];
for (short i = 0; i < ATTRIBUTE_COUNT; i++) {
    attribute_signature[i] = new byte[POINT_SIZE];
    attribute_value[i] = new byte[ATTRIBUTE_SIZE];
}

// Some temporary space
point = JCSystem.makeTransientByteArray((short) (POINT_SIZE*2), JCSystem.CLEAR_ON_RESET);
  }
 
开发者ID:credentials,项目名称:sbcred_javacard,代码行数:33,代码来源:CardApplet.java


示例18: handleAirgapKeyAgreement

import javacard.security.ECPrivateKey; //导入依赖的package包/类
private static void handleAirgapKeyAgreement(APDU apdu) throws ISOException {
    short offset = (short)0;
    byte[] buffer = apdu.getBuffer();
    apdu.setIncomingAndReceive();
    checkAirgapPersonalizationAvailable();
    if (buffer[ISO7816.OFFSET_P1] == P1_INITIATE_PAIRING) {
        if (buffer[ISO7816.OFFSET_LC] != (byte)65) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }
        pairingDone = false;
        Crypto.keyPair.genKeyPair();
        Crypto.keyAgreement.init((ECPrivateKey)Crypto.keyPair.getPrivate());
        Crypto.keyAgreement.generateSecret(buffer, ISO7816.OFFSET_CDATA, (short)65, scratch256, (short)0);
        pairingKey.setKey(scratch256, (short)0);
        ((ECPublicKey)Crypto.keyPair.getPublic()).getW(buffer, offset);
        offset += (short)65;
        Crypto.signature.init(attestationPrivate, Signature.MODE_SIGN);
        Crypto.signature.sign(buffer, (short)0, (short)65, buffer, offset);
        offset += (short)(buffer[(short)(offset + 1)] + 2);
        apdu.setOutgoingAndSend((short)0, offset);
    }
    else
    if (buffer[ISO7816.OFFSET_P1] == P1_CONFIRM_PAIRING) {
        if (buffer[ISO7816.OFFSET_LC] != (byte)32) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }
        Crypto.initCipherAES(pairingKey, false);
        Crypto.blobEncryptDecryptAES.doFinal(buffer, ISO7816.OFFSET_CDATA, (short)32, scratch256, (short)0);
        pairingKey.setKey(scratch256, (short)0);
        pairingDone = true;
    }
    else {
        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
    }
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard,代码行数:36,代码来源:LedgerWalletApplet.java


示例19: SignVerifyECDSA

import javacard.security.ECPrivateKey; //导入依赖的package包/类
public static boolean SignVerifyECDSA(ECPrivateKey privateKey, ECPublicKey publicKey, Signature signEngine, byte[] tmpSignArray) {
    signEngine.init(privateKey, Signature.MODE_SIGN);
    short signLen = signEngine.sign(msg, (short) 0, (short) msg.length, tmpSignArray, (short) 0);
    signEngine.init(publicKey, Signature.MODE_VERIFY);
    return signEngine.verify(msg, (short) 0, (short) msg.length, tmpSignArray, (short) 0, signLen);
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:7,代码来源:ECPoint.java


示例20: generateKeyAndWrap

import javacard.security.ECPrivateKey; //导入依赖的package包/类
public short generateKeyAndWrap(byte[] applicationParameter, short applicationParameterOffset, ECPrivateKey generatedPrivateKey, byte[] publicKey, short publicKeyOffset, byte[] keyHandle, short keyHandleOffset) {
    // Generate 48 byte nonce
	random.generateData(keyHandle, keyHandleOffset, (short) 48);
	
	//Generate PrivKey 
	generatePrivateKey(applicationParameter, applicationParameterOffset, keyHandle, keyHandleOffset);

	
	// Set private Key S, before generating Public Key
	((ECPrivateKey)keyPair.getPrivate()).setS(scratch, (short) 0, (short) 32);
	
	generatePublicKeyPoint(publicKey, publicKeyOffset);
	
	// erase Private Key
	Util.arrayFillNonAtomic(scratch, (short)0, (short)32, (byte)0x00);
	((ECPrivateKey)keyPair.getPrivate()).setS(scratch, (short) 0, (short) 32);
	
	calcMAC(applicationParameter, applicationParameterOffset, keyHandle, keyHandleOffset);
	Util.arrayCopyNonAtomic(scratch, (short) 0, keyHandle, (short) (keyHandleOffset + 32), (short) 32);
    
    return (short)64;
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:23,代码来源:FIDOCCImplementation.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Generics类代码示例发布时间:2022-05-22
下一篇:
Java ByteBufferOutputStream类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap