Skip to content

Commit

Permalink
Add more debug instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Apr 14, 2022
1 parent 64331ec commit abfd69e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions applet/src/main/java/jced25519/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public class Consts {
public static final byte INS_SIGN_NONCE = (byte) 0xD5;
public static final byte INS_SIGN_FINALIZE = (byte) 0xD6;
public static final byte INS_SIGN_UPDATE = (byte) 0xD7;
public static final byte INS_GET_PRIV_NONCE = (byte) 0xD8;

public final static short E_ALREADY_INITIALIZED = (short) 0xee00;
public final static short E_UNINITIALIZED = (short) 0xee01;
public final static short E_DEBUG_DISABLED = (short) 0xee02;

public final static short SW_Exception = (short) 0xff01;
public final static short SW_ArrayIndexOutOfBoundsException = (short) 0xff02;
Expand Down
17 changes: 15 additions & 2 deletions applet/src/main/java/jced25519/JCEd25519.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import jced25519.swalgs.*;

public class JCEd25519 extends Applet implements MultiSelectable {
private final boolean DEBUG = true;

private ECConfig ecc;
private ECCurve curve;
private Bignat privateKey, privateNonce, signature;
private Bignat transformC, transformA3, transformX, transformY, eight;
Expand Down Expand Up @@ -85,9 +88,19 @@ public void process(APDU apdu) {
break;

case Consts.INS_GET_PRIV:
if(!DEBUG) {
ISOException.throwIt(Consts.E_DEBUG_DISABLED);
}
Util.arrayCopyNonAtomic(privateKey.as_byte_array(), (short) 0, apdu.getBuffer(), (short) 0, (short) 32);
apdu.setOutgoingAndSend((short) 0, (short) 32);
break;
case Consts.INS_GET_PRIV_NONCE:
if(!DEBUG) {
ISOException.throwIt(Consts.E_DEBUG_DISABLED);
}
Util.arrayCopyNonAtomic(privateNonce.as_byte_array(), (short) 0, apdu.getBuffer(), (short) 0, (short) 32);
apdu.setOutgoingAndSend((short) 0, (short) 32);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
Expand Down Expand Up @@ -119,6 +132,7 @@ public void process(APDU apdu) {
}

public boolean select(boolean b) {
ecc.refreshAfterReset();
return true;
}

Expand All @@ -134,7 +148,7 @@ private void initialize(APDU apdu) {
hasher = new Sha2(Sha2.SHA_512);
}

ECConfig ecc = new ECConfig((short) 256);
ecc = new ECConfig((short) 256);

privateKey = new Bignat((short) 32, JCSystem.MEMORY_TYPE_PERSISTENT, ecc.bnh);

Expand All @@ -148,7 +162,6 @@ private void initialize(APDU apdu) {

eight = new Bignat(Consts.EIGHT, null);


curve = new ECCurve(false, Wei25519.p, Wei25519.a, Wei25519.b, Wei25519.G, Wei25519.r, Wei25519.k);
point = new ECPoint(curve, ecc.ech);

Expand Down

0 comments on commit abfd69e

Please sign in to comment.