From 79d9342827097839330491f0c47b026687c6a543 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine Date: Wed, 21 Mar 2018 11:41:26 +0100 Subject: [PATCH] Fix useless/misplaced short conversions --- src/fr/anssi/smartpgp/Constants.java | 10 +++++----- src/fr/anssi/smartpgp/PGPKey.java | 10 +++++----- src/fr/anssi/smartpgp/SmartPGPApplet.java | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/fr/anssi/smartpgp/Constants.java b/src/fr/anssi/smartpgp/Constants.java index 00bc76c..585deb9 100644 --- a/src/fr/anssi/smartpgp/Constants.java +++ b/src/fr/anssi/smartpgp/Constants.java @@ -28,7 +28,7 @@ import javacardx.crypto.*; public final class Constants { protected static final short INTERNAL_BUFFER_MAX_LENGTH = - (short)((short)0x500); + (short)0x500; protected static final short APDU_MAX_LENGTH = (short)256; @@ -42,8 +42,8 @@ public final class Constants { protected static final byte USER_PIN_MIN_SIZE_FORMAT_2 = 6; protected static final byte USER_PIN_MAX_SIZE_FORMAT_2 = 12; protected static final byte[] USER_PIN_DEFAULT = { - (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, - (byte)0x35, (byte)0x36 + (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, + (byte)0x35, (byte)0x36 }; protected static final boolean USER_PIN_DEFAULT_IS_FORMAT_2 = false; /* @@ -69,8 +69,8 @@ public final class Constants { protected static final byte ADMIN_PIN_MIN_SIZE_FORMAT_2 = 8; protected static final byte ADMIN_PIN_MAX_SIZE_FORMAT_2 = 12; protected static final byte[] ADMIN_PIN_DEFAULT = { - (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, - (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38 + (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, + (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38 }; protected static final boolean ADMIN_PIN_DEFAULT_IS_FORMAT_2 = false; /* diff --git a/src/fr/anssi/smartpgp/PGPKey.java b/src/fr/anssi/smartpgp/PGPKey.java index c024c03..7f32ff1 100644 --- a/src/fr/anssi/smartpgp/PGPKey.java +++ b/src/fr/anssi/smartpgp/PGPKey.java @@ -320,7 +320,7 @@ public final class PGPKey { off = Common.skipLength(buf, off, (short)(len - (short)(off - boff))); template_off = off; - if(template_len > (short)(len - ((short)off - boff))) { + if(template_len > (short)(len - (short)(off - boff))) { ISOException.throwIt(ISO7816.SW_WRONG_DATA); return; } @@ -353,7 +353,7 @@ public final class PGPKey { off = Common.skipLength(buf, off, (short)(len - (short)(off - boff))); data_off = off; - if(data_len > (short)(len - ((short)off - boff))) { + if(data_len > (short)(len - (short)(off - boff))) { ISOException.throwIt(ISO7816.SW_WRONG_DATA); return; } @@ -476,9 +476,9 @@ public final class PGPKey { cipher_rsa_pkcs1.init(priv, Cipher.MODE_ENCRYPT); off = cipher_rsa_pkcs1.doFinal(buf, (short)0, lc, - buf, (short)lc); + buf, lc); - return Util.arrayCopyNonAtomic(buf, (short)lc, + return Util.arrayCopyNonAtomic(buf, lc, buf, (short)0, off); @@ -516,7 +516,7 @@ public final class PGPKey { cipher_rsa_pkcs1.init(priv, Cipher.MODE_DECRYPT); final short len = cipher_rsa_pkcs1.doFinal(buf, (short)1, (short)(lc - 1), - buf, (short)lc); + buf, lc); off = Util.arrayCopyNonAtomic(buf, lc, buf, (short)0, diff --git a/src/fr/anssi/smartpgp/SmartPGPApplet.java b/src/fr/anssi/smartpgp/SmartPGPApplet.java index 89c2dfc..7511033 100644 --- a/src/fr/anssi/smartpgp/SmartPGPApplet.java +++ b/src/fr/anssi/smartpgp/SmartPGPApplet.java @@ -291,7 +291,7 @@ public final class SmartPGPApplet extends Applet { case Constants.TAG_HISTORICAL_BYTES_CARD_SERVICE_CARD_CAPABILITIES: off = Util.arrayCopyNonAtomic(Constants.HISTORICAL_BYTES, (short)0, - buf, (short)off, + buf, off, (byte)Constants.HISTORICAL_BYTES.length); break; @@ -1090,17 +1090,17 @@ public final class SmartPGPApplet extends Applet { case Constants.TAG_GENERATION_DATE_SIG: assertAdmin(); - data.pgp_keys[Persistent.PGP_KEYS_OFFSET_SIG].setGenerationDate(buf, (short)0, (short)lc); + data.pgp_keys[Persistent.PGP_KEYS_OFFSET_SIG].setGenerationDate(buf, (short)0, lc); break; case Constants.TAG_GENERATION_DATE_DEC: assertAdmin(); - data.pgp_keys[Persistent.PGP_KEYS_OFFSET_DEC].setGenerationDate(buf, (short)0, (short)lc); + data.pgp_keys[Persistent.PGP_KEYS_OFFSET_DEC].setGenerationDate(buf, (short)0, lc); break; case Constants.TAG_GENERATION_DATE_AUT: assertAdmin(); - data.pgp_keys[Persistent.PGP_KEYS_OFFSET_AUT].setGenerationDate(buf, (short)0, (short)lc); + data.pgp_keys[Persistent.PGP_KEYS_OFFSET_AUT].setGenerationDate(buf, (short)0, lc); break; case Constants.TAG_RESETTING_CODE: