Java Code Examples for javacard.security.MessageDigest#getInstance()
The following examples show how to use
javacard.security.MessageDigest#getInstance() .
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: ResourceManager.java From JCMathLib with MIT License | 5 votes |
public void initialize(short MAX_POINT_SIZE, short MAX_COORD_SIZE, short MAX_BIGNAT_SIZE, short MULT_RSA_ENGINE_MAX_LENGTH_BITS, Bignat_Helper bnh) { // Allocate long-term helper values locker = new ObjectLocker((short) (NUM_HELPER_ARRAYS + NUM_SHARED_HELPER_OBJECTS)); //locker.setLockingActive(false); // if required, locking can be disabled memAlloc = new ObjectAllocator(); memAlloc.setAllAllocatorsRAM(); //if required, memory for helper objects and arrays can be in persistent memory to save RAM (or some tradeoff) //ObjectAllocator.setAllAllocatorsEEPROM(); //ObjectAllocator.setAllocatorsTradeoff(); // Multiplication speedup engines and arrays used by Bignat.mult_RSATrick() helper_BN_array1 = memAlloc.allocateByteArray((short) (MULT_RSA_ENGINE_MAX_LENGTH_BITS / 8), memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_array1)); locker.registerLock(helper_BN_array1); helper_BN_array2 = memAlloc.allocateByteArray((short) (MULT_RSA_ENGINE_MAX_LENGTH_BITS / 8), memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_array2)); locker.registerLock(helper_BN_array2); helper_uncompressed_point_arr1 = memAlloc.allocateByteArray((short) (MAX_POINT_SIZE + 1), memAlloc.getAllocatorType(ObjectAllocator.ECPH_uncompressed_point_arr1)); locker.registerLock(helper_uncompressed_point_arr1); hashEngine = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false); helper_hashArray = memAlloc.allocateByteArray(hashEngine.getLength(), memAlloc.getAllocatorType(ObjectAllocator.ECPH_hashArray)); locker.registerLock(helper_hashArray); //locker.registerLock(hashEngine); // register hash engine to slightly speedup search for locked objects (hash engine used less frequently) helper_BN_A = new Bignat(MAX_BIGNAT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_A), bnh); helper_BN_B = new Bignat(MAX_BIGNAT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_B), bnh); helper_BN_C = new Bignat(MAX_BIGNAT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_C), bnh); helper_BN_D = new Bignat(MAX_BIGNAT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_D), bnh); helper_BN_E = new Bignat(MAX_BIGNAT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_E), bnh); helper_BN_F = new Bignat((short) (MAX_BIGNAT_SIZE + 2), memAlloc.getAllocatorType(ObjectAllocator.BNH_helper_BN_F), bnh); // +2 is to correct for infrequent RSA result with two or more leading zeroes helperEC_BN_A = new Bignat(MAX_POINT_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_A), bnh); helperEC_BN_B = new Bignat(MAX_COORD_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_B), bnh); helperEC_BN_C = new Bignat(MAX_COORD_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_C), bnh); helperEC_BN_D = new Bignat(MAX_COORD_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_D), bnh); helperEC_BN_E = new Bignat(MAX_COORD_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_E), bnh); helperEC_BN_F = new Bignat(MAX_COORD_SIZE, memAlloc.getAllocatorType(ObjectAllocator.ECPH_helperEC_BN_F), bnh); }
Example 2
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 3
Source File: HmacSha512.java From SatochipApplet with GNU Affero General Public License v3.0 | 5 votes |
public static void init(byte[] tmp){ data= tmp; try { sha512 = MessageDigest.getInstance(MessageDigest.ALG_SHA_512, false); } catch (CryptoException e) { ISOException.throwIt(CardEdge.SW_UNSUPPORTED_FEATURE); // unsupported feature => use a more recent card! } }
Example 4
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 5
Source File: HmacSha160.java From SatochipApplet with GNU Affero General Public License v3.0 | 4 votes |
public static void init(byte[] tmp){ sha160= MessageDigest.getInstance(MessageDigest.ALG_SHA, false); data= tmp; }
Example 6
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]); }