Math library for JavaCard?

后端 未结 2 1614
北海茫月
北海茫月 2021-01-16 15:12

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 i

相关标签:
2条回答
  • 2021-01-16 15:30

    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.

    0 讨论(0)
  • 2021-01-16 15:46

    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.

    0 讨论(0)
提交回复
热议问题