Skip to content

Commit

Permalink
perform ECDSA signature without calling update
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Wendland committed Dec 27, 2022
1 parent 1bcfd8a commit fa16e15
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/xyz/wendland/javacard/pki/isoapplet/IsoApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1272,14 +1272,13 @@ private void computeDigitalSignature(APDU apdu) throws ISOException {
short lc;
short sigLen = 0;

// Receive.
// Bytes received must be Lc.
lc = readIncomingDataIntoRam(apdu);

switch(currentAlgorithmRef[0]) {
case ALG_RSA_PAD_PKCS1:
case ALG_RSA_PAD_PSS:
// Receive.
// Bytes received must be Lc.
lc = readIncomingDataIntoRam(apdu);

// RSA signature operation.
RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) keys[currentPrivateKeyRef[0]];

Expand Down Expand Up @@ -1328,28 +1327,13 @@ private void computeDigitalSignature(APDU apdu) throws ISOException {
apdu.sendBytesLong(ram_buf, lc, sigLen);
break;

case ALG_ECDSA_SHA1:
case ALG_ECDSA:
// Get the key - it must be a EC private key,
// checks have been done in MANAGE SECURITY ENVIRONMENT.
ECPrivateKey ecKey = (ECPrivateKey) keys[currentPrivateKeyRef[0]];

ecdsaSignature.init(ecKey, Signature.MODE_SIGN);

short recvLen = apdu.setIncomingAndReceive();
short offset_cdata = apdu.getOffsetCdata();
byte[] buf = apdu.getBuffer();

// Receive data. For extended APDUs, the data is received piecewise
// and aggregated in the hash. When using short APDUs, command
// chaining is performed.
while (recvLen > 0) {
ecdsaSignature.update(buf, offset_cdata, recvLen);
recvLen = apdu.receiveBytes(offset_cdata);
}

sigLen = ecdsaSignature.sign(buf, (short)0, (short)0, buf, (short) 0);
sigLen = ecdsaSignature.sign(ram_buf, (short)0, lc, apdu.getBuffer(), (short)0);
apdu.setOutgoingAndSend((short) 0, sigLen);

break;

default:
Expand Down

0 comments on commit fa16e15

Please sign in to comment.