1

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 !

neogenesis
  • 51
  • 6
  • I've not stumbled upon such a library yet. Of course you can do some limited tricks with the crypto API (e.g. perform an RSA modulo exponentiation using 2 as public key and a large modulus to perform squares), but many CPU's are still 8 bit with the co-processors doing all the work. Nowadays you can get 32 bit machines on high end contact chips, but it remains a limited environment. – Maarten Bodewes Mar 12 '13 at 23:23
  • @MaartenBodewes Nice trick. Would you please depict it? (An example) – Ebrahim Ghasemi Mar 11 '15 at 16:21

2 Answers2

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.

David
  • 3,957
  • 2
  • 28
  • 52
1

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.