Math library for JavaCard?

随声附和 提交于 2019-12-19 10:46:33

问题


I'm currently working on a JavaCard project (v.2.2.2) and I need to compute values using square roots, logarithms, etc...

I know that the Math class isn't available in JavaCard API and wonder if there exists another library which provides such operations ?

And also I can't use double values but I need to. Is there a way to represent a double value in the JavaCard API and perform operation (such as log, sqrt, etc..) ?

Any help appreciated !


回答1:


The javacard 2.2.2 only supports boolean, byte, short, and optionally int. If you really need to perform Math, then you need to create your own class with tricky ways and of course the result is not precise.

Best practice is the card only stores data and do simple calculation/encryption and the server/terminal side calculates the complex things. The workaround to store double in the card is to use byte array.




回答2:


There is javacardx.framework.math package in JavaCard API since 2.2.2 with limited functionality (add, subtract, multiply only). However, is frequently unsupported by physical cards and even when supported, it might be only 8 bytes long.

JCAlgTest now also provides results for all JavaCard packages including all versions as supported by cards in the database (including the javacardx.framework.math).

Alternatively, you may consider trying JCMathLib library. This library uses only public JC API calls to provide BigInteger with arbitrary length (as well as ECPoint operations) and is an improved version of older BigNat library. It will consume around 1KB RAM and requires card supporting ECC (if you like to use ECPoint, for BigInteger only it is not required). The implementation is done only partly in hardware (using RSA and ECC co-processors) and partly in software so is less resistant against side-channel and fault-induction attacks.



来源:https://stackoverflow.com/questions/15363244/math-library-for-javacard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!