Java Code Examples for javacard.framework.JCSystem#makeTransientByteArray()
The following examples show how to use
javacard.framework.JCSystem#makeTransientByteArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Crypto.java From status-keycard with Apache License 2.0 | 6 votes |
Crypto() { random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false); ecdh = KeyAgreement.getInstance(KeyAgreement.ALG_EC_SVDP_DH_PLAIN, false); sha512 = MessageDigest.getInstance(MessageDigest.ALG_SHA_512, false); aesCbcIso9797m2 = Cipher.getInstance(Cipher.ALG_AES_CBC_ISO9797_M2,false); try { hmacSHA512 = Signature.getInstance(Signature.ALG_HMAC_SHA_512, false); hmacKey = (HMACKey) KeyBuilder.buildKey(KeyBuilder.TYPE_HMAC_TRANSIENT_DESELECT, KeyBuilder.LENGTH_AES_256, false); } catch (CryptoException e) { hmacSHA512 = null; hmacBlock = JCSystem.makeTransientByteArray(HMAC_BLOCK_SIZE, JCSystem.CLEAR_ON_RESET); } }
Example 2
Source File: OpenPGPSecureMessaging.java From javacard-openpgpcard with GNU General Public License v2.0 | 6 votes |
/** * Construct a new secure messaging wrapper. */ public OpenPGPSecureMessaging() { ssc = JCSystem.makeTransientByteArray(SSC_SIZE, JCSystem.CLEAR_ON_DESELECT); tmp = JCSystem.makeTransientByteArray(TMP_SIZE, JCSystem.CLEAR_ON_DESELECT); signer = Signature.getInstance( Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false); verifier = Signature.getInstance( Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false); cipher = Cipher.getInstance( Cipher.ALG_DES_CBC_ISO9797_M2, false); decipher = Cipher.getInstance( Cipher.ALG_DES_CBC_ISO9797_M2, false); keyMAC = (DESKey) KeyBuilder.buildKey( KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, KeyBuilder.LENGTH_DES3_2KEY, false); keyENC = (DESKey) KeyBuilder.buildKey( KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, KeyBuilder.LENGTH_DES3_2KEY, false); ssc_set = JCSystem.makeTransientBooleanArray((short)1, JCSystem.CLEAR_ON_DESELECT); ssc_set[0] = false; }
Example 3
Source File: FIDOStandalone.java From ledger-u2f-javacard with Apache License 2.0 | 6 votes |
/** * Init cipher engines and allocate memory. */ public FIDOStandalone() { scratch = JCSystem.makeTransientByteArray((short) 64, JCSystem.CLEAR_ON_DESELECT); keyPair = new KeyPair( (ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false), (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false)); Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPrivate()); Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPublic()); random = RandomData.getInstance(RandomData.ALG_KEYGENERATION); // Initialize the unique wrapping key chipKey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false); random.nextBytes(scratch, (short) 0, (short) 32); chipKey.setKey(scratch, (short) 0); cipherEncrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false); cipherEncrypt.init(chipKey, Cipher.MODE_ENCRYPT, IV_ZERO_AES, (short) 0, (short) IV_ZERO_AES.length); cipherDecrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false); cipherDecrypt.init(chipKey, Cipher.MODE_DECRYPT, IV_ZERO_AES, (short) 0, (short) IV_ZERO_AES.length); }
Example 4
Source File: FIDOCCImplementation.java From CCU2F with Apache License 2.0 | 5 votes |
public FIDOCCImplementation() { random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); scratch = JCSystem.makeTransientByteArray((short)128, JCSystem.CLEAR_ON_DESELECT); //seed = new byte[64]; keyPair = new KeyPair( (ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false), (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false)); Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPrivate()); Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPublic()); // Initialize the unique seed for DRNG function //random.generateData(seed, (short)0, (short)64); // Initialize the unique seed for DRNG function drngSeed1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false); drngSeed2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false); random.generateData(scratch, (short)0, (short)32); drngSeed1.setKey(scratch, (short)0); random.generateData(scratch, (short)0, (short)32); drngSeed2.setKey(scratch, (short)0); sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false); // Initialize the unique keys for MAC function macKey1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false); macKey2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false); random.generateData(scratch, (short)0, (short)16); macKey1.setKey(scratch, (short)0); random.generateData(scratch, (short)0, (short)16); macKey2.setKey(scratch, (short)0); // Initialize ecMultiplier ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false); }
Example 5
Source File: FIDOCCImplementation.java From CCU2F with Apache License 2.0 | 5 votes |
private short computeHmacSha256(byte[] key, short key_offset, short key_length, byte[] message, short message_offset, short message_length, byte[] mac, short mac_offset){ byte[] hmacBuffer = JCSystem.makeTransientByteArray((short) 128, JCSystem.CLEAR_ON_DESELECT); short BLOCKSIZE=64; short HASHSIZE=32; // compute inner hash for (short i=0; i<key_length; i++){ hmacBuffer[i]= (byte) (key[(short)(key_offset+i)] ^ (0x36)); } Util.arrayFillNonAtomic(hmacBuffer, key_length, (short)(BLOCKSIZE-key_length), (byte)0); Util.arrayCopyNonAtomic(message, message_offset, hmacBuffer, BLOCKSIZE, message_length); sha256.reset(); sha256.doFinal(hmacBuffer, (short)0, (short)(BLOCKSIZE+message_length), hmacBuffer, BLOCKSIZE); // copy hash result to data buffer! // compute outer hash for (short i=0; i<key_length; i++){ hmacBuffer[i]= (byte) (key[(short)(key_offset+i)] ^ (0x5c)); } Util.arrayFillNonAtomic(hmacBuffer, key_length, (short)(BLOCKSIZE-key_length), (byte)0); // previous hash already copied to correct offset in scratch sha256.reset(); sha256.doFinal(hmacBuffer, (short)0, (short)(BLOCKSIZE+HASHSIZE), mac, mac_offset); return HASHSIZE; }
Example 6
Source File: ObjectAllocator.java From JCMathLib with MIT License | 5 votes |
/** * Allocates new byte[] array with provided length either in RAM or EEPROM based on an allocator type. * Method updates internal counters of bytes allocated with specific allocator. Use {@code getAllocatedInRAM()} * or {@code getAllocatedInEEPROM} for counters readout. * @param length length of array * @param allocatorType type of allocator * @return allocated array */ public byte[] allocateByteArray(short length, byte allocatorType) { switch (allocatorType) { case JCSystem.MEMORY_TYPE_PERSISTENT: allocatedInEEPROM += length; return new byte[length]; case JCSystem.MEMORY_TYPE_TRANSIENT_RESET: allocatedInRAM += length; return JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_RESET); case JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT: allocatedInRAM += length; return JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_DESELECT); } return null; }
Example 7
Source File: GidsPINManager.java From GidsApplet with GNU General Public License v3.0 | 5 votes |
public GidsPINManager() { pin_pin = new GidsPIN(PIN_MAX_TRIES, PIN_MAX_LENGTH, PIN_MIN_LENGTH); ExternalChallenge = JCSystem.makeTransientByteArray((short)16, JCSystem.CLEAR_ON_DESELECT); CardChallenge = JCSystem.makeTransientByteArray((short)16, JCSystem.CLEAR_ON_DESELECT); KeyReference = JCSystem.makeTransientObjectArray((short)1, JCSystem.CLEAR_ON_DESELECT); buffer = JCSystem.makeTransientByteArray((short)40, JCSystem.CLEAR_ON_DESELECT); sharedKey = JCSystem.makeTransientByteArray((short)40, JCSystem.CLEAR_ON_DESELECT); status = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT); }
Example 8
Source File: LedgerWalletApplet.java From ledger-javacard with GNU Affero General Public License v3.0 | 5 votes |
public LedgerWalletApplet(byte[] parameters, short parametersOffset, byte parametersLength) { BCDUtils.init(); TC.init(); Crypto.init(); Transaction.init(); Bip32Cache.init(); Keycard.init(); limits = new byte[LIMIT_LAST]; scratch256 = JCSystem.makeTransientByteArray((short)256, JCSystem.CLEAR_ON_DESELECT); transactionPin = new OwnerPIN(TRANSACTION_PIN_ATTEMPTS, TRANSACTION_PIN_SIZE); walletPin = new OwnerPIN(WALLET_PIN_ATTEMPTS, WALLET_PIN_SIZE); secondaryPin = new OwnerPIN(SECONDARY_PIN_ATTEMPTS, SECONDARY_PIN_SIZE); masterDerived = new byte[64]; chipKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); trustedInputKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); developerKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); try { pairingKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false); } catch(Exception e) { } reset(); if (parametersLength != 0) { attestationPrivate = (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false); attestationPublic = new byte[65]; Secp256k1.setCommonCurveParameters(attestationPrivate); attestationPrivate.setS(parameters, parametersOffset, (short)32); parametersOffset += (short)32; attestationSignature = new byte[parameters[(short)(parametersOffset + 1)] + 2]; Util.arrayCopy(parameters, parametersOffset, attestationSignature, (short)0, (short)attestationSignature.length); } }
Example 9
Source File: JavaCardAES.java From sim-password-manager with Apache License 2.0 | 5 votes |
public JavaCardAES() { // ALLOCATE AND COMPUTE LOOKUP TABLES SBox = new byte[256]; SiBox = new byte[256]; Alogtable = new byte[256]; // ALOG_MUL Alogtable_mul2 = new byte[256]; // ALOG_MUL Alogtable_mul3 = new byte[256]; // ALOG_MUL Alogtable_mul2 = JCSystem.makeTransientByteArray((short)256, JCSystem.CLEAR_ON_RESET); // ALOG_MUL Alogtable_mul3 = JCSystem.makeTransientByteArray((short)256, JCSystem.CLEAR_ON_RESET); Logtable = new short[256]; tempBuffer = JCSystem.makeTransientByteArray(STATELEN, JCSystem.CLEAR_ON_RESET); MakeSBox(); }
Example 10
Source File: LWNFCForumApplet.java From ledger-javacard with GNU Affero General Public License v3.0 | 5 votes |
public LWNFCForumApplet() { scratch = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT); FILE_DATA = new byte[500]; // Header initialization short offset = 0; offset += (short)2; FILE_DATA[offset++] = (byte)0xC1; // beginning of well known record, short record bit not set FILE_DATA[offset++] = (byte)0x01; FILE_DATA[offset++] = (byte)0x00; // start of 4 bytes length FILE_DATA[offset++] = (byte)0x00; offset += (short)2; Util.arrayCopyNonAtomic(LANG, (short)0, FILE_DATA, offset, (short)LANG.length); LedgerWalletApplet.writeIdleText(); created = true; }
Example 11
Source File: Bip32Cache.java From ledger-javacard with GNU Affero General Public License v3.0 | 5 votes |
public static void init() { cache = new Bip32Cache[CACHE_SIZE]; for (short i=0; i<CACHE_SIZE; i++) { cache[i] = new Bip32Cache(); } lastCacheIndex = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT); }
Example 12
Source File: PayPass.java From CardExamples with The Unlicense | 4 votes |
public PayPass(byte[] bArray, short bOffset, byte bLength) { if (bLength != 27) ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); // transaction starts JCSystem.beginTransaction(); // set up and initialize all the DES encryption/descrytion ciphers used in the app DESKEY_KD_PERSO_L_EN = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false); DESKEY_KD_PERSO_R_DE = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false); DESKEY_KD_PERSO_L_DE = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false); DESKEY_KD_PERSO_R_EN = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false); CIPHER_KD_PERSO_L_EN = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false); CIPHER_KD_PERSO_R_DE = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false); CIPHER_KD_PERSO_L_DE = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false); CIPHER_KD_PERSO_R_EN = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false); // transaction ends JCSystem.commitTransaction(); // define RAM buffers for faster operation CVC3_DATA = JCSystem.makeTransientByteArray((short) 16, JCSystem.CLEAR_ON_DESELECT); CMD_BUF = JCSystem.makeTransientByteArray((short) 261, JCSystem.CLEAR_ON_DESELECT); MAC = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_DESELECT); // on initialize the current state is not_alive state = not_alive; PROFILE = new Profile(); // testing area // pre-personalization data // issuer supply PROFILE.VER_KMC = (byte) 0x01; // MC version PROFILE.VER_KMC = bArray[bOffset]; // MC version PROFILE.KMC_ID[0] = (byte) 0x54; // key id PROFILE.KMC_ID[1] = (byte) 0x13; PROFILE.KMC_ID[2] = (byte) 0x12; PROFILE.KMC_ID[3] = (byte) 0xFF; PROFILE.KMC_ID[4] = (byte) 0xFF; PROFILE.KMC_ID[5] = (byte) 0xFF; Util.arrayCopyNonAtomic(bArray, (short) (bOffset + 1), PROFILE.KMC_ID, (short) 0, (short) 6); PROFILE.KD_PERSO[0] = (byte) 0xA8; // personalization key PROFILE.KD_PERSO[1] = (byte) 0x6A; PROFILE.KD_PERSO[2] = (byte) 0x3D; PROFILE.KD_PERSO[3] = (byte) 0x06; PROFILE.KD_PERSO[4] = (byte) 0xCA; PROFILE.KD_PERSO[5] = (byte) 0xE7; PROFILE.KD_PERSO[6] = (byte) 0x04; PROFILE.KD_PERSO[7] = (byte) 0x6A; PROFILE.KD_PERSO[8] = (byte) 0x10; PROFILE.KD_PERSO[9] = (byte) 0x63; PROFILE.KD_PERSO[10] = (byte) 0x58; PROFILE.KD_PERSO[11] = (byte) 0xD5; PROFILE.KD_PERSO[12] = (byte) 0xB8; PROFILE.KD_PERSO[13] = (byte) 0x23; PROFILE.KD_PERSO[14] = (byte) 0x9C; PROFILE.KD_PERSO[15] = (byte) 0xBE; Util.arrayCopyNonAtomic(bArray, (short) (bOffset + 7), PROFILE.KD_PERSO, (short) 0, (short) 16); PROFILE.CSN[0] = (byte) 0x89; PROFILE.CSN[1] = (byte) 0xAA; PROFILE.CSN[2] = (byte) 0x7F; PROFILE.CSN[3] = (byte) 0x00; Util.arrayCopyNonAtomic(bArray, (short) (bOffset + 23), PROFILE.CSN, (short) 0, (short) 4); // end issuer supply // profile can now be considered in personalization state PROFILE.STATE = PERSO; }
Example 13
Source File: STPayP.java From CardExamples with The Unlicense | 4 votes |
/** * Creates Java Card applet object. * * @param array * the byte array containing the AID bytes * @param offset * the start of AID bytes in array * @param length * the length of the AID bytes in array */ private STPayP(byte[] array, short offset, byte length) { /*** Start allocate memory when applet is instantiated. ***/ this.records = new Records(Constants.MAX_SFI_RECORDS); this.persistentByteBuffer = new byte[Constants.SIZE_PBB]; this.personalizedPersistentByteBuffer = new byte[Constants.SIZE_PPBB]; this.transientByteBuffer = JCSystem.makeTransientByteArray(Constants.SIZE_TBB, JCSystem.CLEAR_ON_DESELECT); // NOTE: 'keyEncryption' parameter not used. this.mkAC = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); this.mkIDN = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); /*** End allocate memory when applet is instantiated. ***/ /*** Allocate memory when personalized. ***/ this.selectResponse = null; this.cardLayoutDescriptionPart1 = null; this.cardLayoutDescriptionPart2 = null; this.cardLayoutDescriptionPart3 = null; this.gpState = GPSystem.APPLICATION_SELECTABLE; /*** Start initialize variables specific to MPP Remote-SE Lite. ***/ this.cardProfile = new CardProfile(); // Build Card Profile. // NOTE: This is a kludge to retrieve AID. This would not work with real Java Card. byte aidLength = JCSystem.getAID().getBytes(this.transientByteBuffer, (short) 0); this.cardProfile.setAid(this.transientByteBuffer, (short) 0, aidLength); this.cardProfileHash = new byte[32]; // Initialize and seed random. this.random = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); byte[] seed = DataUtil.stringToCompressedByteArray(String.valueOf(Calendar.getInstance().getTimeInMillis())); this.random.setSeed(seed, (short) 0, (short) seed.length); // Initialize Mobile Key. this.dataEncryption = new DataEncryption(); if (!this.dataEncryption.initMobileKey()) { System.out.println("Error: M_Key not initialized."); } this.sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false); /*** End initialize variables specific to MPP Remote-SE Lite. ***/ // Register instance AID. register(array, (short) (offset + (byte) 1), array[offset]); }
Example 14
Source File: Gpg.java From OpenPGP-Card with GNU General Public License v3.0 | 4 votes |
/** * Only this class's install method should create the applet object. */ protected Gpg(byte[] parameters, short offset, byte length) { pinLength = new byte[3]; pins = new OwnerPIN[3]; pins[PIN_INDEX_PW1] = new OwnerPIN(MAX_TRIES_PIN1, MAX_PIN_LENGTH); pins[PIN_INDEX_PW1].update(defaultPIN, (short) 0, MIN_PIN1_LENGTH); pinLength[PIN_INDEX_PW1] = MIN_PIN1_LENGTH; pins[PIN_INDEX_PW3] = new OwnerPIN(MAX_TRIES_PIN3, MAX_PIN_LENGTH); pins[PIN_INDEX_PW3].update(defaultPIN, (short) 0, MIN_PIN3_LENGTH); pinLength[PIN_INDEX_PW3] = MIN_PIN3_LENGTH; // The resetting code is disabled by default. pins[PIN_INDEX_RC] = new OwnerPIN(MAX_TRIES_RC, MAX_PIN_LENGTH); pinLength[PIN_INDEX_RC] = 0; pinSubmitted = JCSystem.makeTransientBooleanArray((short) 2, JCSystem.CLEAR_ON_DESELECT); commandChainingBuffer = JCSystem.makeTransientByteArray((short) (TEMP_PUT_KEY_ACCUMULATOR + RSA_KEY_LENGTH_BYTES), JCSystem.CLEAR_ON_DESELECT); privateDO1 = new byte[255]; privateDO2 = new byte[255]; privateDO3 = new byte[255]; privateDO4 = new byte[255]; loginData = new byte[(short) 255]; url = new byte[(short) 255]; name = new byte[(short) 40]; language = new byte[(short) 9]; sex = new byte[(short) 1]; fingerprints = new byte[(short) 60]; caFingerprints = new byte[(short) 60]; generationDates = new byte[(short) 12]; signatureCounter = new byte[(short) 3]; pinValidForMultipleSignatures = (byte) 0; signatureKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048); confidentialityKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048); authenticationKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048); cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); register(); }
Example 15
Source File: Keycard.java From ledger-javacard with GNU Affero General Public License v3.0 | 4 votes |
public static void init() { issuerKeycard = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); userKeycard = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); pairingData = JCSystem.makeTransientByteArray((byte)(PAIRING_DATA_SIZE + 1), JCSystem.CLEAR_ON_DESELECT); challenge = JCSystem.makeTransientByteArray((byte)4, JCSystem.CLEAR_ON_DESELECT); }
Example 16
Source File: TC.java From ledger-javacard with GNU Affero General Public License v3.0 | 4 votes |
public static void init() { ctx = JCSystem.makeTransientByteArray(TX_CONTEXT_SIZE, JCSystem.CLEAR_ON_DESELECT); ctxP = new byte[P_TX_CONTEXT_SIZE]; }
Example 17
Source File: PasswordManagerApplet.java From sim-password-manager with Apache License 2.0 | 4 votes |
private PasswordManagerApplet(byte[] bArray, short bOffset, byte bLength) { keyBytes = new byte[KEY_LENGTH]; // XXX sample values for easier testing // always initialize from install parameters! prngKey = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf }; prngNonce = new byte[] { 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf }; if (bArray != null) { short Li = bArray[bOffset]; short Lc = bArray[(short) (bOffset + Li + 1)]; short seedLength = bArray[(short) (bOffset + Li + Lc + 2)]; if (seedLength > 0) { if (seedLength != (KEY_LENGTH + PRNG_NONCE_LEN)) { ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); } short seedOffset = (short) (bOffset + Li + Lc + 3); Util.arrayCopy(bArray, seedOffset, prngKey, OFFSET_ZERO, KEY_LENGTH); Util.arrayCopy(bArray, (short) (seedOffset + KEY_LENGTH), prngNonce, OFFSET_ZERO, PRNG_NONCE_LEN); } } prngCounter = 0; iv = JCSystem.makeTransientByteArray(AES_BLOCK_LEN, JCSystem.CLEAR_ON_DESELECT); cbcV = JCSystem.makeTransientByteArray(AES_BLOCK_LEN, JCSystem.CLEAR_ON_DESELECT); cbcNextV = JCSystem.makeTransientByteArray(AES_BLOCK_LEN, JCSystem.CLEAR_ON_DESELECT); // account for padding cipherBuff = JCSystem.makeTransientByteArray( (short) (MAX_DATA_LEN + AES_BLOCK_LEN), JCSystem.CLEAR_ON_DESELECT); roundKeysBuff = JCSystem.makeTransientByteArray( (short) (AES_BLOCK_LEN * 11), JCSystem.CLEAR_ON_DESELECT); aesCipher = new JavaCardAES(); }
Example 18
Source File: Transaction.java From SatochipApplet with GNU Affero General Public License v3.0 | 4 votes |
public static void init() { ctx = JCSystem.makeTransientByteArray(TX_CONTEXT_SIZE, JCSystem.CLEAR_ON_DESELECT); ctx2 = JCSystem.makeTransientShortArray((short)3, JCSystem.CLEAR_ON_DESELECT); digestFull = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false); }
Example 19
Source File: GidsApplet.java From GidsApplet with GNU General Public License v3.0 | 4 votes |
/** * \brief Only this class's install method should create the applet object. */ protected GidsApplet() { // by default the pin manager is in "initialization mode" pinManager = new GidsPINManager(); transmitManager = new TransmitManager(); currentAlgorithmRef = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT); currentKey = JCSystem.makeTransientObjectArray((short)1, JCSystem.CLEAR_ON_DESELECT); rsaPkcs1Cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); try { rsaOaepCipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1_OAEP, false); } catch (CryptoException e) { if(e.getReason() == CryptoException.NO_SUCH_ALGORITHM) { rsaOaepCipher = null; } else { throw e; } } rsaRawCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false); byte mechanisms = (byte) 0xC0; fs = new GidsFileSystem(pinManager, transmitManager, (short) 0x3F00, // FCP new byte[] { (byte)0x62, (byte)0x08, (byte)0x82, (byte)0x01, (byte)0x38, // File descriptor byte. (byte)0x8C, (byte)0x03, (byte)0x03, (byte)0x30, (byte)0x30,// security attribute }, // FCI new byte[] { 0x61, 0X12, 0x4F, 0x0B, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x97, (byte) 0x42, (byte) 0x54, (byte) 0x46, (byte) 0x59, 0x02, 0x01, // AID 0x73, 0x03, 0x40, 0x01, mechanisms, // cryptographic mechanism }, // FMD new byte[] { (byte)0x64, (byte)0x09, (byte)0x5F, (byte)0x2F, (byte) 0x01, (byte) 0x60, // pin usage policy (byte)0x7F, (byte)0x65, 0x02, (byte) 0x80, 0x00 } ); // FCI / FMD / FCP are hard coded register(); }
Example 20
Source File: TransmitManager.java From GidsApplet with GNU General Public License v3.0 | 4 votes |
public TransmitManager() { ram_buf = JCSystem.makeTransientByteArray(RAM_BUF_SIZE, JCSystem.CLEAR_ON_DESELECT); chaining_cache = JCSystem.makeTransientShortArray(CHAINING_CACHE_SIZE, JCSystem.CLEAR_ON_DESELECT); chaining_object = JCSystem.makeTransientObjectArray((short) 2, JCSystem.CLEAR_ON_DESELECT); }