philipWendland / IsoApplet

A Java Card PKI Applet aiming to be ISO 7816 compliant
GNU General Public License v3.0
165 stars 72 forks source link

Javacard Optimizations missing #2

Closed frankmorgner closed 9 years ago

frankmorgner commented 9 years ago

I find your code a very good starting point. However, your code looks like it's written for Java, not JavaCard. There are some scientific articles about JavaCard optimizations. But I found reading this guide highly interesting: http://www.ruimtools.com/doc.php?doc=jc_best. Maybe you want to have a look into it, too.

martinpaljak commented 9 years ago

The article you referenced is useful read, but not entirely true or relevant either. These days cards are quite well performing and I would not "optimize" unless there are realistic concerns on usability because of speed. Readability is a must and security a bigger priority than bitfidling speed optimizations. Notice that the information there references things from the 10+ year past and talks about a single card experience ("the operating system" is not really relevant, there are several vendors with different features)

Can you point out some exact changes that are necessary ? I find the implementation of file systems always intriguing (a concept that IMHO should be a thing of the past, but well..)

Also, some of the stuff that you find from academic papers is not relevant either on latest and greatest cards, so while it won't hurt (or provide some protection when moving from one card to another) it might not be useful either. YMMV.

frankmorgner commented 9 years ago

You should always verify other peoples opinions, especially when found on the internet. I was first referring to missing use of transient arrays. This, however, turns out to be a misuse of grep on my part, sorry. Anyway, I still find the article worth reading.

philipWendland commented 9 years ago

Hello Frank, thanks for the feedback and the hint to that article, but it is not unfamiliar to me. Still, I decided to not follow it strictly. The IsoApplet is ment to be for "mordern" java cards, with the muscle applet being the applet that should be chosen for older, slower cards.

If you are refering to the OO-design of the filesystem, the reason to implement this in OO (with filetypes as classes and files as objects) were

classfile (class hierarchy of the file system)

After most of the implementation was done, I did a performance evaluation and was quite happy with it (I knew I was taking a risk with the design of the filesystem). Signing with RSA is done in ~1.1s to ~1.8s, depending on the smartcard that was used for the test. "Signing" in this context includes pin verification, reading in the complete PKCS#15 file structure by OpenSC etc. Still, I am assuming the sign()-operation takes most of the time, but that has to be proven.

I don't want to sacrifice readability by massively "re-using local variables" etc.

Nevertheless, I will have another look at the code myself the next days. There is definitely room for improvements. Maybe the DFS search of files should be the place to look at first when trying to optimize performance. This is executed often and I kind of dislike the way it is currently implemented..