Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Store data in EEPROM or RAM?

JavaCard Applet Development Related Questions and Answers.
GraceGIRL
Posts: 15
Joined: Fri May 15, 2015 3:25 am
Points :30
Contact:

Store data in EEPROM or RAM?

Post by GraceGIRL » Fri Nov 27, 2015 5:02 am

When I develop a java card applet, what data should I store in the EEPROM? What data should I store in the RAM?
What's difference between them?

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: Store data in EEPROM or RAM?

Post by mabel » Wed Dec 02, 2015 8:02 am

When we develop javacard applets, we will apply for memory for variables.

You should know that data stored in EEPROM will not be erased even after you remove the power supply to the card. Writing and reading from EEPROM is slower compared to RAM. Also, the number of possible EEPROM writes that you can perform is limited and reaching this limit might cause the card to be not usable anymore. This is called EEPROM wearing. So use EEPROM only if absolutely needed.
The variable created by new() function will be stored in EEPROM, For example,

Code: Select all

byte[] tempBuffer; 
tempBuffer  = new byte[32];


Data stored in RAM will be cleared (all bits set to 0) either when removing the power supply, or by deselecting the applet. This is usually used for temporary data which you can afford to lose after the card loses power. Unlike EEPROM, there is no limit on the number of RAM writes you can perform.

Via JCSystem. MakeTransientByteArray () function will be stored in RAM, for example,

Code: Select all

byte[] tempBuffer;
tempBuffer = JCSystem.makeTransientByteArray((short)256, CSystem.CLEAR_ON_DESELECT);

aahmadzadeh
Posts: 27
Joined: Mon Sep 28, 2015 2:31 am
Points :400
Contact:

Re: Store data in EEPROM or RAM?

Post by aahmadzadeh » Wed Oct 19, 2016 4:40 am

How can i create other data type global variable (such as byte, short, Cipher, DesKey and...) in RAM memory?

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Store data in EEPROM or RAM?

Post by UNKNwYSHSA » Wed Oct 19, 2016 5:20 am

1 You can create byte array or short array use RAM space using method:

Code: Select all

JCSystem.makeTransientByteArray(...);
JCSystem.makeTransientShortArray(...);
See Class javacard.framework JCSystem for more details.
2 Local variables of one method with type byte/short/Object reference (not Object) are all on JavaCard stack, using RAM space;
3 Cipher object cannot be created on RAM, because no method the JC API given, and there's no need to do that. See Class javacardx.crypto.Cipher for more details.
4 Key object can be created on RAM, if the JCVM implementation support keyMemoryType XXX_TRANSIENT_DESELECT or XXX_TRANSIENT_RESET. See Class javacard.security.KeyBuilder for more details.

Note:
1 RAM object only means object data in RAM, Object is still in EEPROM .
2 Key object created with keyMemoryType XXX_TRANSIENT_DESELECT or XXX_TRANSIENT_RESET may be not in RAM, it is rely on the JCVM implementation. It can be created on NVM and clear data when power on or reset.
sense and simplicity

tay00000
Posts: 161
Joined: Tue Sep 27, 2016 10:58 am
Points :2324
Contact:

Re: Store data in EEPROM or RAM?

Post by tay00000 » Thu Oct 20, 2016 10:19 pm

KeyBuilder argument has a parameter for "keyType" in it's "buildKey" function. You specify one that is transient.

How you should call KeyBuilder is something like:

Code: Select all

// For transient memory AES key
private AESKey myRAMKey = KeyBuilder.buildKey(KeyBuilder.TYPE_AES_TRANSIENT_RESET, KeyBuilder.LENGTH_AES_256, false);

// For permanent memory AES key
private AESKey myEEPROMKey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false);


Notice that the difference is simply adding the world "TRANSIENT_RESET" or "TRANSIENT_DESELECT". The reset type means it resets when you pull out the card. The deselect type means that you can deselect the card applet but as long as you don't pull out the card, the RAM memory holding the RAM-based key would still sit inside until you finally pull out the smart card or power cycle it.

Do note that if you are creating a security sensitive cryptographic key, try to use appropriate Key types to build them instead of just storing the keys in JCSystem.makeTransientByteArray objects. The reason is these transient byte array objects are generic RAM memory allocations and the difference is those transient RAM allocated and designated as Key type objects will likely have higher security protection via the card's security mechanisms. It is like storing a key inside a key cabinet or simply putting a key on the table top. If you are intended of storing cryptographic key information in the normal RAM memory, make sure to clear the memory by overwriting it with zero bytes manually (called zeroizing the key to prevent recovery) once they have no more use. However if you store the temporary keys in Key type objects, you can be a little careless by simply leaving them as it is since end of the data the clearKey() method (to wipe the memory safely) would still be used to clean it's Key type object memory in a secure manner.

There are instances where you have to copy the bytes of a secret key to do some form of key exchange (Diffie-Hellman and such) which you can't avoid copying into normal RAM memory to be encrypted for the key exchange, then you have to make good use of Util.arrayFillNonAtomic() to zeroize the memory after use.

Also, note that reading and writing operation speeds from EEPROM and RAM have vast differences in the matter of order of magnitude of thousands where the access to RAM is said to be thousands time faster than EEPROM. EEPROM also have a lifespan of 10,000+ write and above and you have to consider if you might need to write data to EEPROM or FLASH frequently as these will shorten the lifespan of the card via write-leveling on the EEPROM/FLASH memory cells everytime you write something to chip's persistent storage. So you should only use EEPROM/FLASH when you really need to and use RAM as much as possible for the sake of speed of the RAM and to allow your card to last longer due to lesser write cycles on the EEPROM/FLASH.

Please bookmark this Java Doc API: http://www.javafind.net/library/111/javacard_specifications-3_0_4-RR/classic/api_classic/index.html?overview-summary.html

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Store data in EEPROM or RAM?

Post by UNKNwYSHSA » Thu Oct 27, 2016 4:22 am

@tay00000, Good!
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 57 guests

JavaCard OS : Disclaimer