make JCOP4 happy

This commit is contained in:
Michele Balistreri 2020-06-23 08:53:45 +03:00
parent ab4afcb4cd
commit a1c2bc119d
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 13 additions and 2 deletions

View File

@ -19,6 +19,7 @@ public class CashApplet extends Applet {
private SECP256k1 secp256k1;
private Signature signature;
private boolean schnorrInitialized;
/**
* Invoked during applet installation. Creates an instance of this class. The installation parameters are passed in
@ -55,6 +56,7 @@ public class CashApplet extends Applet {
signature = Signature.getInstance(Signature.ALG_ECDSA_SHA_256, false);
signature.init(privateKey, Signature.MODE_SIGN);
schnorrInitialized = false;
short c9Off = (short)(bOffset + bArray[bOffset] + 1); // Skip AID
c9Off += (short)(bArray[c9Off] + 1); // Skip Privileges and parameter length
@ -95,6 +97,11 @@ public class CashApplet extends Applet {
}
private void selectApplet(APDU apdu) {
if (!schnorrInitialized) {
secp256k1.initSchnorr();
schnorrInitialized = true;
}
byte[] apduBuffer = apdu.getBuffer();
short off = 0;

View File

@ -343,6 +343,8 @@ public class KeycardApplet extends Applet {
puk.update(apduBuffer, (short)(ISO7816.OFFSET_CDATA + PIN_LENGTH), PUK_LENGTH);
JCSystem.commitTransaction();
secp256k1.initSchnorr();
} else {
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}

View File

@ -93,11 +93,13 @@ public class SECP256k1 {
SECP256k1(Crypto crypto) {
this.crypto = crypto;
this.tmp = JCSystem.makeTransientByteArray(TMP_LEN, JCSystem.CLEAR_ON_RESET);
this.ecPointMultiplier = KeyAgreement.getInstance(ALG_EC_SVDP_DH_PLAIN_XY, false);
this.tmpECPrivateKey = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, SECP256K1_KEY_SIZE, false);
setCurveParameters(tmpECPrivateKey);
}
void initSchnorr() {
this.tmp = JCSystem.makeTransientByteArray(TMP_LEN, JCSystem.CLEAR_ON_RESET);
multPair = new KeyPair(KeyPair.ALG_RSA_CRT, SCHNORR_MULT_KEY_SIZE);
multPair.genKeyPair();