问题
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