本文整理汇总了Java中javacard.security.KeyPair.ALG_EC_FP属性的典型用法代码示例。如果您正苦于以下问题:Java KeyPair.ALG_EC_FP属性的具体用法?Java KeyPair.ALG_EC_FP怎么用?Java KeyPair.ALG_EC_FP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javacard.security.KeyPair
的用法示例。
在下文中一共展示了KeyPair.ALG_EC_FP属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newKeyPair
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: GenerateKeyPair
/**
* This function generates a key pair using the card's on board key generation
* process. The key number (or numbers if a key pair is being generated), algorithm
* type, and algorithm parameters are specified by arguments P1 and P2 and by
* provided DATA.
*
* ins: 0x30
* p1: private key number (0x00-0x0F)
* p2: public key number (0x00-0x0F)
* data: [Key Generation Parameters]
* return: none
*/
private void GenerateKeyPair(APDU apdu, byte[] buffer) {
short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
if (bytesLeft != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
byte alg_id = buffer[OFFSET_GENKEY_ALG];
switch (alg_id) {
case KeyPair.ALG_RSA:
case KeyPair.ALG_RSA_CRT:
GenerateKeyPairRSA(buffer);
break;
case KeyPair.ALG_EC_FP:
//GenerateKeyPairECFP(buffer);
GeneratePrivateKeyECFP(buffer);
break;
default:
ISOException.throwIt(SW_INCORRECT_ALG);
}
}
示例3: newKeyPair
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;
}
示例4: newKeyPair
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;
}
示例5: newKeyPair
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;
}
示例6: getDescription
@Override
public String getDescription() {
String field = keyClass == KeyPair.ALG_EC_FP ? "ALG_EC_FP" : "ALG_EC_F2M";
String key;
if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
key = "both keypairs";
} else {
key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
}
return String.format("Allocated %s %db %s", key, keyLength, field);
}
示例7: setup
@Override
public void setup(CardMngr cardManager) {
/* Do the default tests with the public keys set to provided smallorder keys
* over composite order curves. Essentially small subgroup attacks.
* These should fail, the curves aren't safe so that if the computation with
* a small order public key succeeds the private key modulo the public key order
* is revealed.
*/
Map<String, EC_Key> keys = dataStore.getObjects(EC_Key.class, "composite");
for (EC_Key key : keys.values()) {
EC_Curve curve = dataStore.getObject(EC_Curve.class, key.getCurve());
if (cfg.namedCurve != null && !(key.getCurve().startsWith(cfg.namedCurve) || key.getCurve().equals(cfg.namedCurve))) {
continue;
}
if (curve.getField() == KeyPair.ALG_EC_FP && !cfg.primeField || curve.getField() == KeyPair.ALG_EC_F2M && !cfg.binaryField) {
continue;
}
if ((curve.getBits() == cfg.bits || cfg.all)) {
tests.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), ExpectedValue.SUCCESS));
tests.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), ExpectedValue.ANY));
tests.add(new Test.Simple(new Command.Generate(cardManager, ECTesterApplet.KEYPAIR_LOCAL), ExpectedValue.ANY));
Command ecdhCommand = new Command.ECDH_direct(cardManager, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_NONE, EC_Consts.KA_ECDH, key.flatten());
tests.add(new Test.Simple(ecdhCommand, ExpectedValue.FAILURE, "Card correctly rejected to do ECDH over a composite order curve.", "Card incorrectly does ECDH over a composite order curve, leaks bits of private key."));
tests.add(new Test.Simple(new Command.Cleanup(cardManager), ExpectedValue.ANY));
}
}
}
示例8: setCurve
/**
*
* @param keypair
* @param key
* @param curve
* @param params
* @param buffer
* @param offset
* @return
*/
public short setCurve(KeyPair keypair, byte key, byte curve, short params, byte[] buffer, short offset) {
byte alg = EC_Consts.getCurveType(curve);
sw = ISO7816.SW_NO_ERROR;
if (params == EC_Consts.PARAMETERS_NONE) {
return sw;
}
short length;
//handle fp and f2m differently, as a FP KeyPair doesnt contain a F2M field and vice versa.
if (alg == KeyPair.ALG_EC_FP && (params & EC_Consts.PARAMETER_FP) != 0) {
length = EC_Consts.getCurveParameter(curve, EC_Consts.PARAMETER_FP, buffer, offset);
sw = setParameter(keypair, key, EC_Consts.PARAMETER_FP, buffer, offset, length);
} else if (alg == KeyPair.ALG_EC_F2M && (params & EC_Consts.PARAMETER_F2M) != 0) {
length = EC_Consts.getCurveParameter(curve, EC_Consts.PARAMETER_F2M, buffer, offset);
sw = setParameter(keypair, key, EC_Consts.PARAMETER_F2M, buffer, offset, length);
}
if (sw != ISO7816.SW_NO_ERROR) return sw;
//go through all params
short paramMask = EC_Consts.PARAMETER_A;
while (paramMask <= EC_Consts.PARAMETER_S) {
short masked = (short) (paramMask & params);
if (masked != 0) {
length = EC_Consts.getCurveParameter(curve, masked, buffer, offset);
sw = setParameter(keypair, key, masked, buffer, offset, length);
if (sw != ISO7816.SW_NO_ERROR) break;
}
paramMask = (short) (paramMask << 1);
}
return sw;
}
示例9: EC_Curve
/**
* @param bits
* @param field KeyPair.ALG_EC_FP or KeyPair.ALG_EC_F2M
*/
public EC_Curve(short bits, byte field) {
super(field == KeyPair.ALG_EC_FP ? EC_Consts.PARAMETERS_DOMAIN_FP : EC_Consts.PARAMETERS_DOMAIN_F2M);
this.bits = bits;
this.field = field;
}
示例10: toString
@Override
public String toString() {
return "<" + getId() + "> " + (field == KeyPair.ALG_EC_FP ? "Prime" : "Binary") + " field Elliptic curve (" + String.valueOf(bits) + "b)" + (desc == null ? "" : ": " + desc);
}
示例11: setup
@Override
public void setup(CardMngr cardManager) throws IOException {
/* Set original curves (secg/nist/brainpool). Set keypairs from test vectors.
* Do ECDH both ways, export and verify that the result is correct.
*/
Map<String, EC_KAResult> results = dataStore.getObjects(EC_KAResult.class, "test");
for (EC_KAResult result : results.values()) {
EC_Curve curve = dataStore.getObject(EC_Curve.class, result.getCurve());
if (cfg.namedCurve != null && !(result.getCurve().startsWith(cfg.namedCurve) || result.getCurve().equals(cfg.namedCurve))) {
continue;
}
if (curve.getBits() != cfg.bits && !cfg.all) {
continue;
}
if (curve.getField() == KeyPair.ALG_EC_FP && !cfg.primeField || curve.getField() == KeyPair.ALG_EC_F2M && !cfg.binaryField) {
continue;
}
EC_Params onekey = dataStore.getObject(EC_Keypair.class, result.getOneKey());
if (onekey == null) {
onekey = dataStore.getObject(EC_Key.Private.class, result.getOneKey());
}
EC_Params otherkey = dataStore.getObject(EC_Keypair.class, result.getOtherKey());
if (otherkey == null) {
otherkey = dataStore.getObject(EC_Key.Public.class, result.getOtherKey());
}
if (onekey == null || otherkey == null) {
throw new IOException("Test vector keys couldn't be located.");
}
List<Test> testVector = new LinkedList<>();
testVector.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), ExpectedValue.SUCCESS));
testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), ExpectedValue.SUCCESS));
//tests.add(new Test.Simple(new Command.Generate(cardManager, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS));
testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_LOCAL, EC_Consts.CURVE_external, EC_Consts.PARAMETER_S, onekey.flatten(EC_Consts.PARAMETER_S)), ExpectedValue.SUCCESS));
testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_REMOTE, EC_Consts.CURVE_external, EC_Consts.PARAMETER_W, otherkey.flatten(EC_Consts.PARAMETER_W)), ExpectedValue.SUCCESS));
testVector.add(new Test.Simple(new Command.ECDH(cardManager, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_TRUE, EC_Consts.CORRUPTION_NONE, result.getKA()), (command, response) -> {
Response.ECDH dh = (Response.ECDH) response;
if (!dh.successful())
return new Result(Value.FAILURE, "ECDH was unsuccessful.");
if (!dh.hasSecret())
return new Result(Value.FAILURE, "ECDH response did not contain the derived secret.");
if (!Util.compareBytes(dh.getSecret(), 0, result.getParam(0), 0, dh.secretLength())) {
int firstDiff = Util.diffBytes(dh.getSecret(), 0, result.getParam(0), 0, dh.secretLength());
return new Result(Value.FAILURE, "ECDH derived secret does not match the test, first difference was at byte " + String.valueOf(firstDiff) + ".");
}
return new Result(Value.SUCCESS);
}));
tests.add(Test.Compound.all(ExpectedValue.SUCCESS, "Test vector " + result.getId(), testVector.toArray(new Test[0])));
tests.add(new Test.Simple(new Command.Cleanup(cardManager), ExpectedValue.ANY));
}
}
示例12: getCurve
public static byte getCurve(short keyLength, byte keyClass) {
if (keyClass == KeyPair.ALG_EC_FP) {
switch (keyLength) {
case (short) 112:
return CURVE_secp112r1;
case (short) 128:
return CURVE_secp128r1;
case (short) 160:
return CURVE_secp160r1;
case (short) 192:
return CURVE_secp192r1;
case (short) 224:
return CURVE_secp224r1;
case (short) 256:
return CURVE_secp256r1;
case (short) 384:
return CURVE_secp384r1;
case (short) 521:
return CURVE_secp521r1;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
} else if (keyClass == KeyPair.ALG_EC_F2M) {
switch (keyLength) {
case (short) 163:
return CURVE_sect163r1;
case (short) 233:
return CURVE_sect233r1;
case (short) 283:
return CURVE_sect283r1;
case (short) 409:
return CURVE_sect409r1;
case (short) 571:
return CURVE_sect571r1;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
} else {
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
return 0;
}
示例13: getCurveType
public static byte getCurveType(byte curve) {
return curve <= FP_CURVES ? KeyPair.ALG_EC_FP : KeyPair.ALG_EC_F2M;
}
示例14: initializeKeys
private void initializeKeys() {
/**
* init random data generator
*/
mSaltGenerator = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
mRsaPublicKekForSquare = (RSAPublicKey) KeyBuilder.buildKey(
KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, false);
mRsaPublicKeyModPow = (RSAPublicKey) KeyBuilder.buildKey(
KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, false);
mRsaCipherForSquaring = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
mRsaCipherModPow = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
mRsaPublicKekForSquare.setExponent(SQUARE_EXPONENT, (short) 0x00,
(short) 0x01);
// Copy P of used curve to temporary transient memory for faster computation (used several times)
Util.arrayCopy(CurveConstants.P_forRSAOperation, (short) 0x00, tempBuffer, TEMP_OFFSET_P,
LENGTH_MODULUS);
/**
* set public key modulus
*/
mRsaPublicKekForSquare.setModulus(tempBuffer, TEMP_OFFSET_P, (short) LENGTH_RSAOBJECT_MODULUS);
mRsaPublicKeyModPow.setModulus(tempBuffer, TEMP_OFFSET_P, (short) LENGTH_RSAOBJECT_MODULUS);
/**
* Initialize static values for key agreement
*/
mV_Pi = new byte[(short) LENGTH_EC_POINT];
mREDP = new byte[(short) LENGTH_EC_POINT];
mSalt = new byte[(short) 0x10];
/**
* Initialize point and agreement scheme for Elliptic curve multiplication
*/
mECMultiplHelperPrivatePoint = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_192, false);
mECMultiplHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
/**
* Initialize EC Keys for Point addition (pub keys from alice and bob)
*/
mNxpPointForECAddition = ECPointBuilder.buildECPoint(ECPointBuilder.TYPE_EC_FP_POINT,KeyBuilder.LENGTH_EC_FP_192);
SRP5Utils.initializeECPoint(mNxpPointForECAddition);
SRP5Utils.initializeECPoint(mECMultiplHelperPrivatePoint);
/**
* Local public/private key pair
*/
mECKeyPairGenerator = new KeyPair(KeyPair.ALG_EC_FP,KeyBuilder.LENGTH_EC_FP_192);
mLocalECPrivateKey = (ECPrivateKey) mECKeyPairGenerator.getPrivate();
mLocalECPublicKey = ECPointBuilder.buildECPoint(ECPointBuilder.TYPE_EC_FP_POINT,KeyBuilder.LENGTH_EC_FP_192);
SRP5Utils.initializeECPoint((ECKey)mECKeyPairGenerator.getPublic());
SRP5Utils.initializeECPoint(mLocalECPrivateKey);
SRP5Utils.initializeECPoint(mLocalECPublicKey);
}